AT_arc222_a.Colorful Intervals
普及-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given positive integers N and M. For each j=1,2,…,M, you are given a pair of integers (Lj,Rj) satisfying 1≤Lj≤Rj≤N.
Consider a length-N positive integer sequence A=(A1,A2,…,AN) satisfying the following condition for all j=1,2,…,M:
- ALj,ALj+1,…,ARj are all distinct.
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(A1,A2,…,AN).
T test cases are given; solve each of them.
给定正整数 N 和 M。对于每个 j=1,2,…,M,给定一对满足 1≤Lj≤Rj≤N 的整数 (Lj,Rj)。
考虑一个长度为 N 的正整数序列 A=(A1,A2,…,AN),其需对所有 j=1,2,…,M 满足以下条件:
- ALj,ALj+1,…,ARj 中所有元素互不相同。
可以证明,满足该条件的正整数序列 A 总是存在的。在所有满足条件的正整数序列 A 中,输出一个使得 max(A1,A2,…,AN) 最小的序列。
共给出 T 组测试数据;请分别求解每组数据。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
Each test case is given in the following format:
N M
L1 R1
L2 R2
⋮
LM RM
输入从标准输入给出,格式如下:
T
case1
case2
⋮
caseT
每个测试用例的格式如下:
N M
L1 R1
L2 R2
⋮
LM RM
输出格式
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(A1,A2,…,AN).
A1 A2 … AN
If multiple such A exist, any of them will be accepted.
每个测试用例输出一行。对于每个测试用例,输出满足条件的正整数序列 A 的各元素(以空格分隔),使得 max(A1,A2,…,AN) 最小。
A1 A2 … AN
若存在多个满足条件的序列 A,输出其中任意一个即可。
输入输出样例
输入#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,A5 are 1,2,3,4,5, which are all distinct.
In this case, max(A1,A2,…,AN)=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,A2 are 3,1, which are all distinct.
- A2,A3 are 1,2, which are all distinct.
- A3,A4,A5 are 2,1,3, which are all distinct.
In this case, max(A1,A2,…,AN)=3, which is the minimum value for a positive integer sequence satisfying the condition.
Constraints
- 1≤T≤105
- 1≤N≤2×105
- 1≤M≤2×105
- 1≤Lj≤Rj≤N (1≤j≤M)
- All input values are integers.
- The sum of N over all test cases is at most 2×105.
- The sum of M over all test cases is at most 2×105.
样例 1 解释:
对于第一个测试用例,输出可验证满足如下条件:
- A1,A2,A3,A4,A5 分别为 1,2,3,4,5,彼此互不相同。
此时,max(A1,A2,…,AN)=5,这是满足该条件的正整数序列所能达到的最小最大值。
对于第二个测试用例,输出可验证满足如下条件:
- A1,A2 为 3,1,彼此互不相同。
- A2,A3 为 1,2,彼此互不相同。
- A3,A4,A5 为 2,1,3,彼此互不相同。
此时,max(A1,A2,…,AN)=3,这是满足该条件的正整数序列所能达到的最小最大值。
约束条件
- 1≤T≤105
- 1≤N≤2×105
- 1≤M≤2×105
- 1≤Lj≤Rj≤N(1≤j≤M)
- 所有输入值均为整数。
- 所有测试用例中 N 的总和不超过 2×105。
- 所有测试用例中 M 的总和不超过 2×105。
输入解题思路,AI测评打分。不知道怎么写?