问题 F: Four-tuples(2018山东省省赛容斥)

问题 F: Four-tuples

时间限制: 10 Sec   内存限制: 128 MB
提交: 173   解决: 44
[ 提交][ 状态][ 讨论版][命题人: admin]

题目描述

Given l1,r1,l2,r2,l3,r3,l4,r4, please count the number of four-tuples (x1,x2,x3,x4) such that li≤ xi≤ ri and x1≠x2,x2≠x3,x3≠x4,x4≠x1. The answer should modulo 10^9+7 before output.

输入

The input consists of several test cases. The first line gives the number of test cases, T(1≤ T≤ 10^6).
For each test case, the input contains one line with 8 integers l1,r1,l2, r2, l3,r3,l4,r4(1≤ li≤ ri≤ 10^9)

输出

For each test case, output one line containing one integer, representing the answer.

样例输入

1
1 1 2 2 3 3 4 4

样例输出

1

提示

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#define mod 1000000007
using namespace std;
struct node{
    long long l, r;
}st[4];
long long ff(node a, node b)
{
    long long tt=min(a.r, b.r)-max(a.l, b.l)+1;
    if(tt<=0)
        return 0;
    return tt;
}
long long fff(node a, node b, node c)
{
    long long tt=min(a.r, min(b.r, c.r))-max(a.l, max(b.l, c.l))+1;
    if(tt<=0)
        return 0;
    return tt;
}
long long ffff(node a, node b, node c, node d)
{
    long long tt=min(min(a.r, b.r), min(c.r, d.r))-max(max(a.l, b.l), max(c.l, d.l))+1;
    if(tt<=0)
        return 0;
    return tt;
}
int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        long long ans=1;
        for(int i=0;i<4;i++)
        {
            scanf("%lld%lld", &st[i].l, &st[i].r);
            ans=(ans*(st[i].r-st[i].l+1))%mod;
        }
        long long sum1=(ff(st[0], st[1])%mod*(st[2].r-st[2].l+1)%mod*(st[3].r-st[3].l+1)%mod)%mod+(ff(st[1], st[2])%mod*(st[3].r-st[3].l+1)%mod*(st[0].r-st[0].l+1)%mod)%mod+(ff(st[2], st[3])%mod*(st[0].r-st[0].l+1)%mod*(st[1].r-st[1].l+1)%mod)%mod+(ff(st[3], st[0])%mod*(st[2].r-st[2].l+1)%mod*(st[1].r-st[1].l+1)%mod)%mod;
        long long sum2=(fff(st[0], st[1], st[2])%mod*(st[3].r-st[3].l+1)%mod)%mod+(ff(st[0], st[1])%mod*ff(st[2], st[3])%mod)+(ff(st[1], st[2])%mod*ff(st[0], st[3])%mod)%mod+(fff(st[3], st[1], st[2])%mod*(st[0].r-st[0].l+1)%mod)%mod+(fff(st[2], st[3], st[0])%mod*(st[1].r-st[1].l+1)%mod)%mod+(fff(st[3], st[0], st[1])%mod*(st[2].r-st[2].l+1)%mod)%mod;
        long long sum3=3*ffff(st[0], st[1], st[2], st[3])%mod;
        long long sum=(sum1-sum2+sum3+mod)%mod;
        printf("%lld\n", (ans-sum+mod)%mod);
    }
    return 0;
}
 
/**************************************************************
    Problem: 6991
    User: ldu_reserver201701
    Language: C++
    Result: 正确
    Time:1892 ms
    Memory:1092 kb
****************************************************************/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hhjian6666

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值