CF1920A.Satisfying Constraints

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alex is solving a problem. He has nn constraints on what the integer kk can be. There are three types of constraints:

  1. kk must be greater than or equal to some integer xx;
  2. kk must be less than or equal to some integer xx;
  3. kk must be not equal to some integer xx.

Help Alex find the number of integers kk that satisfy all nn constraints. It is guaranteed that the answer is finite (there exists at least one constraint of type 11 and at least one constraint of type 22). Also, it is guaranteed that no two constraints are the exact same.

Alex 正在解决一个问题。他有 nn 个关于整数 kk 的约束条件。约束条件共有三种类型:

  1. kk 必须大于等于某个整数 xx;
  2. kk 必须小于等于某个整数 xx;
  3. kk 必须不等于某个整数 xx。

请帮助 Alex 找出满足全部 nn 个约束条件的整数 kk 的个数。题目保证答案是有限的(即至少存在一个类型 1 的约束和至少一个类型 2 的约束)。此外,题目还保证不存在两个完全相同的约束。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤5001 \leq t \leq 500) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤1002 \leq n \leq 100) — the number of constraints.

The following nn lines describe the constraints. Each line contains two integers aa and xx (a∈1,2,3, 1≤x≤109a \in {1,2,3}, \, 1 \leq x \leq 10^9). aa denotes the type of constraint. If a=1a=1, kk must be greater than or equal to xx. If a=2a=2, kk must be less than or equal to xx. If a=3a=3, kk must be not equal to xx.

It is guaranteed that there is a finite amount of integers satisfying all nn constraints (there exists at least one constraint of type 11 and at least one constraint of type 22). It is also guaranteed that no two constraints are the exact same (in other words, all pairs (a,x)(a, x) are distinct).

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤5001 \leq t \leq 500),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤1002 \leq n \leq 100),表示约束条件的数量。

接下来的 nn 行描述这些约束条件。每行包含两个整数 aa 和 xx(a∈{1,2,3}, 1≤x≤109a \in \{1,2,3\},\, 1 \leq x \leq 10^9)。其中 aa 表示约束类型:若 a=1a=1,则 kk 必须大于等于 xx;若 a=2a=2,则 kk 必须小于等于 xx;若 a=3a=3,则 kk 必须不等于 xx。

保证存在有限个整数满足全部 nn 个约束条件(即至少存在一个类型为 11 的约束,且至少存在一个类型为 22 的约束)。同时保证不存在两个完全相同的约束(即所有 (a,x)(a, x) 对互不相同)。

输出格式

For each test case, output a single integer — the number of integers kk that satisfy all nn constraints.

对于每个测试用例,输出一个整数——满足全部 nn 个约束条件的整数 kk 的个数。

输入输出样例

  • 输入#1

    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

    输出#1

    7
    0
    90
    0
    0
    800000000

说明/提示

In the first test case, k≥3k \geq 3 and k≤10k \leq 10. Furthermore, k≠1k \neq 1 and k≠5k \neq 5. The possible integers kk that satisfy the constraints are 3,4,6,7,8,9,103,4,6,7,8,9,10. So the answer is 77.

In the second test case, k≥5k \ge 5 and k≤4k \le 4, which is impossible. So the answer is 00.

在第一个测试用例中,k≥3k \geq 3 且 k≤10k \leq 10。此外,k≠1k \neq 1 且 k≠5k \neq 5。满足约束条件的可能整数 kk 为 3,4,6,7,8,9,103,4,6,7,8,9,10。因此答案为 77。

在第二个测试用例中,k≥5k \ge 5 且 k≤4k \le 4,这是不可能的。因此答案为 00。

输入解题思路,AI测评打分。不知道怎么写?

首页