CF2162F.Beautiful Intervals

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an integer nn and mm intervals. Each interval is of the form [li,ri][l_i, r_i] and satisfies 1≤li≤ri≤n1 \le l_i \le r_i \le n. Note that there can be duplicate intervals.

Let pp be a permutation of length nn containing all the integers 0,1,2,…,n−10,1,2,\dots,n-1 exactly once.

There is a multiset MM which is initially empty.

For each interval [li,ri][l_i, r_i]:

  • consider the subarray p[li…ri]p[l_i \dots r_i],
  • compute vi=mex⁡v_i = \operatorname{mex}∗^{\text{∗}}(p[li…ri])(p[l_i \dots r_i]),
  • insert viv_i into MM.

After processing all the intervals, MM will be equal to v1,v2,…,vm{v_1, v_2, \dots, v_m}.

Your task is to construct a permutation pp of length nn containing all the integers 0,1,2,…,n−10,1,2,\dots,n-1 exactly once such that mex⁡(M)\operatorname{mex}(M) is minimized.

∗^{\text{∗}}mex⁡(a)\operatorname{mex}(a) denotes the minimum excluded (MEX) of the integers in aa. For example, mex⁡([2,2,1])=0\operatorname{mex}([2,2,1])=0 because 00 does not belong to the array, and mex⁡([0,3,1,2])=4\operatorname{mex}([0,3,1,2])=4 because 00, 11, 22, and 33 appear in the array, but 44 does not.

给你一个整数 nn 和 mm 个区间。每个区间形如 [li,ri][l_i, r_i],且满足 1≤li≤ri≤n1 \le l_i \le r_i \le n。注意:区间可能重复。

设 pp 是一个长度为 nn 的排列,恰好包含所有整数 0,1,2,…,n−10,1,2,\dots,n-1 各一次。

有一个多重集合 MM,初始为空。

对每个区间 [li,ri][l_i, r_i]:

  • 考察子数组 p[li…ri]p[l_i \dots r_i],
  • 计算 vi=mex⁡v_i = \operatorname{mex}∗^{\text{∗}}(p[li…ri])(p[l_i \dots r_i]),
  • 将 viv_i 插入 MM。

处理完所有区间后,MM 将等于 {v1,v2,…,vm}\{v_1, v_2, \dots, v_m\}。

你的任务是构造一个长度为 nn 的排列 pp,其中恰好包含所有整数 0,1,2,…,n−10,1,2,\dots,n-1 各一次,使得 mex⁡(M)\operatorname{mex}(M) 最小。

∗^{\text{∗}}mex⁡(a)\operatorname{mex}(a) 表示数组 aa 中整数的最小未出现值(MEX)。例如,mex⁡([2,2,1])=0\operatorname{mex}([2,2,1])=0,因为 00 不在该数组中;而 mex⁡([0,3,1,2])=4\operatorname{mex}([0,3,1,2])=4,因为 00、11、22 和 33 均出现在该数组中,但 44 没有出现。

输入格式

The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases. Description of each testcase follows.

The first line contains two integers nn and mm (3≤n≤30003 \le n \le 3000, 1≤m≤30001 \le m \le 3000).

The next mm lines each contain two space-separated integers li,ril_i, r_i (1≤li≤ri≤n1 \le l_i \le r_i \le n) each denoting an interval.

It is guaranteed that the sum of nn over all test cases does not exceed 30003000, and the sum of mm over all test cases does not exceed 30003000.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)—— 表示测试用例的数量。每个测试用例的描述如下。

第一行包含两个整数 nn 和 mm(3≤n≤30003 \le n \le 3000,1≤m≤30001 \le m \le 3000)。

接下来的 mm 行每行包含两个以空格分隔的整数 li,ril_i, r_i(1≤li≤ri≤n1 \le l_i \le r_i \le n),分别表示一个区间。

保证所有测试用例中 nn 的总和不超过 30003000,且所有测试用例中 mm 的总和不超过 30003000。

输出格式

For each testcase, print a permutation pp of length nn containing all the integers 0,1,2,…,n−10,1,2,\dots,n-1 exactly once such that mex⁡(M)\operatorname{mex}(M) is minimized.

If there are multiple answers, you may print any one of them.

对于每个测试用例,输出一个长度为 nn 的排列 pp,该排列恰好包含所有整数 0,1,2,…,n−10,1,2,\dots,n-1 各一次,使得 mex⁡(M)\operatorname{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]p = [2, 0, 1], then M=mex⁡(2,0)=1M = {\operatorname{mex}(2, 0)} = {1}. Now, mex⁡(M)=0\operatorname{mex}(M) = 0.

For the third testcase, if we choose to construct p=[0,2,1,3]p = [0, 2, 1, 3], then M=mex⁡(0,2),mex⁡(2,1),mex⁡(1,3),mex⁡(0),mex⁡(3)=1,0,0,1,0M = {\operatorname{mex}(0, 2), \operatorname{mex}(2, 1), \operatorname{mex}(1, 3), \operatorname{mex}(0), \operatorname{mex}(3)} = {1, 0, 0, 1, 0}. Now, mex⁡(M)=2\operatorname{mex}(M) = 2.

For the fourth testcase, if we choose to construct p=[2,0,1,3,4]p = [2, 0, 1, 3, 4], then M=mex⁡(1,3,4),mex⁡(2),mex⁡(0,1,3),mex⁡(4)=0,0,2,0M = {\operatorname{mex}(1, 3, 4), \operatorname{mex}(2), \operatorname{mex}(0, 1, 3), \operatorname{mex}(4)} = {0, 0, 2, 0}. Now, mex⁡(M)=1\operatorname{mex}(M) = 1.

For the fifth testcase, if we choose to construct p=[3,1,0,2]p = [3, 1, 0, 2], then M=mex⁡(3,1,0),mex⁡(1,0,2)=2,3M = {\operatorname{mex}(3, 1, 0), \operatorname{mex}(1, 0, 2)} = {2, 3}. Now, mex⁡(M)=0\operatorname{mex}(M) = 0.

对于第一个测试用例,如果我们选择构造 p=[2,0,1]p = [2, 0, 1],则 M=mex⁡(2,0)=1M = {\operatorname{mex}(2, 0)} = {1}。此时,mex⁡(M)=0\operatorname{mex}(M) = 0。

对于第三个测试用例,如果我们选择构造 p=[0,2,1,3]p = [0, 2, 1, 3],则 M=mex⁡(0,2),mex⁡(2,1),mex⁡(1,3),mex⁡(0),mex⁡(3)=1,0,0,1,0M = {\operatorname{mex}(0, 2), \operatorname{mex}(2, 1), \operatorname{mex}(1, 3), \operatorname{mex}(0), \operatorname{mex}(3)} = {1, 0, 0, 1, 0}。此时,mex⁡(M)=2\operatorname{mex}(M) = 2。

对于第四个测试用例,如果我们选择构造 p=[2,0,1,3,4]p = [2, 0, 1, 3, 4],则 M=mex⁡(1,3,4),mex⁡(2),mex⁡(0,1,3),mex⁡(4)=0,0,2,0M = {\operatorname{mex}(1, 3, 4), \operatorname{mex}(2), \operatorname{mex}(0, 1, 3), \operatorname{mex}(4)} = {0, 0, 2, 0}。此时,mex⁡(M)=1\operatorname{mex}(M) = 1。

对于第五个测试用例,如果我们选择构造 p=[3,1,0,2]p = [3, 1, 0, 2],则 M=mex⁡(3,1,0),mex⁡(1,0,2)=2,3M = {\operatorname{mex}(3, 1, 0), \operatorname{mex}(1, 0, 2)} = {2, 3}。此时,mex⁡(M)=0\operatorname{mex}(M) = 0。

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

首页