CF1330B.Dreamoon Likes Permutations

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The sequence of mm integers is called the permutation if it contains all integers from 11 to mm exactly once. The number mm is called the length of the permutation.

Dreamoon has two permutations p1p_1 and p2p_2 of non-zero lengths l1l_1 and l2l_2.

Now Dreamoon concatenates these two permutations into another sequence aa of length l1+l2l_1 + l_2. First l1l_1 elements of aa is the permutation p1p_1 and next l2l_2 elements of aa is the permutation p2p_2.

You are given the sequence aa, and you need to find two permutations p1p_1 and p2p_2. If there are several possible ways to restore them, you should find all of them. (Note that it is also possible that there will be no ways.)

由 mm 个整数组成的序列被称为排列,当且仅当它恰好包含从 11 到 mm 的所有整数各一次。称该数 mm 为该排列的长度。

Dreamoon 拥有两个非零长度的排列 p1p_1 和 p2p_2,其长度分别为 l1l_1 和 l2l_2。

现在 Dreamoon 将这两个排列连接(拼接)成另一个长度为 l1+l2l_1 + l_2 的序列 aa:aa 的前 l1l_1 个元素是排列 p1p_1,后 l2l_2 个元素是排列 p2p_2。

你将被给定序列 aa,需要找出两个排列 p1p_1 和 p2p_2。如果存在多种可能的恢复方式,则你需要找出所有可能的方式。(注意:也有可能不存在任何可行方式。)

输入格式

The first line contains an integer tt (1≤t≤10 0001 \le t \le 10\,000) denoting the number of test cases in the input.

Each test case contains two lines. The first line contains one integer nn (2≤n≤200 0002 \leq n \leq 200\,000): the length of aa. The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤n−11 \leq a_i \leq n-1).

The total sum of nn is less than 200 000200\,000.

第一行包含一个整数 tt(1≤t≤10 0001 \le t \le 10\,000),表示输入中测试用例的数量。

每个测试用例包含两行。第一行包含一个整数 nn(2≤n≤200 0002 \leq n \leq 200\,000):数组 aa 的长度。第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤n−11 \leq a_i \leq n-1)。

所有测试用例的 nn 值之和小于 200 000200\,000。

输出格式

For each test case, the first line of output should contain one integer kk: the number of ways to divide aa into permutations p1p_1 and p2p_2.

Each of the next kk lines should contain two integers l1l_1 and l2l_2 (1≤l1,l2≤n,l1+l2=n1 \leq l_1, l_2 \leq n, l_1 + l_2 = n), denoting, that it is possible to divide aa into two permutations of length l1l_1 and l2l_2 (p1p_1 is the first l1l_1 elements of aa, and p2p_2 is the last l2l_2 elements of aa). You can print solutions in any order.

对于每个测试用例,输出的第一行应包含一个整数 kk:将 aa 划分为两个排列 p1p_1 和 p2p_2 的方案数。

接下来的 kk 行中,每行应包含两个整数 l1l_1 和 l2l_2(1≤l1,l2≤n1 \leq l_1, l_2 \leq n,且 l1+l2=nl_1 + l_2 = n),表示可以将 aa 划分为长度分别为 l1l_1 和 l2l_2 的两个排列(其中 p1p_1 是 aa 的前 l1l_1 个元素,p2p_2 是 aa 的后 l2l_2 个元素)。你可以以任意顺序输出这些解。

输入输出样例

  • 输入#1

    6
    5
    1 4 3 2 1
    6
    2 4 1 3 2 1
    4
    2 1 1 3
    4
    1 3 3 1
    12
    2 1 3 4 5 6 7 8 9 1 10 2
    3
    1 1 1

    输出#1

    2
    1 4
    4 1
    1
    4 2
    0
    0
    1
    2 10
    0

说明/提示

In the first example, two possible ways to divide aa into permutations are 1+4,3,2,1{1} + {4, 3, 2, 1} and 1,4,3,2+1{1,4,3,2} + {1}.

In the second example, the only way to divide aa into permutations is 2,4,1,3+2,1{2,4,1,3} + {2,1}.

In the third example, there are no possible ways.

在第一个例子中,将 aa 划分为排列的两种可能方式是 1+4,3,2,1{1} + {4, 3, 2, 1} 和 1,4,3,2+1{1,4,3,2} + {1}。

在第二个例子中,将 aa 划分为排列的唯一方式是 2,4,1,3+2,1{2,4,1,3} + {2,1}。

在第三个例子中,不存在任何可行的方式。

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

首页