B. Dreamoon Likes Permutations

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 p1p1 and p2p2 of non-zero lengths l1l1 and l2l2.

Now Dreamoon concatenates these two permutations into another sequence aa of length l1+l2l1+l2. First l1l1 elements of aa is the permutation p1p1 and next l2l2 elements of aa is the permutation p2p2.

You are given the sequence aa, and you need to find two permutations p1p1 and p2p2. 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.)

Input

The first line contains an integer tt (1t100001≤t≤10000) denoting the number of test cases in the input.

Each test case contains two lines. The first line contains one integer nn (2n2000002≤n≤200000): the length of aa. The second line contains nn integers a1,a2,,ana1,a2,…,an (1ain11≤ai≤n−1).

The total sum of nn is less than 200000200000.

Output

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

Each of the next kk lines should contain two integers l1l1 and l2l2 (1l1,l2n,l1+l2=n1≤l1,l2≤n,l1+l2=n), denoting, that it is possible to divide aa into two permutations of length l1l1 and l2l2 (p1p1 is the first l1l1 elements of aa, and p2p2 is the last l2l2 elements of aa). You can print solutions in any order.

Example
input
Copy
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
output
Copy
2
1 4
4 1
1
4 2
0
0
1
2 10
0
Note

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.

 

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <deque>
#include <bitset>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>
//#include <xfunctional>
#define ll  long long
#define PII  pair<int, int>
using namespace std;
int dir[5][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } ,{ 0,0 } };
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979;
const int mod = 1e9 + 7;
const int maxn = 200000;
//if(x<0 || x>=r || y<0 || y>=c)
//1000000000000000000

int a[maxn],res[maxn][2];

bool check(int a[],int n)
{
    vector<bool> vis(maxn+1, 0);
    for (int i = 0; i < n; i++)
        vis[a[i]] = 1;
    for (int i = 1; i <= n; i++)
    {
        if (!vis[i])
            return 0;
    }
    return 1;
}

bool judge(int len, int n)
{
    return check(a,len) && check(a+len,n-len);
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n,am=0;
        cin >> n;
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            if (a[i] > am)
                am = a[i];
        }
        vector<int> ans[2];
        if (judge(n - am, n))
        {
            ans[0].push_back(n - am);
            ans[1].push_back(am);
        }
        if (am*2 !=n && judge(am, n))
        {
            ans[0].push_back(am);
            ans[1].push_back(n-am);
        }
        cout << ans[0].size()<<endl;
        for (int i = 0; i < ans[0].size(); i++)
        {
            cout << ans[0][i] << " " << ans[1][i] << endl;
        }
    }
    return 0;
}

 

原文地址:https://www.cnblogs.com/dealer/p/12637733.html