第七回日本最強プログラマー学生選手権-予選-(AtCoder Regular Contest 222)
A
彩色区间
Colorful Intervals
AtCoder
⌀ 500
原题
←B →

彩色区间AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

You are given positive integers $N$ and $M$. For each $j = 1, 2, \ldots, M$, you are given a pair of integers $(L_j, R_j)$ satisfying $1\leq L_j\leq R_j\leq N$.

给定正整数 $N$ 和 $M$。对于每个 $j = 1, 2, \ldots, M$,给定一对满足 $1\leq L_j\leq R_j\leq N$ 的整数 $(L_j, R_j)$。AI (CI翻译)

Consider a length-$N$ positive integer sequence $A = (A_1, A_2, \ldots, A_N)$ satisfying the following condition for all $j = 1, 2, \ldots, M$:

考虑一个长度为 $N$ 的正整数序列 $A = (A_1, A_2, \ldots, A_N)$,要求对于所有 $j = 1, 2, \ldots, M$,满足以下条件:AI (CI翻译)

  • $A_{L_j}, A_{L_j+1}, \ldots, A_{R_j}$ are all distinct.
  • $A_{L_j}, A_{L_j+1}, \ldots, A_{R_j}$ 两两不同。
AI (CI翻译)

It can be proved that such a positive integer sequence $A$ always exists. Among all positive integer sequences $A$ satisfying the condition, output one that minimizes the value of $\max(A_1, A_2, \ldots, A_N)$.

可以证明,总是存在满足条件的正整数序列 $A$。在所有满足条件的正整数序列中,请输出一个使得 $\max(A_1, A_2, \ldots, A_N)$ 最小的序列。AI (CI翻译)

$T$ test cases are given; solve each of them.

共有 $T$ 组测试用例,请分别求解。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1\leq T\leq 10^5$
  • $1\leq N\leq 2\times 10^5$
  • $1\leq M\leq 2\times 10^5$
  • $1\leq L_j \leq R_j\leq N$ ($1\leq j\leq M$)
  • All input values are integers.
  • The sum of $N$ over all test cases is at most $2\times 10^5$.
  • The sum of $M$ over all test cases is at most $2\times 10^5$.
  • $1\leq T\leq 10^5$
  • $1\leq N\leq 2\times 10^5$
  • $1\leq M\leq 2\times 10^5$
  • $1\leq L_j \leq R_j\leq N$($1\leq j\leq M$)
  • 所有输入值均为整数。
  • 所有测试用例中 $N$ 的总和不超过 $2\times 10^5$。
  • 所有测试用例中 $M$ 的总和不超过 $2\times 10^5$。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入给出,格式如下:AI (CI翻译)

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
AI (CI翻译)

Each test case is given in the following format:

每组测试用例的格式如下:AI (CI翻译)

N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M

N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output one line per test case. For each test case, output the elements, space-separated, of a positive integer sequence $A$ satisfying the condition that minimizes $\max(A_1, A_2, \ldots, A_N)$.

每组测试用例输出一行。对于每组测试用例,输出一个满足条件且使 $\max(A_1, A_2, \ldots, A_N)$ 最小的正整数序列 $A$ 的各个元素,元素之间用空格分隔。AI (CI翻译)

A_1 A_2 \ldots A_N

A_1 A_2 \ldots A_N
AI (CI翻译)

If multiple such $A$ exist, any of them will be accepted.

如果有多个满足条件的 $A$,输出其中任意一个即可。AI (CI翻译)

样例

Input #1
2
5 1
1 5
5 3
1 2
2 3
3 5
Output #1
1 2 3 4 5
3 1 2 1 3
For the first test case, the output can be verified to satisfy the condition as follows: - $A_1, A_2, A_3, A_4, A_5$ are $1, 2, 3, 4, 5$, which are all distinct. In this case, $\max(A_1, A_2, \ldots, A_N) = 5$, which is the minimum value for a positive integer sequence satisfying the condition. For the second test case, the output can be verified to satisfy the condition as follows: - $A_1, A_2$ are $3, 1$, which are all distinct. - $A_2, A_3$ are $1, 2$, which are all distinct. - $A_3, A_4, A_5$ are $2, 1, 3$, which are all distinct. In this case, $\max(A_1, A_2, \ldots, A_N) = 3$, which is the minimum value for a positive integer sequence satisfying the condition.
题目信息

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。