题目
题意:
你有一个序列 ,现在你可以把 分成两部分,但是要保证两个部分都有 ~ 中的每个整数都存在,且 也就是说每一部分数字唯一。
思路:
我们可以设置两个数组 ,从头开始扫如果这个点满足上述条件,那么就将 置成 ,然后 从后往前扫,最后从前往后遍历一遍,如果出现了 的情况的那么就说明这个点满足前面符合条件和后面符合条件,然后存进 最后输出就行了。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
char c;
int sgn;
if (c = getchar(), c == EOF) return ;
while (c != '-' && (c < '0' || c > '9')) c = getchar();
sgn = (c == '-') ? -1:1;
ret = (c == '-') ? 0:(c - '0');
while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return ;
}
inline void out(int x) {
if (x > 9) out(x / 10);
putchar(x % 10 + '0');
}
const int maxn = 2e5 + 10;
int a[maxn], cnt[maxn], cntt[maxn];
bool ql[maxn], qr[maxn];
int main() {
int t, n, x;
read(t);
while (t--) {
bool book = false;
memset(cnt, 0, sizeof(cnt));
memset(ql, false, sizeof(ql));
memset(qr, false, sizeof(qr));
read(n);
for (int i = 1; i <= n; i++) read(a[i]);
int x = 1;
for (int i = 1; i <= n; i++) {
if (cnt[a[i]] == 0) cnt[a[i]]++;
else break;
while (cnt[x] == 1) x++;
if (x - 1 == i) ql[i] = true;
}
memset(cnt, 0, sizeof(cnt));
x = 1;
for (int i = n; i >= 1; i--) {
if (cnt[a[i]] == 0) cnt[a[i]]++;
else break;
while (cnt[x] == 1) x++;
if (x - 1 == n - i + 1) qr[i] = true;
}
veci v;
for (int i = 1; i <= n - 1; i++) {
if (ql[i] && qr[i + 1]) v.push_back(i);
}
printf("%d\n", v.size());
for (int i = 0; i < v.size(); i++) {
printf("%d %d\n", v[i], n - v[i]);
}
}
return 0;
}