Four-tuples 山东省赛F题

题目描述

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
题目描述: 给四个区间 要求在四个区间中分别取出来一个数值 分别定义为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呢 因为在第一步中加了一遍 第二步中减去了四遍 第三步中加上了六遍 所以最后要减去三遍啊
代码如下:

转载于:https://www.cnblogs.com/Flower-Z/p/9041970.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值