题目描述
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, 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
题目描述: 给四个区间 要求在四个区间中分别取出来一个数值 分别定义为x1 x2 x3 x4 要求x1!=x2 x2!=x3 x3!=x4 x4!=x1 四个范围均为1e9 求符合
条件的取值方法数
题解: 容斥原理 将四个条件分别称为 A B C D 那么要求的就是 A∩B∩C∩D
A∩B∩C∩D = |U|-|A∪B∪C∪D|
= L[A]*L[B]*L[C]*L[D](第i个区间的长度) - L[A]=L[b] - L[B]=L[C] - L[C]=L[D] - L[D]=L[A](每种情况未提及的区间
任选 及乘以区间长度) + L[A]=L[B]=L[C] + L[B]=L[C]=L[D] + L[C]=L[D]=[A] + L[D]=L[A]=L[B] + L[A]=L[B]&&L[C]=L[D] +
L[B]=L[C]&&L[D]=L[A] - L[A]=L[B]=L[C]=L[D]*3
为什么要乘3呢 因为在第一步中加了一遍 第二步中减去了四遍 第三步中加上了六遍 所以最后要减去三遍啊
代码如下: