COFO::1330B Dreamoon Likes Permutations

Problem

Point

Design

Complexity

Code

#include<bits/stdc++.h>
#define sz(a) (int) a.size()
#define rep(i, a, b) for(int i=(a); i <(b); i++)
#define r_rep(i, a, b) for(int i=(a); i >(b); i--)
using namespace std;

int n;
int a[200009];

void solve() {
    map<int,int> fr, re;
    vector<pair<int,int> > ans;
    cin >> n;
    rep(i, 1, n + 1) {
        cin >> a[i];
        re[a[i]]++;
    }
    
    rep(i, 1, n + 1) {
        if (fr.find( a[i] ) == fr.end()) fr[ a[i] ] = 1;
        else fr[ a[i] ] ++ ;
        
        re[ a[i] ] -- ;
        if (re[ a[i] ] == 0) re.erase(a[i]);
        if (sz(fr) == 0 || sz(re) == 0) continue;
        if (sz(fr) != i || sz(re) != (n-i)) continue;
        auto itf = fr.find(sz(fr)), itr = re.find(sz(re));
        if(itf == fr.end() || itr == re.end()) continue;
        if ((++itf) == fr.end() && fr.begin()->first == 1 && (++itr) == re.end() && re.begin()->first == 1) {
            ans.push_back({i, n-i});
        }
    }
    cout << sz(ans) << '\n';
    if (sz(ans) > 0) {
        rep(i, 0, sz(ans)) cout << ans[i].first << " " << ans[i].second << '\n';
    }
}
int main(){
    int tc; cin >>tc;
    while(tc--)
        solve();
    return 0;
}

#include<cstdio>
const int SIZE = 200000;
int p[SIZE];
int ans[SIZE][2];
int ans_cnt;
bool judge(int a[], int n){
    static int used[SIZE+1];
    for(int i = 1; i <= n; i++) used[i] = 0;
    for(int i = 0; i < n; i++) used[a[i]] = 1;
    for(int i = 1; i <= n; i++) {
        if(!used[i]) return 0;
    }
    return 1;
}
bool judge(int len1, int n){
    return judge(p, len1) && judge(p + len1, n - len1);
}
int main() {
    int t = 0;
    scanf("%d", &t);
    while(t--) {
        ans_cnt = 0;
        int n;
        scanf("%d", &n);
        int ma=0;
        for(int i = 0; i < n; i++) {
            scanf("%d", &p[i]);
            if(ma < p[i]) ma = p[i];
        }
        if(judge(n - ma,n)) {
            ans[ans_cnt][0] = n - ma;
            ans[ans_cnt++][1] = ma;
        }
        if(ma * 2 != n && judge(ma,n)) {
            ans[ans_cnt][0] = ma;
            ans[ans_cnt++][1] = n - ma;
        }
        printf("%d\n", ans_cnt);
        for(int i = 0; i < ans_cnt; i++) {
            printf("%d %d\n", ans[i][0], ans[i][1]);
        }
    }
    return 0;
}