欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1920A.Satisfying Constraints
Satisfying Constraints
Alex is solving a problem. He has constraints on what the integer can be. There are three types of constraints:
- must be greater than or equal to some integer ;
- must be less than or equal to some integer ;
- must be not equal to some integer .
Help Alex find the number of integers that satisfy all constraints. It is guaranteed that the answer is finite (there exists at least one constraint of type and at least one constraint of type ). Also, it is guaranteed that no two constraints are the exact same.
Input
Each test consists of multiple test cases. The first line contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () — the number of constraints.
The following lines describe the constraints. Each line contains two integers and (). denotes the type of constraint. If , must be greater than or equal to . If , must be less than or equal to . If , must be not equal to .
It is guaranteed that there is a finite amount of integers satisfying all constraints (there exists at least one constraint of type and at least one constraint of type ). It is also guaranteed that no two constraints are the exact same (in other words, all pairs are distinct).
Output
For each test case, output a single integer — the number of integers that satisfy all constraints.
Note
In the first test case, and . Furthermore, and . The possible integers that satisfy the constraints are . So the answer is .
In the second test case, and , which is impossible. So the answer is .
Samples
6
4
1 3
2 10
3 1
3 5
2
1 5
2 4
10
3 6
3 7
1 2
1 7
3 100
3 44
2 100
2 98
1 3
3 99
6
1 5
2 10
1 9
2 2
3 2
3 9
5
1 1
2 2
3 1
3 2
3 3
6
1 10000
2 900000000
3 500000000
1 100000000
3 10000
3 900000001
7
0
90
0
0
800000000
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |