#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define dforn(i, n) for(int i=n-1; i>=0; --i)
#define PB push_back
const int MAXN=1000010, INF=1000000000;
int n, arr[MAXN], brr[MAXN], rle[MAXN], rri[MAXN], d[MAXN], key[MAXN], lans;
vector<int> anti[MAXN];
vector<vector<int>> ret;
void lis(int* arg, int* res){
forn(i, n+1) d[i]=INF;
d[0]=-INF;
forn(i, n){
auto itr = upper_bound(d, d+n+1, arg[i]);
res[i]=itr-d;
*itr=arg[i];
}
}
bool drop(int pos){
bool flag=false, touched=true;
while(touched && !anti[pos].empty() && !anti[pos+1].empty()){
touched=false;
if(anti[pos].back() > anti[pos+1].back()){
touched=flag=true;
anti[pos].pop_back();
}
if(arr[anti[pos].back()] > arr[anti[pos+1].back()]){
touched=flag=true;
anti[pos+1].pop_back();
}
}
if(pos && flag) drop(pos-1);
return flag;
}
int main(){
scanf("%d", &n);
forn(i, n) scanf("%d", &arr[i]), brr[n-1-i]=n-arr[i];
lis(arr, rle);
lis(brr, rri);
forn(i, n) lans=max(lans, rle[i]);
forn(i, n) key[i]= (rle[i] + rri[n-1-i] == lans+1)? rle[i] : -1;
forn(i, n) if(key[i]!=-1) anti[key[i]-1].PB(i);
while(true){
vector<int> add;
forn(i, lans){
add.PB(anti[i].back());
anti[i].pop_back();
}
ret.PB(add);
forn(i, lans-1) while(drop(i));
forn(i, lans) if(anti[i].empty()) goto end;
}
end:
printf("%d %d\n", (int)ret.size(), lans);
for(auto vec:ret){
for(auto el:vec) printf("%d ", el+1);
printf("\n");
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
Main.cpp:43:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | forn(i, n) scanf("%d", &arr[i]), brr[n-1-i]=n-arr[i];
| ~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23708 KB |
Output is correct |
3 |
Correct |
11 ms |
23788 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23748 KB |
Output is correct |
6 |
Correct |
11 ms |
23720 KB |
Output is correct |
7 |
Correct |
12 ms |
23800 KB |
Output is correct |
8 |
Correct |
12 ms |
23828 KB |
Output is correct |
9 |
Correct |
11 ms |
23836 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
12 ms |
23764 KB |
Output is correct |
12 |
Correct |
14 ms |
23832 KB |
Output is correct |
13 |
Correct |
12 ms |
23792 KB |
Output is correct |
14 |
Correct |
12 ms |
23724 KB |
Output is correct |
15 |
Correct |
12 ms |
23792 KB |
Output is correct |
16 |
Correct |
13 ms |
23808 KB |
Output is correct |
17 |
Correct |
12 ms |
23764 KB |
Output is correct |
18 |
Correct |
12 ms |
23788 KB |
Output is correct |
19 |
Correct |
12 ms |
23788 KB |
Output is correct |
20 |
Correct |
12 ms |
23764 KB |
Output is correct |
21 |
Correct |
12 ms |
23764 KB |
Output is correct |
22 |
Correct |
13 ms |
23812 KB |
Output is correct |
23 |
Correct |
13 ms |
23764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23708 KB |
Output is correct |
3 |
Correct |
11 ms |
23788 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23748 KB |
Output is correct |
6 |
Correct |
11 ms |
23720 KB |
Output is correct |
7 |
Correct |
12 ms |
23800 KB |
Output is correct |
8 |
Correct |
12 ms |
23828 KB |
Output is correct |
9 |
Correct |
11 ms |
23836 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
12 ms |
23764 KB |
Output is correct |
12 |
Correct |
14 ms |
23832 KB |
Output is correct |
13 |
Correct |
12 ms |
23792 KB |
Output is correct |
14 |
Correct |
12 ms |
23724 KB |
Output is correct |
15 |
Correct |
12 ms |
23792 KB |
Output is correct |
16 |
Correct |
13 ms |
23808 KB |
Output is correct |
17 |
Correct |
12 ms |
23764 KB |
Output is correct |
18 |
Correct |
12 ms |
23788 KB |
Output is correct |
19 |
Correct |
12 ms |
23788 KB |
Output is correct |
20 |
Correct |
12 ms |
23764 KB |
Output is correct |
21 |
Correct |
12 ms |
23764 KB |
Output is correct |
22 |
Correct |
13 ms |
23812 KB |
Output is correct |
23 |
Correct |
13 ms |
23764 KB |
Output is correct |
24 |
Correct |
12 ms |
23892 KB |
Output is correct |
25 |
Correct |
12 ms |
23816 KB |
Output is correct |
26 |
Correct |
15 ms |
23792 KB |
Output is correct |
27 |
Correct |
12 ms |
23860 KB |
Output is correct |
28 |
Correct |
12 ms |
23764 KB |
Output is correct |
29 |
Correct |
12 ms |
23824 KB |
Output is correct |
30 |
Correct |
12 ms |
23892 KB |
Output is correct |
31 |
Correct |
12 ms |
23788 KB |
Output is correct |
32 |
Correct |
12 ms |
23764 KB |
Output is correct |
33 |
Correct |
13 ms |
23764 KB |
Output is correct |
34 |
Correct |
12 ms |
23856 KB |
Output is correct |
35 |
Correct |
12 ms |
23764 KB |
Output is correct |
36 |
Correct |
15 ms |
23792 KB |
Output is correct |
37 |
Correct |
12 ms |
23764 KB |
Output is correct |
38 |
Correct |
12 ms |
23788 KB |
Output is correct |
39 |
Correct |
14 ms |
23792 KB |
Output is correct |
40 |
Correct |
12 ms |
23788 KB |
Output is correct |
41 |
Correct |
12 ms |
23836 KB |
Output is correct |
42 |
Correct |
13 ms |
23764 KB |
Output is correct |
43 |
Correct |
12 ms |
23788 KB |
Output is correct |
44 |
Correct |
13 ms |
23780 KB |
Output is correct |
45 |
Correct |
12 ms |
23764 KB |
Output is correct |
46 |
Correct |
12 ms |
23792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23708 KB |
Output is correct |
3 |
Correct |
11 ms |
23788 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23748 KB |
Output is correct |
6 |
Correct |
11 ms |
23720 KB |
Output is correct |
7 |
Correct |
12 ms |
23800 KB |
Output is correct |
8 |
Correct |
12 ms |
23828 KB |
Output is correct |
9 |
Correct |
11 ms |
23836 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
12 ms |
23764 KB |
Output is correct |
12 |
Correct |
14 ms |
23832 KB |
Output is correct |
13 |
Correct |
12 ms |
23792 KB |
Output is correct |
14 |
Correct |
12 ms |
23724 KB |
Output is correct |
15 |
Correct |
12 ms |
23792 KB |
Output is correct |
16 |
Correct |
13 ms |
23808 KB |
Output is correct |
17 |
Correct |
12 ms |
23764 KB |
Output is correct |
18 |
Correct |
12 ms |
23788 KB |
Output is correct |
19 |
Correct |
12 ms |
23788 KB |
Output is correct |
20 |
Correct |
12 ms |
23764 KB |
Output is correct |
21 |
Correct |
12 ms |
23764 KB |
Output is correct |
22 |
Correct |
13 ms |
23812 KB |
Output is correct |
23 |
Correct |
13 ms |
23764 KB |
Output is correct |
24 |
Correct |
12 ms |
23892 KB |
Output is correct |
25 |
Correct |
12 ms |
23816 KB |
Output is correct |
26 |
Correct |
15 ms |
23792 KB |
Output is correct |
27 |
Correct |
12 ms |
23860 KB |
Output is correct |
28 |
Correct |
12 ms |
23764 KB |
Output is correct |
29 |
Correct |
12 ms |
23824 KB |
Output is correct |
30 |
Correct |
12 ms |
23892 KB |
Output is correct |
31 |
Correct |
12 ms |
23788 KB |
Output is correct |
32 |
Correct |
12 ms |
23764 KB |
Output is correct |
33 |
Correct |
13 ms |
23764 KB |
Output is correct |
34 |
Correct |
12 ms |
23856 KB |
Output is correct |
35 |
Correct |
12 ms |
23764 KB |
Output is correct |
36 |
Correct |
15 ms |
23792 KB |
Output is correct |
37 |
Correct |
12 ms |
23764 KB |
Output is correct |
38 |
Correct |
12 ms |
23788 KB |
Output is correct |
39 |
Correct |
14 ms |
23792 KB |
Output is correct |
40 |
Correct |
12 ms |
23788 KB |
Output is correct |
41 |
Correct |
12 ms |
23836 KB |
Output is correct |
42 |
Correct |
13 ms |
23764 KB |
Output is correct |
43 |
Correct |
12 ms |
23788 KB |
Output is correct |
44 |
Correct |
13 ms |
23780 KB |
Output is correct |
45 |
Correct |
12 ms |
23764 KB |
Output is correct |
46 |
Correct |
12 ms |
23792 KB |
Output is correct |
47 |
Correct |
108 ms |
36400 KB |
Output is correct |
48 |
Correct |
113 ms |
36940 KB |
Output is correct |
49 |
Correct |
141 ms |
40372 KB |
Output is correct |
50 |
Correct |
244 ms |
53076 KB |
Output is correct |
51 |
Correct |
63 ms |
30412 KB |
Output is correct |
52 |
Correct |
348 ms |
100100 KB |
Output is correct |
53 |
Correct |
366 ms |
120548 KB |
Output is correct |
54 |
Correct |
281 ms |
68812 KB |
Output is correct |
55 |
Correct |
244 ms |
68812 KB |
Output is correct |
56 |
Correct |
13 ms |
24012 KB |
Output is correct |
57 |
Correct |
189 ms |
47156 KB |
Output is correct |
58 |
Correct |
54 ms |
29248 KB |
Output is correct |
59 |
Correct |
47 ms |
28396 KB |
Output is correct |
60 |
Correct |
200 ms |
47312 KB |
Output is correct |
61 |
Correct |
129 ms |
39348 KB |
Output is correct |
62 |
Correct |
14 ms |
23792 KB |
Output is correct |
63 |
Correct |
13 ms |
23764 KB |
Output is correct |
64 |
Correct |
12 ms |
23720 KB |
Output is correct |
65 |
Correct |
11 ms |
23788 KB |
Output is correct |
66 |
Correct |
11 ms |
23828 KB |
Output is correct |
67 |
Correct |
13 ms |
23764 KB |
Output is correct |
68 |
Correct |
11 ms |
23796 KB |
Output is correct |
69 |
Correct |
12 ms |
23796 KB |
Output is correct |