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 a of length n, and you want to divide it into k>1 subsegments† in such a way that the MEX‡ on each subsegment is equal to the same integer.
Help Nyam-Nyam find any suitable division, or determine that it does not exist.
†A division of an array into k subsegments is defined as k pairs of integers (l1,r1),(l2,r2),…,(lk,rk) such that li≤ri and for each 1≤j≤k−1, lj+1=rj+1, and also l1=1 and rk=n. These pairs represent the subsegments themselves.
‡MEX of an array is the smallest non-negative integer that does not belong to the array.
For example:
- MEX of the array [2,2,1] is 0, because 0 does not belong to the array.
- MEX of the array [3,1,0,1] is 2, because 0 and 1 belong to the array, but 2 does not.
- MEX of the array [0,3,1,2] is 4, because 0, 1, 2, and 3 belong to the array, but 4 does not.
在硕士生辅导中心,Nyam-Nyam 收到了一道信息学作业题。
给定一个长度为 n 的数组 a,你需要将其划分为 k>1 个子段†,使得每个子段的 MEX‡ 均等于同一个整数。
请帮助 Nyam-Nyam 找出任意一种满足条件的划分方式,或判定这样的划分不存在。
† 数组划分为 k 个子段,定义为 k 对整数 (l1,r1),(l2,r2),…,(lk,rk),满足:li≤ri;对每个 1≤j≤k−1,有 lj+1=rj+1;且 l1=1,rk=n。这些数对即表示各子段本身。
‡MEX(最小缺失非负整数)指不属于该数组的最小非负整数。
例如:
- 数组 [2,2,1] 的 MEX 是 0,因为 0 不在该数组中。
- 数组 [3,1,0,1] 的 MEX 是 2,因为 0 和 1 在该数组中,但 2 不在。
- 数组 [0,3,1,2] 的 MEX 是 4,因为 0、1、2 和 3 都在该数组中,但 4 不在。
输入格式
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer n (2≤n≤105) — the length of the array a.
The second line of each test case contains n integers a1,a2,…,an (0≤ai<n) — the elements of the array a.
It is guaranteed that the sum of n over all test cases does not exceed 105.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(2≤n≤105),表示数组 a 的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(0≤ai<n),表示数组 a 的元素。
保证所有测试用例的 n 之和不超过 105。
输出格式
For each test case, output a single integer −1 if a suitable division does not exist.
Otherwise, on the first line, output an integer k (2≤k≤n) — the number of subsegments in the division.
Then output k lines — the division into subsegments. The i-th line should contain two integers li and ri (1≤li≤ri≤n) — the boundaries of the i-th subsegment.
The following conditions must be satisfied:
- For all 1≤j≤k−1, lj+1=rj+1;
- l1=1, rk=n.
If there are multiple possible solutions, output any of them.
对于每个测试用例,若不存在满足条件的划分,则输出单个整数 −1。
否则,在第一行输出一个整数 k(2≤k≤n)—— 划分所得子区间的数量。
随后输出 k 行,表示该划分结果。第 i 行应包含两个整数 li 和 ri(1≤li≤ri≤n)—— 表示第 i 个子区间的左右边界。
需满足以下条件:
- 对所有 1≤j≤k−1,有 lj+1=rj+1;
- l1=1,rk=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 a can be divided into 2 subsegments with boundaries [1,1] and [2,2]:
- MEX of the first subsegment [0] is 1, as 0 belongs to the subsegment, but 1 does not.
- MEX of the second subsegment [0] is 1, as 0 belongs to the subsegment, but 1 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 a can be divided into 3 subsegments with boundaries [1,3], [4,5], [6,8]:
- MEX of the first subsegment [0,1,7] is 2, as 0 and 1 belong to the subsegment, but 2 does not.
- MEX of the second subsegment [1,0] is 2, as 0 and 1 belong to the subsegment, but 2 does not.
- MEX of the third subsegment [1,0,3] is 2, as 0 and 1 belong to the subsegment, but 2 does not.
在第一个测试用例中,数组 a 可被划分为 2 个子段,边界分别为 [1,1] 和 [2,2]:
- 第一个子段 [0] 的 MEX 为 1,因为 0 属于该子段,但 1 不属于。
- 第二个子段 [0] 的 MEX 为 1,因为 0 属于该子段,但 1 不属于。
在第二个测试用例中,可以证明所要求的划分不存在。
在第三个测试用例中,数组 a 可被划分为 3 个子段,边界分别为 [1,3]、[4,5] 和 [6,8]:
- 第一个子段 [0,1,7] 的 MEX 为 2,因为 0 和 1 属于该子段,但 2 不属于。
- 第二个子段 [1,0] 的 MEX 为 2,因为 0 和 1 属于该子段,但 2 不属于。
- 第三个子段 [1,0,3] 的 MEX 为 2,因为 0 和 1 属于该子段,但 2 不属于。
输入解题思路,AI测评打分。不知道怎么写?