311107: CF1935B. Informatics in MAC

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Informatics in MACtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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$^{\dagger}$ in such a way that the $\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 $k$ subsegments is defined as $k$ pairs of integers $(l_1, r_1), (l_2, r_2), \ldots, (l_k, r_k)$ such that $l_i \le r_i$ and for each $1 \le j \le k - 1$, $l_{j + 1} = r_j + 1$, and also $l_1 = 1$ and $r_k = n$. These pairs represent the subsegments themselves.

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

For example:

  • $\operatorname{MEX}$ of the array $[2, 2, 1]$ is $0$, because $0$ does not belong to the array.
  • $\operatorname{MEX}$ of the array $[3, 1, 0, 1]$ is $2$, because $0$ and $1$ belong to the array, but $2$ does not.
  • $\operatorname{MEX}$ of the array $[0, 3, 1, 2]$ is $4$, because $0$, $1$, $2$, and $3$ belong to the array, but $4$ does not.
Input

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \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 $n$ ($2 \le n \le 10^5$) — the length of the array $a$.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i < n$) — the elements of the array $a$.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

Output

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 \le k \le n$) — the number of subsegments in the division.

Then output $k$ lines — the division into subsegments. The $i$-th line should contain two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the boundaries of the $i$-th subsegment.

The following conditions must be satisfied:

  • For all $1 \le j \le k - 1$, $l_{j + 1} = r_j + 1$;
  • $l_1 = 1$, $r_k = n$.

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

ExampleInput
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
Output
2
1 1
2 2
-1
3
1 3
4 5
6 8
3
1 1
2 2
3 3
-1
Note

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

  • $\operatorname{MEX}$ of the first subsegment $[0]$ is $1$, as $0$ belongs to the subsegment, but $1$ does not.
  • $\operatorname{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]$:

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

Output

**题目大意:**

在大师助手中心,Nyam-Nyam 收到了一个关于信息学的家庭作业任务。

有一个长度为 $ n $ 的数组 $ a $,需要将其划分为 $ k > 1 $ 个子段,使得每个子段的 $ \operatorname{MEX} $ 都相等。

帮助 Nyam-Nyam 找到任何合适的划分,或者确定不存在这样的划分。

- 数组 $ a $ 分成 $ k $ 个子段的定义是 $ k $ 对整数 $ (l_1, r_1), (l_2, r_2), \ldots, (l_k, r_k) $,满足 $ l_i \le r_i $ 以及对于每个 $ 1 \le j \le k - 1 $,$ l_{j + 1} = r_j + 1 $,同时 $ l_1 = 1 $ 和 $ r_k = n $。这些整数对代表子段本身。
- 数组 $ \operatorname{MEX} $ 是数组中最小的非负整数,它不属于该数组。

**输入输出数据格式:**

**输入:**

每个测试包含多个测试用例。第一行包含一个整数 $ t $ ($ 1 \leq t \leq 10^4 $) —— 测试用例的数量。接下来是测试用例的描述。

每个测试用例的第一行包含一个整数 $ n $ ($ 2 \le n \le 10^5 $) —— 数组 $ a $ 的长度。

每个测试用例的第二行包含 $ n $ 个整数 $ a_1, a_2, \ldots, a_n $ ($ 0 \le a_i < n $) —— 数组 $ a $ 的元素。

保证所有测试用例的 $ n $ 之和不超过 $ 10^5 $。

**输出:**

对于每个测试用例,如果不存在合适的划分,则输出一个整数 $-1$。

否则,首先输出一个整数 $ k $ ($ 2 \le k \le n $) —— 划分中的子段数量。

然后输出 $ k $ 行 —— 子段的划分。第 $ i $ 行应包含两个整数 $ l_i $ 和 $ r_i $ ($ 1 \le l_i \le r_i \le n $) —— 第 $ i $ 个子段的边界。

必须满足以下条件:

