311255: CF1956F. Nene and the Passing Game

Memory Limit:256 MB Time Limit:4 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Nene and the Passing Gametime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Nene is training her team as a basketball coach. Nene's team consists of $n$ players, numbered from $1$ to $n$. The $i$-th player has an arm interval $[l_i,r_i]$. Two players $i$ and $j$ ($i \neq j$) can pass the ball to each other if and only if $|i-j|\in[l_i+l_j,r_i+r_j]$ (here, $|x|$ denotes the absolute value of $x$).

Nene wants to test the cooperation ability of these players. In order to do this, she will hold several rounds of assessment.

  • In each round, Nene will select a sequence of players $p_1,p_2,\ldots,p_m$ such that players $p_i$ and $p_{i+1}$ can pass the ball to each other for all $1 \le i < m$. The length of the sequence $m$ can be chosen by Nene. Each player can appear in the sequence $p_1,p_2,\ldots,p_m$ multiple times or not appear in it at all.
  • Then, Nene will throw a ball to player $p_1$, player $p_1$ will pass the ball to player $p_2$ and so on... Player $p_m$ will throw a ball away from the basketball court so it can no longer be used.

As a coach, Nene wants each of $n$ players to appear in at least one round of assessment. Since Nene has to go on a date after school, Nene wants you to calculate the minimum number of rounds of assessment needed to complete the task.

Input

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2\cdot 10^5$). The description of test cases follows.

The first line contains a single integer $n$ ($1 \le n \le 2\cdot 10^6$) — the number of players.

The $i$-th of the next $n$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$) — the arm interval of the $i$-th player.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^6$.

Output

For each test case, output one integer — the minimum number of rounds of assessment Nene needs to complete her work.

ExampleInput
5
2
1 1
1 1
2
1 1
2 2
3
1 3
1 3
1 3
5
1 1
2 2
1 5
2 2
1 1
6
1 2
5 5
2 3
2 3
2 2
1 2
Output
2
2
2
1
3
Note

In the first two test cases, Nene can host two rounds of assessment: one with $p=[1]$ and one with $p=[2]$. It can be shown that hosting one round of assessment is not enough, so the answer is $2$.

In the third test case, Nene can host two rounds of assessment: one with $p=[1,3]$ and one with $p=[2]$. Player $1$ can pass the ball to player $3$ as $|3-1|=2 \in [1+1,3+3]$. It can be shown that hosting one round of assessment is not enough, so the answer is $2$.

Output

题目大意:
Nene作为一名篮球教练,正在训练她的球队。她的球队有n名球员,编号从1到n。第i名球员有一个臂距区间[l_i,r_i]。两名球员i和j(i≠j)能够互相传球,当且仅当|i-j|∈[l_i+l_j,r_i+r_j](这里,|x|表示x的绝对值)。

Nene想要测试这些球员的协作能力。为此,她将举行几轮评估。
- 在每一轮中,Nene将选择一个球员序列p_1,p_2,…,p_m,使得球员p_i和p_{i+1}能够互相传球,对于所有1≤i - 然后,Nene将向球员p_1投球,球员p_1将球传给球员p_2,依此类推……球员p_m将把球扔出篮球场,使其无法再使用。

作为一名教练,Nene希望每个n名球员至少出现在一轮评估中。由于Nene下课后要去约会,她希望你计算完成这项任务所需的最少评估轮数。

输入输出数据格式:
输入:
- 每个测试包含多个测试用例。第一行包含测试用例数t(1≤t≤2×10^5)。
- 描述测试用例如下。
- 第一行包含一个整数n(1≤n≤2×10^6)——球员的数量。
- 接下来的n行中的第i行包含两个整数l_i和r_i(1≤l_i≤r_i≤n)——第i个球员的臂距区间。
- 保证所有测试用例的n之和不超过2×10^6。

输出:
- 对于每个测试用例,输出一个整数——Nene完成工作所需的最少评估轮数。

示例输入输出:
输入:
```
5
2
1 1
1 1
2
1 1
2 2
3
1 3
1 3
1 3
5
1 1
2 2
1 5
2 2
1 1
6
1 2
5 5
2 3
2 3
2 2
1 2
```
输出:
```
2
2
2
1
3
```题目大意: Nene作为一名篮球教练,正在训练她的球队。她的球队有n名球员,编号从1到n。第i名球员有一个臂距区间[l_i,r_i]。两名球员i和j(i≠j)能够互相传球,当且仅当|i-j|∈[l_i+l_j,r_i+r_j](这里,|x|表示x的绝对值)。 Nene想要测试这些球员的协作能力。为此,她将举行几轮评估。 - 在每一轮中,Nene将选择一个球员序列p_1,p_2,…,p_m,使得球员p_i和p_{i+1}能够互相传球,对于所有1≤i

加入题单

上一题 下一题 算法标签: