#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pii pair<int,int>
const int N=1010000;
int a[N], fr[N], n, lb[N];
vector<int>lis={INT_MAX};
vector<pii> lv[N];
vector<vector<int>>ans;
set<int>st[N];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
for(int i=1; i<=n; i++){
cin >> a[i];
auto it=lower_bound(lis.begin(), lis.end(), a[i]);
if(it==lis.end())lis.push_back(a[i]), fr[i]=lis.size();
else lis[it-lis.begin()]=a[i], fr[i]=it-lis.begin()+1;
st[fr[i]].insert(i); lv[fr[i]].push_back({a[i],i});
if(fr[i]==1)continue;
int l=0, r=lv[fr[i]-1].size()-1;
while(l<r){
int mid=(l+r)/2;
if(lv[fr[i]-1][mid].fs < a[i])r=mid;
else l=mid+1;
}
lb[i]=lv[fr[i]-1][l].sc;
}
for(auto i:st[lis.size()]){
vector<int>v;
bool br=0;
for(int t=lis.size(); t>1; t--){
v.push_back(i);
auto it=st[t-1].lower_bound(lb[i]), it2=st[t-1].lower_bound(i);
if(it==it2){
br=1;
break;}
i=*it;
}
v.push_back(i);
if(v.size()!=lis.size()||br)continue;
reverse(v.begin(), v.end());
ans.push_back(v);
for(int i=0; i<v.size()-1; i++)st[i+1].erase(v[i]);
}
cout << ans.size() << ' ' << lis.size() << '\n';
for(auto v:ans){
for(int x:v)cout << x << ' ';
cout << '\n';
}
return 0;}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:49:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int i=0; i<v.size()-1; i++)st[i+1].erase(v[i]);
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
71368 KB |
Output is correct |
2 |
Correct |
41 ms |
71372 KB |
Output is correct |
3 |
Correct |
34 ms |
71372 KB |
Output is correct |
4 |
Correct |
35 ms |
71480 KB |
Output is correct |
5 |
Correct |
33 ms |
71480 KB |
Output is correct |
6 |
Correct |
38 ms |
71368 KB |
Output is correct |
7 |
Correct |
33 ms |
71444 KB |
Output is correct |
8 |
Correct |
32 ms |
71380 KB |
Output is correct |
9 |
Correct |
33 ms |
71396 KB |
Output is correct |
10 |
Correct |
34 ms |
71444 KB |
Output is correct |
11 |
Correct |
34 ms |
71412 KB |
Output is correct |
12 |
Correct |
35 ms |
71412 KB |
Output is correct |
13 |
Correct |
34 ms |
71420 KB |
Output is correct |
14 |
Correct |
33 ms |
71444 KB |
Output is correct |
15 |
Correct |
33 ms |
71380 KB |
Output is correct |
16 |
Correct |
34 ms |
71492 KB |
Output is correct |
17 |
Correct |
33 ms |
71408 KB |
Output is correct |
18 |
Correct |
35 ms |
71472 KB |
Output is correct |
19 |
Correct |
36 ms |
71468 KB |
Output is correct |
20 |
Correct |
41 ms |
71372 KB |
Output is correct |
21 |
Correct |
47 ms |
71436 KB |
Output is correct |
22 |
Correct |
42 ms |
71380 KB |
Output is correct |
23 |
Correct |
38 ms |
71480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
71368 KB |
Output is correct |
2 |
Correct |
41 ms |
71372 KB |
Output is correct |
3 |
Correct |
34 ms |
71372 KB |
Output is correct |
4 |
Correct |
35 ms |
71480 KB |
Output is correct |
5 |
Correct |
33 ms |
71480 KB |
Output is correct |
6 |
Correct |
38 ms |
71368 KB |
Output is correct |
7 |
Correct |
33 ms |
71444 KB |
Output is correct |
8 |
Correct |
32 ms |
71380 KB |
Output is correct |
9 |
Correct |
33 ms |
71396 KB |
Output is correct |
10 |
Correct |
34 ms |
71444 KB |
Output is correct |
11 |
Correct |
34 ms |
71412 KB |
Output is correct |
12 |
Correct |
35 ms |
71412 KB |
Output is correct |
13 |
Correct |
34 ms |
71420 KB |
Output is correct |
14 |
Correct |
33 ms |
71444 KB |
Output is correct |
15 |
Correct |
33 ms |
71380 KB |
Output is correct |
16 |
Correct |
34 ms |
71492 KB |
Output is correct |
17 |
Correct |
33 ms |
71408 KB |
Output is correct |
18 |
Correct |
35 ms |
71472 KB |
Output is correct |
19 |
Correct |
36 ms |
71468 KB |
Output is correct |
20 |
Correct |
41 ms |
71372 KB |
Output is correct |
21 |
Correct |
47 ms |
71436 KB |
Output is correct |
22 |
Correct |
42 ms |
71380 KB |
Output is correct |
23 |
Correct |
38 ms |
71480 KB |
Output is correct |
24 |
Correct |
35 ms |
71500 KB |
Output is correct |
25 |
Correct |
42 ms |
71476 KB |
Output is correct |
26 |
Correct |
38 ms |
71472 KB |
Output is correct |
27 |
Correct |
36 ms |
71448 KB |
Output is correct |
28 |
Correct |
39 ms |
71492 KB |
Output is correct |
29 |
Correct |
34 ms |
71508 KB |
Output is correct |
30 |
Correct |
32 ms |
71592 KB |
Output is correct |
31 |
Correct |
38 ms |
71528 KB |
Output is correct |
32 |
Correct |
34 ms |
71572 KB |
Output is correct |
33 |
Incorrect |
33 ms |
71476 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
71368 KB |
Output is correct |
2 |
Correct |
41 ms |
71372 KB |
Output is correct |
3 |
Correct |
34 ms |
71372 KB |
Output is correct |
4 |
Correct |
35 ms |
71480 KB |
Output is correct |
5 |
Correct |
33 ms |
71480 KB |
Output is correct |
6 |
Correct |
38 ms |
71368 KB |
Output is correct |
7 |
Correct |
33 ms |
71444 KB |
Output is correct |
8 |
Correct |
32 ms |
71380 KB |
Output is correct |
9 |
Correct |
33 ms |
71396 KB |
Output is correct |
10 |
Correct |
34 ms |
71444 KB |
Output is correct |
11 |
Correct |
34 ms |
71412 KB |
Output is correct |
12 |
Correct |
35 ms |
71412 KB |
Output is correct |
13 |
Correct |
34 ms |
71420 KB |
Output is correct |
14 |
Correct |
33 ms |
71444 KB |
Output is correct |
15 |
Correct |
33 ms |
71380 KB |
Output is correct |
16 |
Correct |
34 ms |
71492 KB |
Output is correct |
17 |
Correct |
33 ms |
71408 KB |
Output is correct |
18 |
Correct |
35 ms |
71472 KB |
Output is correct |
19 |
Correct |
36 ms |
71468 KB |
Output is correct |
20 |
Correct |
41 ms |
71372 KB |
Output is correct |
21 |
Correct |
47 ms |
71436 KB |
Output is correct |
22 |
Correct |
42 ms |
71380 KB |
Output is correct |
23 |
Correct |
38 ms |
71480 KB |
Output is correct |
24 |
Correct |
35 ms |
71500 KB |
Output is correct |
25 |
Correct |
42 ms |
71476 KB |
Output is correct |
26 |
Correct |
38 ms |
71472 KB |
Output is correct |
27 |
Correct |
36 ms |
71448 KB |
Output is correct |
28 |
Correct |
39 ms |
71492 KB |
Output is correct |
29 |
Correct |
34 ms |
71508 KB |
Output is correct |
30 |
Correct |
32 ms |
71592 KB |
Output is correct |
31 |
Correct |
38 ms |
71528 KB |
Output is correct |
32 |
Correct |
34 ms |
71572 KB |
Output is correct |
33 |
Incorrect |
33 ms |
71476 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |