CF1935B.Informatics in MAC

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

In the Master's Assistance Center, Nyam-Nyam was given a homework assignment in informatics.

There is an array aa of length nn, and you want to divide it into k>1k \gt 1 subsegments†^{\dagger} in such a way that the MEX⁡‡\operatorname{MEX} ^{\ddagger} on each subsegment is equal to the same integer.

Help Nyam-Nyam find any suitable division, or determine that it does not exist.

†^{\dagger}A division of an array into kk subsegments is defined as kk pairs of integers (l1,r1),(l2,r2),…,(lk,rk)(l_1, r_1), (l_2, r_2), \ldots, (l_k, r_k) such that li≤ril_i \le r_i and for each 1≤j≤k−11 \le j \le k - 1, lj+1=rj+1l_{j + 1} = r_j + 1, and also l1=1l_1 = 1 and rk=nr_k = n. These pairs represent the subsegments themselves.

‡MEX⁡^{\ddagger}\operatorname{MEX} of an array is the smallest non-negative integer that does not belong to the array.

For example:

  • MEX⁡\operatorname{MEX} of the array [2,2,1][2, 2, 1] is 00, because 00 does not belong to the array.
  • MEX⁡\operatorname{MEX} of the array [3,1,0,1][3, 1, 0, 1] is 22, because 00 and 11 belong to the array, but 22 does not.
  • MEX⁡\operatorname{MEX} of the array [0,3,1,2][0, 3, 1, 2] is 44, because 00, 11, 22, and 33 belong to the array, but 44 does not.

在硕士生辅导中心,Nyam-Nyam 收到了一道信息学作业题。

给定一个长度为 nn 的数组 aa,你需要将其划分为 k>1k > 1 个子段†^{\dagger},使得每个子段的 MEX⁡‡\operatorname{MEX}^{\ddagger} 均等于同一个整数。

请帮助 Nyam-Nyam 找出任意一种满足条件的划分方式,或判定这样的划分不存在。

†^{\dagger} 数组划分为 kk 个子段,定义为 kk 对整数 (l1,r1),(l2,r2),…,(lk,rk)(l_1, r_1), (l_2, r_2), \ldots, (l_k, r_k),满足:li≤ril_i \le r_i;对每个 1≤j≤k−11 \le j \le k - 1,有 lj+1=rj+1l_{j + 1} = r_j + 1;且 l1=1l_1 = 1,rk=nr_k = n。这些数对即表示各子段本身。

‡MEX⁡^{\ddagger}\operatorname{MEX}(最小缺失非负整数)指不属于该数组的最小非负整数。

例如:

  • 数组 [2,2,1][2, 2, 1] 的 MEX⁡\operatorname{MEX} 是 00,因为 00 不在该数组中。
  • 数组 [3,1,0,1][3, 1, 0, 1] 的 MEX⁡\operatorname{MEX} 是 22,因为 00 和 11 在该数组中,但 22 不在。
  • 数组 [0,3,1,2][0, 3, 1, 2] 的 MEX⁡\operatorname{MEX} 是 44,因为 00、11、22 和 33 都在该数组中,但 44 不在。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤1052 \le n \le 10^5) — the length of the array aa.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai<n0 \le a_i \lt n) — the elements of the array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤1052 \le n \le 10^5),表示数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai<n0 \le a_i \lt n),表示数组 aa 的元素。

保证所有测试用例的 nn 之和不超过 10510^5。

输出格式

For each test case, output a single integer −1-1 if a suitable division does not exist.

Otherwise, on the first line, output an integer kk (2≤k≤n2 \le k \le n) — the number of subsegments in the division.

Then output kk lines — the division into subsegments. The ii-th line should contain two integers lil_i and rir_i (1≤li≤ri≤n1 \le l_i \le r_i \le n) — the boundaries of the ii-th subsegment.

The following conditions must be satisfied:

  • For all 1≤j≤k−11 \le j \le k - 1, lj+1=rj+1l_{j + 1} = r_j + 1;
  • l1=1l_1 = 1, rk=nr_k = n.

If there are multiple possible solutions, output any of them.

对于每个测试用例,若不存在满足条件的划分,则输出单个整数 −1-1。

否则,在第一行输出一个整数 kk(2≤k≤n2 \le k \le n)—— 划分所得子区间的数量。

随后输出 kk 行,表示该划分结果。第 ii 行应包含两个整数 lil_i 和 rir_i(1≤li≤ri≤n1 \le l_i \le r_i \le n)—— 表示第 ii 个子区间的左右边界。

需满足以下条件:

  • 对所有 1≤j≤k−11 \le j \le k - 1,有 lj+1=rj+1l_{j + 1} = r_j + 1;
  • l1=1l_1 = 1,rk=nr_k = n。

若存在多种可行解,输出任意一种即可。

输入输出样例

  • 输入#1

    5
    2
    0 0
    5
    0 1 2 3 4
    8
    0 1 7 1 0 1 0 3
    3
    2 2 2
    4
    0 1 2 0

    输出#1

    2
    1 1
    2 2
    -1
    3
    1 3
    4 5
    6 8
    3
    1 1
    2 2
    3 3
    -1

说明/提示

In the first test case, the array aa can be divided into 22 subsegments with boundaries [1,1][1, 1] and [2,2][2, 2]:

  • MEX⁡\operatorname{MEX} of the first subsegment [0][0] is 11, as 00 belongs to the subsegment, but 11 does not.
  • MEX⁡\operatorname{MEX} of the second subsegment [0][0] is 11, as 00 belongs to the subsegment, but 11 does not.

In the second test case, it can be proven that the required division does not exist.

In the third test case, the array aa can be divided into 33 subsegments with boundaries [1,3][1, 3], [4,5][4, 5], [6,8][6, 8]:

  • MEX⁡\operatorname{MEX} of the first subsegment [0,1,7][0, 1, 7] is 22, as 00 and 11 belong to the subsegment, but 22 does not.
  • MEX⁡\operatorname{MEX} of the second subsegment [1,0][1, 0] is 22, as 00 and 11 belong to the subsegment, but 22 does not.
  • MEX⁡\operatorname{MEX} of the third subsegment [1,0,3][1, 0, 3] is 22, as 00 and 11 belong to the subsegment, but 22 does not.

在第一个测试用例中,数组 aa 可被划分为 22 个子段,边界分别为 [1,1][1, 1] 和 [2,2][2, 2]:

  • 第一个子段 [0][0] 的 MEX⁡\operatorname{MEX} 为 11,因为 00 属于该子段,但 11 不属于。
  • 第二个子段 [0][0] 的 MEX⁡\operatorname{MEX} 为 11,因为 00 属于该子段,但 11 不属于。

在第二个测试用例中,可以证明所要求的划分不存在。

在第三个测试用例中,数组 aa 可被划分为 33 个子段,边界分别为 [1,3][1, 3]、[4,5][4, 5] 和 [6,8][6, 8]:

  • 第一个子段 [0,1,7][0, 1, 7] 的 MEX⁡\operatorname{MEX} 为 22,因为 00 和 11 属于该子段,但 22 不属于。
  • 第二个子段 [1,0][1, 0] 的 MEX⁡\operatorname{MEX} 为 22,因为 00 和 11 属于该子段,但 22 不属于。
  • 第三个子段 [1,0,3][1, 0, 3] 的 MEX⁡\operatorname{MEX} 为 22,因为 00 和 11 属于该子段,但 22 不属于。

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

首页