#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
#define lg long long
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mid (lr+hr)/2
const lg N = 1e6+5;
vector<lg> val(N), lev[N], v(N), cur;
vector<vector<lg>> ans;
lg lis = 0, n;
bool dfs(lg idx)
{
// cout << "IDX: " << idx << '\n';
// for(auto it : cur) cout << it << ' ';
// cout << '\n';
if(idx == lis)
{
ans.push_back(cur);
return true;
}
while(lev[idx].size() && lev[idx].back() < cur.back()) lev[idx].pop_back();
while(lev[idx].size())
{
if(v[lev[idx].back()] < v[cur.back()])
{
return false;
}
cur.push_back(lev[idx].back());
lev[idx].pop_back();
if(dfs(idx+1)) return true;
cur.pop_back();
}
return false;
}
int main()
{
fastio;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> v[i];
if(!lis || val[lis-1] < v[i])
{
val[lis] = v[i];
lev[lis].push_back(i);
lis++;
}
else{
lg idx = lower_bound(val.begin(), val.begin()+lis, v[i])-val.begin();
lev[idx].push_back(i);
val[idx] = v[i];
}
}
for(int i = 0; i <= n; i++) reverse(lev[i].begin(), lev[i].end());
while(lev[0].size())
{
cur.push_back(lev[0].back());
lev[0].pop_back();
dfs(1);
cur.clear();
}
cout << ans.size() << ' ' << lis << '\n';
for(auto it : ans)
{
for(auto it2 : it) cout << it2 << ' ';
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
39516 KB |
Output is correct |
2 |
Correct |
9 ms |
39516 KB |
Output is correct |
3 |
Correct |
8 ms |
39516 KB |
Output is correct |
4 |
Correct |
9 ms |
39616 KB |
Output is correct |
5 |
Correct |
9 ms |
39516 KB |
Output is correct |
6 |
Correct |
8 ms |
39516 KB |
Output is correct |
7 |
Correct |
10 ms |
39512 KB |
Output is correct |
8 |
Correct |
9 ms |
39516 KB |
Output is correct |
9 |
Correct |
10 ms |
39512 KB |
Output is correct |
10 |
Correct |
8 ms |
39420 KB |
Output is correct |
11 |
Correct |
8 ms |
39516 KB |
Output is correct |
12 |
Correct |
8 ms |
39516 KB |
Output is correct |
13 |
Correct |
9 ms |
39604 KB |
Output is correct |
14 |
Correct |
9 ms |
39512 KB |
Output is correct |
15 |
Correct |
9 ms |
39516 KB |
Output is correct |
16 |
Correct |
9 ms |
39768 KB |
Output is correct |
17 |
Correct |
8 ms |
39516 KB |
Output is correct |
18 |
Correct |
8 ms |
39432 KB |
Output is correct |
19 |
Correct |
9 ms |
39516 KB |
Output is correct |
20 |
Correct |
9 ms |
39440 KB |
Output is correct |
21 |
Correct |
8 ms |
39376 KB |
Output is correct |
22 |
Correct |
10 ms |
39516 KB |
Output is correct |
23 |
Correct |
8 ms |
39448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
39516 KB |
Output is correct |
2 |
Correct |
9 ms |
39516 KB |
Output is correct |
3 |
Correct |
8 ms |
39516 KB |
Output is correct |
4 |
Correct |
9 ms |
39616 KB |
Output is correct |
5 |
Correct |
9 ms |
39516 KB |
Output is correct |
6 |
Correct |
8 ms |
39516 KB |
Output is correct |
7 |
Correct |
10 ms |
39512 KB |
Output is correct |
8 |
Correct |
9 ms |
39516 KB |
Output is correct |
9 |
Correct |
10 ms |
39512 KB |
Output is correct |
10 |
Correct |
8 ms |
39420 KB |
Output is correct |
11 |
Correct |
8 ms |
39516 KB |
Output is correct |
12 |
Correct |
8 ms |
39516 KB |
Output is correct |
13 |
Correct |
9 ms |
39604 KB |
Output is correct |
14 |
Correct |
9 ms |
39512 KB |
Output is correct |
15 |
Correct |
9 ms |
39516 KB |
Output is correct |
16 |
Correct |
9 ms |
39768 KB |
Output is correct |
17 |
Correct |
8 ms |
39516 KB |
Output is correct |
18 |
Correct |
8 ms |
39432 KB |
Output is correct |
19 |
Correct |
9 ms |
39516 KB |
Output is correct |
20 |
Correct |
9 ms |
39440 KB |
Output is correct |
21 |
Correct |
8 ms |
39376 KB |
Output is correct |
22 |
Correct |
10 ms |
39516 KB |
Output is correct |
23 |
Correct |
8 ms |
39448 KB |
Output is correct |
24 |
Correct |
9 ms |
39516 KB |
Output is correct |
25 |
Correct |
8 ms |
39620 KB |
Output is correct |
26 |
Correct |
8 ms |
39512 KB |
Output is correct |
27 |
Correct |
9 ms |
39516 KB |
Output is correct |
28 |
Correct |
10 ms |
39512 KB |
Output is correct |
29 |
Correct |
11 ms |
39516 KB |
Output is correct |
30 |
Correct |
10 ms |
39516 KB |
Output is correct |
31 |
Correct |
9 ms |
39512 KB |
Output is correct |
32 |
Correct |
8 ms |
39516 KB |
Output is correct |
33 |
Correct |
8 ms |
39516 KB |
Output is correct |
34 |
Correct |
10 ms |
39516 KB |
Output is correct |
35 |
Correct |
9 ms |
39728 KB |
Output is correct |
36 |
Correct |
9 ms |
39512 KB |
Output is correct |
37 |
Correct |
9 ms |
39512 KB |
Output is correct |
38 |
Correct |
8 ms |
39516 KB |
Output is correct |
39 |
Correct |
9 ms |
39516 KB |
Output is correct |
40 |
Correct |
8 ms |
39516 KB |
Output is correct |
41 |
Correct |
8 ms |
39516 KB |
Output is correct |
42 |
Correct |
8 ms |
39516 KB |
Output is correct |
43 |
Correct |
8 ms |
39516 KB |
Output is correct |
44 |
Correct |
9 ms |
39568 KB |
Output is correct |
45 |
Correct |
9 ms |
39524 KB |
Output is correct |
46 |
Correct |
10 ms |
39516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
39516 KB |
Output is correct |
2 |
Correct |
9 ms |
39516 KB |
Output is correct |
3 |
Correct |
8 ms |
39516 KB |
Output is correct |
4 |
Correct |
9 ms |
39616 KB |
Output is correct |
5 |
Correct |
9 ms |
39516 KB |
Output is correct |
6 |
Correct |
8 ms |
39516 KB |
Output is correct |
7 |
Correct |
10 ms |
39512 KB |
Output is correct |
8 |
Correct |
9 ms |
39516 KB |
Output is correct |
9 |
Correct |
10 ms |
39512 KB |
Output is correct |
10 |
Correct |
8 ms |
39420 KB |
Output is correct |
11 |
Correct |
8 ms |
39516 KB |
Output is correct |
12 |
Correct |
8 ms |
39516 KB |
Output is correct |
13 |
Correct |
9 ms |
39604 KB |
Output is correct |
14 |
Correct |
9 ms |
39512 KB |
Output is correct |
15 |
Correct |
9 ms |
39516 KB |
Output is correct |
16 |
Correct |
9 ms |
39768 KB |
Output is correct |
17 |
Correct |
8 ms |
39516 KB |
Output is correct |
18 |
Correct |
8 ms |
39432 KB |
Output is correct |
19 |
Correct |
9 ms |
39516 KB |
Output is correct |
20 |
Correct |
9 ms |
39440 KB |
Output is correct |
21 |
Correct |
8 ms |
39376 KB |
Output is correct |
22 |
Correct |
10 ms |
39516 KB |
Output is correct |
23 |
Correct |
8 ms |
39448 KB |
Output is correct |
24 |
Correct |
9 ms |
39516 KB |
Output is correct |
25 |
Correct |
8 ms |
39620 KB |
Output is correct |
26 |
Correct |
8 ms |
39512 KB |
Output is correct |
27 |
Correct |
9 ms |
39516 KB |
Output is correct |
28 |
Correct |
10 ms |
39512 KB |
Output is correct |
29 |
Correct |
11 ms |
39516 KB |
Output is correct |
30 |
Correct |
10 ms |
39516 KB |
Output is correct |
31 |
Correct |
9 ms |
39512 KB |
Output is correct |
32 |
Correct |
8 ms |
39516 KB |
Output is correct |
33 |
Correct |
8 ms |
39516 KB |
Output is correct |
34 |
Correct |
10 ms |
39516 KB |
Output is correct |
35 |
Correct |
9 ms |
39728 KB |
Output is correct |
36 |
Correct |
9 ms |
39512 KB |
Output is correct |
37 |
Correct |
9 ms |
39512 KB |
Output is correct |
38 |
Correct |
8 ms |
39516 KB |
Output is correct |
39 |
Correct |
9 ms |
39516 KB |
Output is correct |
40 |
Correct |
8 ms |
39516 KB |
Output is correct |
41 |
Correct |
8 ms |
39516 KB |
Output is correct |
42 |
Correct |
8 ms |
39516 KB |
Output is correct |
43 |
Correct |
8 ms |
39516 KB |
Output is correct |
44 |
Correct |
9 ms |
39568 KB |
Output is correct |
45 |
Correct |
9 ms |
39524 KB |
Output is correct |
46 |
Correct |
10 ms |
39516 KB |
Output is correct |
47 |
Correct |
76 ms |
46672 KB |
Output is correct |
48 |
Correct |
65 ms |
46924 KB |
Output is correct |
49 |
Correct |
87 ms |
50164 KB |
Output is correct |
50 |
Correct |
135 ms |
57684 KB |
Output is correct |
51 |
Correct |
40 ms |
43856 KB |
Output is correct |
52 |
Correct |
210 ms |
155056 KB |
Output is correct |
53 |
Correct |
212 ms |
117172 KB |
Output is correct |
54 |
Correct |
174 ms |
69240 KB |
Output is correct |
55 |
Correct |
154 ms |
69060 KB |
Output is correct |
56 |
Correct |
9 ms |
39772 KB |
Output is correct |
57 |
Correct |
108 ms |
54400 KB |
Output is correct |
58 |
Correct |
33 ms |
42836 KB |
Output is correct |
59 |
Correct |
28 ms |
42576 KB |
Output is correct |
60 |
Correct |
115 ms |
54644 KB |
Output is correct |
61 |
Correct |
76 ms |
49316 KB |
Output is correct |
62 |
Correct |
9 ms |
39512 KB |
Output is correct |
63 |
Correct |
9 ms |
39516 KB |
Output is correct |
64 |
Correct |
9 ms |
39516 KB |
Output is correct |
65 |
Correct |
9 ms |
39440 KB |
Output is correct |
66 |
Correct |
9 ms |
39512 KB |
Output is correct |
67 |
Correct |
8 ms |
39512 KB |
Output is correct |
68 |
Correct |
10 ms |
39464 KB |
Output is correct |
69 |
Correct |
9 ms |
39516 KB |
Output is correct |