E - Packing Under Range Regulations Editorial /

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 500500

問題文

TT 個のテストケースについて、以下の問題を解いてください。

1,2,,1091,2,\dots,10^9 の番号がついた 10910^9 個の箱と、 1,2,,N1,2,\dots,N の番号がついた NN 個のボールがあります。
それぞれの箱に入れることのできるボールの個数は多くとも 11 個です。
以下の条件を満たすように、 NN 個のボールを全て箱に入れることができるか判定してください。

  • 全ての 11 以上 NN 以下の整数 ii について、番号 ii のボールが LiL_i 以上 RiR_i 以下の番号がついた箱に入っている。

制約

  • 1T2×1051 \le T \le 2 \times 10^5
  • 1N2×1051 \le N \le 2 \times 10^5
  • 1LiRi1091 \le L_i \le R_i \le 10^9
  • 11 つの入力に含まれるテストケースについて、それらの NN の総和は 2×1052 \times 10^5 を超えない。

入力

入力は標準入力から与えられる。入力の 11 行目は以下の形式である。

TT

その後、 TT 個のテストケースが続く。各テストケースは以下の形式で与えられる。

NN
L1L_1 R1R_1
L2L_2 R2R_2
\dots
LNL_N RNR_N

出力

出力は TT 行からなる。
i(1iT)i(1 \le i \le T) 行目には、 ii 番目に入力されたテストケースについて、問題文中の条件を満たすように NN 個のボールを全て箱に入れることができるなら Yes 、そうでないなら No と出力せよ。
なお、正誤判定器は英大文字と英小文字を区別せず、どちらも受理する。


入力例 1Copy

Copy
2
3
1 2
2 3
3 3
5
1 2
2 3
3 3
1 3
999999999 1000000000

出力例 1Copy

Copy
Yes
No

この入力には 22 つのテストケースが含まれます。

  • 11 つ目のテストケースについて、以下のようにボールを箱に入れると、問題文中の条件を満たすように 33 個のボールを全て箱に入れることができるので、 Yes と出力します。

    • ボール 11 を箱 11 に入れる。
    • ボール 22 を箱 22 に入れる。
    • ボール 33 を箱 33 に入れる。
  • 22 つ目のテストケースについて、問題文中の条件を満たすように 55 個のボールを全て箱に入れることはできないので、 No と出力します。

Score : 500500 points

Problem Statement

Solve the following problem for TT test cases.

There are 10910^9 boxes numbered 1,2,,1091,2,\dots,10^9 and NN balls numbered 1,2,,N1,2,\dots,N.
Each box can contain at most one ball.
Determine whether it is possible to put all NN balls in the boxes so that the following condition will be satisfied.

  • For each integer ii from 11 through NN, the ball numbered ii is in a box numbered between LiL_i and RiR_i (inclusive).

Constraints

  • 1T2×1051 \le T \le 2 \times 10^5
  • 1N2×1051 \le N \le 2 \times 10^5
  • 1LiRi1091 \le L_i \le R_i \le 10^9
  • The sum of NN across the test cases in one input is at most 2×1052 \times 10^5.

Input

Input is given from Standard Input. The first line is in the following format:

TT

Then, TT test cases follows, each of which is in the following format:

NN
L1L_1 R1R_1
L2L_2 R2R_2
\dots
LNL_N RNR_N

Output

Your output should have TT lines.
In the ii-th (1iT)(1 \le i \le T) line, print Yes if it is possible to put all NN balls in the boxes so that the condition will be satisfied in the ii-th test case in the input, and printNo otherwise.
The checker is case-insensitive; it will accept both uppercase and lowercase letters.


Sample Input 1Copy

Copy
2
3
1 2
2 3
3 3
5
1 2
2 3
3 3
1 3
999999999 1000000000

Sample Output 1Copy

Copy
Yes
No

This input contains two test cases.

  • In the 11-st test case, the following way to put the three balls would satisfy the condition, so we should print Yes.

    • Put Ball 11 in Box 11.
    • Put Ball 22 in Box 22.
    • Put Ball 33 in Box 33.
  • In the 22-nd test case, there is no way to put the five balls to satisfy the condition, so we should print No.



2025-04-25 (Fri)
21:35:59 +00:00