AT_arc222_a.Colorful Intervals

普及-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given positive integers NN and MM. For each j=1,2,…,Mj = 1, 2, \ldots, M, you are given a pair of integers (Lj,Rj)(L_j, R_j) satisfying 1≤Lj≤Rj≤N1\leq L_j\leq R_j\leq N.

Consider a length-NN positive integer sequence A=(A1,A2,…,AN)A = (A_1, A_2, \ldots, A_N) satisfying the following condition for all j=1,2,…,Mj = 1, 2, \ldots, M:

  • ALj,ALj+1,…,ARjA_{L_j}, A_{L_j+1}, \ldots, A_{R_j} are all distinct.

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

TT test cases are given; solve each of them.

给定正整数 NN 和 MM。对于每个 j=1,2,…,Mj = 1, 2, \ldots, M,给定一对满足 1≤Lj≤Rj≤N1\leq L_j\leq R_j\leq N 的整数 (Lj,Rj)(L_j, R_j)。

考虑一个长度为 NN 的正整数序列 A=(A1,A2,…,AN)A = (A_1, A_2, \ldots, A_N),其需对所有 j=1,2,…,Mj = 1, 2, \ldots, M 满足以下条件:

  • ALj,ALj+1,…,ARjA_{L_j}, A_{L_j+1}, \ldots, A_{R_j} 中所有元素互不相同。

可以证明,满足该条件的正整数序列 AA 总是存在的。在所有满足条件的正整数序列 AA 中,输出一个使得 max⁡(A1,A2,…,AN)\max(A_1, A_2, \ldots, A_N) 最小的序列。

共给出 TT 组测试数据;请分别求解每组数据。

输入格式

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

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case is given in the following format:

NN MM
L1L_1 R1R_1
L2L_2 R2R_2
⋮\vdots
LML_M RMR_M

输入从标准输入给出,格式如下:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例的格式如下:

NN MM
L1L_1 R1R_1
L2L_2 R2R_2
⋮\vdots
LML_M RMR_M

输出格式

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

A1A_1 A2A_2 …\ldots ANA_N

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

每个测试用例输出一行。对于每个测试用例,输出满足条件的正整数序列 AA 的各元素(以空格分隔),使得 max⁡(A1,A2,…,AN)\max(A_1, A_2, \ldots, A_N) 最小。

A1A_1 A2A_2 …\ldots ANA_N

若存在多个满足条件的序列 AA,输出其中任意一个即可。

输入输出样例

  • 输入#1

    2
    5 1
    1 5
    5 3
    1 2
    2 3
    3 5

    输出#1

    1 2 3 4 5
    3 1 2 1 3

说明/提示

Sample 1 Explanation:
For the first test case, the output can be verified to satisfy the condition as follows:

  • A1,A2,A3,A4,A5A_1, A_2, A_3, A_4, A_5 are 1,2,3,4,51, 2, 3, 4, 5, which are all distinct.

In this case, max⁡(A1,A2,…,AN)=5\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:

  • A1,A2A_1, A_2 are 3,13, 1, which are all distinct.
  • A2,A3A_2, A_3 are 1,21, 2, which are all distinct.
  • A3,A4,A5A_3, A_4, A_5 are 2,1,32, 1, 3, which are all distinct.

In this case, max⁡(A1,A2,…,AN)=3\max(A_1, A_2, \ldots, A_N) = 3, which is the minimum value for a positive integer sequence satisfying the condition.

Constraints

  • 1≤T≤1051\leq T\leq 10^5
  • 1≤N≤2×1051\leq N\leq 2\times 10^5
  • 1≤M≤2×1051\leq M\leq 2\times 10^5
  • 1≤Lj≤Rj≤N1\leq L_j \leq R_j\leq N (1≤j≤M1\leq j\leq M)
  • All input values are integers.
  • The sum of NN over all test cases is at most 2×1052\times 10^5.
  • The sum of MM over all test cases is at most 2×1052\times 10^5.

样例 1 解释:
对于第一个测试用例,输出可验证满足如下条件:

  • A1,A2,A3,A4,A5A_1, A_2, A_3, A_4, A_5 分别为 1,2,3,4,51, 2, 3, 4, 5,彼此互不相同。

此时,max⁡(A1,A2,…,AN)=5\max(A_1, A_2, \ldots, A_N) = 5,这是满足该条件的正整数序列所能达到的最小最大值。

对于第二个测试用例,输出可验证满足如下条件:

  • A1,A2A_1, A_2 为 3,13, 1,彼此互不相同。
  • A2,A3A_2, A_3 为 1,21, 2,彼此互不相同。
  • A3,A4,A5A_3, A_4, A_5 为 2,1,32, 1, 3,彼此互不相同。

此时,max⁡(A1,A2,…,AN)=3\max(A_1, A_2, \ldots, A_N) = 3,这是满足该条件的正整数序列所能达到的最小最大值。

约束条件

  • 1≤T≤1051\leq T\leq 10^5
  • 1≤N≤2×1051\leq N\leq 2\times 10^5
  • 1≤M≤2×1051\leq M\leq 2\times 10^5
  • 1≤Lj≤Rj≤N1\leq L_j \leq R_j\leq N(1≤j≤M1\leq j\leq M)
  • 所有输入值均为整数。
  • 所有测试用例中 NN 的总和不超过 2×1052\times 10^5。
  • 所有测试用例中 MM 的总和不超过 2×1052\times 10^5。

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

首页