-
Notifications
You must be signed in to change notification settings - Fork 0
/
B. Dreamoon Likes Permutations.cpp
59 lines (58 loc) · 1.44 KB
/
B. Dreamoon Likes Permutations.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
50
51
52
53
54
55
56
57
58
59
#include <fstream>
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>
#include<bits/stdc++.h>
#include <vector>
using namespace std;
int t;
int n;
int main(){
cin >> t;
for (int z = 0; z < t;z++){
cin >> n;
int arr[n];
for (int x = 0; x < n; x++){
cin >> arr[x];
}
set<int> q;
bool first[n];
bool second[n];
for (int x = 0; x < n; x++){
first[x] = false;
second[x] = false;
}
for (int x = 0; x < n; x++){
if (q.find(arr[x]) != q.end()){
break;
}
q.insert(arr[x]);
if (*(prev(q.end(), 1)) == x + 1){
first[x] = true;
}
}
q.clear();
for (int x = n - 1; x >= 0; x--){
if (q.find(arr[x]) != q.end()){
break;
}
q.insert(arr[x]);
if (*(prev(q.end(), 1)) == n - x){
second[x] = true;
}
}
int counter = 0;
for (int x = 0; x < n - 1; x++){
if (first[x] && second[x + 1]){
counter++;
}
}
cout << counter << "\n";
for (int x = 0; x < n - 1; x++){
if (first[x] && second[x + 1]){
cout << x + 1 << " " << n - x - 1 << "\n";
}
}
}
}