CF2162F.Beautiful Intervals
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer n and m intervals. Each interval is of the form [li,ri] and satisfies 1≤li≤ri≤n. Note that there can be duplicate intervals.
Let p be a permutation of length n containing all the integers 0,1,2,…,n−1 exactly once.
There is a multiset M which is initially empty.
For each interval [li,ri]:
- consider the subarray p[li…ri],
- compute vi=mex∗(p[li…ri]),
- insert vi into M.
After processing all the intervals, M will be equal to v1,v2,…,vm.
Your task is to construct a permutation p of length n containing all the integers 0,1,2,…,n−1 exactly once such that mex(M) is minimized.
∗mex(a) denotes the minimum excluded (MEX) of the integers in a. For example, mex([2,2,1])=0 because 0 does not belong to the array, and mex([0,3,1,2])=4 because 0, 1, 2, and 3 appear in the array, but 4 does not.
给你一个整数 n 和 m 个区间。每个区间形如 [li,ri],且满足 1≤li≤ri≤n。注意:区间可能重复。
设 p 是一个长度为 n 的排列,恰好包含所有整数 0,1,2,…,n−1 各一次。
有一个多重集合 M,初始为空。
对每个区间 [li,ri]:
- 考察子数组 p[li…ri],
- 计算 vi=mex∗(p[li…ri]),
- 将 vi 插入 M。
处理完所有区间后,M 将等于 {v1,v2,…,vm}。
你的任务是构造一个长度为 n 的排列 p,其中恰好包含所有整数 0,1,2,…,n−1 各一次,使得 mex(M) 最小。
∗mex(a) 表示数组 a 中整数的最小未出现值(MEX)。例如,mex([2,2,1])=0,因为 0 不在该数组中;而 mex([0,3,1,2])=4,因为 0、1、2 和 3 均出现在该数组中,但 4 没有出现。
输入格式
The first line contains a single integer t (1≤t≤1000) — the number of test cases. Description of each testcase follows.
The first line contains two integers n and m (3≤n≤3000, 1≤m≤3000).
The next m lines each contain two space-separated integers li,ri (1≤li≤ri≤n) each denoting an interval.
It is guaranteed that the sum of n over all test cases does not exceed 3000, and the sum of m over all test cases does not exceed 3000.
第一行包含一个整数 t(1≤t≤1000)—— 表示测试用例的数量。每个测试用例的描述如下。
第一行包含两个整数 n 和 m(3≤n≤3000,1≤m≤3000)。
接下来的 m 行每行包含两个以空格分隔的整数 li,ri(1≤li≤ri≤n),分别表示一个区间。
保证所有测试用例中 n 的总和不超过 3000,且所有测试用例中 m 的总和不超过 3000。
输出格式
For each testcase, print a permutation p of length n containing all the integers 0,1,2,…,n−1 exactly once such that mex(M) is minimized.
If there are multiple answers, you may print any one of them.
对于每个测试用例,输出一个长度为 n 的排列 p,该排列恰好包含所有整数 0,1,2,…,n−1 各一次,使得 mex(M) 最小。
如果存在多个满足条件的答案,你可以输出其中任意一个。
输入输出样例
输入#1
5 3 1 1 2 3 5 1 1 1 2 2 2 2 2 2 3 4 5 1 2 2 3 3 4 1 1 4 4 5 4 3 5 1 1 2 4 4 4 4 2 1 3 2 4
输出#1
2 0 1 2 1 0 0 2 1 3 2 0 1 3 4 3 1 0 2
说明/提示
For the first testcase, if we choose to construct p=[2,0,1], then M=mex(2,0)=1. Now, mex(M)=0.
For the third testcase, if we choose to construct p=[0,2,1,3], then M=mex(0,2),mex(2,1),mex(1,3),mex(0),mex(3)=1,0,0,1,0. Now, mex(M)=2.
For the fourth testcase, if we choose to construct p=[2,0,1,3,4], then M=mex(1,3,4),mex(2),mex(0,1,3),mex(4)=0,0,2,0. Now, mex(M)=1.
For the fifth testcase, if we choose to construct p=[3,1,0,2], then M=mex(3,1,0),mex(1,0,2)=2,3. Now, mex(M)=0.
对于第一个测试用例,如果我们选择构造 p=[2,0,1],则 M=mex(2,0)=1。此时,mex(M)=0。
对于第三个测试用例,如果我们选择构造 p=[0,2,1,3],则 M=mex(0,2),mex(2,1),mex(1,3),mex(0),mex(3)=1,0,0,1,0。此时,mex(M)=2。
对于第四个测试用例,如果我们选择构造 p=[2,0,1,3,4],则 M=mex(1,3,4),mex(2),mex(0,1,3),mex(4)=0,0,2,0。此时,mex(M)=1。
对于第五个测试用例,如果我们选择构造 p=[3,1,0,2],则 M=mex(3,1,0),mex(1,0,2)=2,3。此时,mex(M)=0。
输入解题思路,AI测评打分。不知道怎么写?