- 对于所有 $ 1 \le j \le k - 1 $,$ l_{j + 1} = r_j + 1 $;
- $ l_1 = 1 $,$ r_k = n $。

如果有多个可能的解决方案,输出其中任何一个。

**示例:**

**输入:**
```
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
```

**输出:**
```
2
1 1
2 2
-1
3
1 3
4 5
6 8
3
1 1
2 2
3 3
-1
```

**注意:**

在第一个测试用例中,数组 $ a $ 可以划分为两个子段,边界为 $[1, 1]$ 和 $[2, 2]$:两个子段的 $ \operatorname{MEX} $ 都是 $ 1 $。

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

在第三个测试用例中,数组 $ a $ 可以划分为三个子段,边界为 $[1, 3]$,$[4, 5]$,$[6, 8]$:三个子段的 $ \operatorname{MEX} $ 都是 $ 2 $。**题目大意:** 在大师助手中心,Nyam-Nyam 收到了一个关于信息学的家庭作业任务。 有一个长度为 $ n $ 的数组 $ a $,需要将其划分为 $ k > 1 $ 个子段,使得每个子段的 $ \operatorname{MEX} $ 都相等。 帮助 Nyam-Nyam 找到任何合适的划分,或者确定不存在这样的划分。 - 数组 $ a $ 分成 $ k $ 个子段的定义是 $ k $ 对整数 $ (l_1, r_1), (l_2, r_2), \ldots, (l_k, r_k) $,满足 $ l_i \le r_i $ 以及对于每个 $ 1 \le j \le k - 1 $,$ l_{j + 1} = r_j + 1 $,同时 $ l_1 = 1 $ 和 $ r_k = n $。这些整数对代表子段本身。 - 数组 $ \operatorname{MEX} $ 是数组中最小的非负整数,它不属于该数组。 **输入输出数据格式:** **输入:** 每个测试包含多个测试用例。第一行包含一个整数 $ t $ ($ 1 \leq t \leq 10^4 $) —— 测试用例的数量。接下来是测试用例的描述。 每个测试用例的第一行包含一个整数 $ n $ ($ 2 \le n \le 10^5 $) —— 数组 $ a $ 的长度。 每个测试用例的第二行包含 $ n $ 个整数 $ a_1, a_2, \ldots, a_n $ ($ 0 \le a_i < n $) —— 数组 $ a $ 的元素。 保证所有测试用例的 $ n $ 之和不超过 $ 10^5 $。 **输出:** 对于每个测试用例,如果不存在合适的划分,则输出一个整数 $-1$。 否则,首先输出一个整数 $ k $ ($ 2 \le k \le n $) —— 划分中的子段数量。 然后输出 $ k $ 行 —— 子段的划分。第 $ i $ 行应包含两个整数 $ l_i $ 和 $ r_i $ ($ 1 \le l_i \le r_i \le n $) —— 第 $ i $ 个子段的边界。 必须满足以下条件: - 对于所有 $ 1 \le j \le k - 1 $,$ l_{j + 1} = r_j + 1 $; - $ l_1 = 1 $,$ r_k = n $。 如果有多个可能的解决方案,输出其中任何一个。 **示例:** **输入:** ``` 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 ``` **输出:** ``` 2 1 1 2 2 -1 3 1 3 4 5 6 8 3 1 1 2 2 3 3 -1 ``` **注意:** 在第一个测试用例中,数组 $ a $ 可以划分为两个子段,边界为 $[1, 1]$ 和 $[2, 2]$:两个子段的 $ \operatorname{MEX} $ 都是 $ 1 $。 在第二个测试用例中,可以证明所需的划分不存在。 在第三个测试用例中,数组 $ a $ 可以划分为三个子段,边界为 $[1, 3]$,$[4, 5]$,$[6, 8]$:三个子段的 $ \operatorname{MEX} $ 都是 $ 2 $。

加入题单

上一题 下一题 算法标签: