-
Notifications
You must be signed in to change notification settings - Fork 23
/
1330B.cpp
executable file
·49 lines (41 loc) · 896 Bytes
/
1330B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Problem Code: 1330B
#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
vector<int> permutations(int n, vector<int>& a) {
vector<int> p;
vector<bool> l(n), r(n);
unordered_set<int> seen;
for (int max_v = 0, i = 0; i < n && !seen.count(a[i]); i++) {
seen.insert(a[i]);
max_v = max(a[i], max_v);
l[i] = (seen.size() == max_v);
}
seen.clear();
for (int max_v = 0, i = n - 1; i >= 0 && !seen.count(a[i]); i--) {
seen.insert(a[i]);
max_v = max(a[i], max_v);
r[i] = (seen.size() == max_v);
}
for (int i = 1; i < n; i++)
if (l[i - 1] && r[i])
p.push_back(i);
return p;
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n), p;
for (int i = 0; i < n; i++)
cin >> a[i];
p = permutations(n, a);
cout << p.size() << endl;
for (int x: p)
cout << x << " " << n - x << endl;
}
return 0;
}