#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
pair<int, int> tree[N * 4];
int arr[N];
int vis[N];
int p[N];
int n;
void build(int node = 1, int l = 1, int r = n)
{
if (l == r)
{
tree[node] = {0, 0};
return;
}
int mid = (l + r) / 2;
build(node * 2, l, mid), build(node * 2 + 1, mid + 1, r);
tree[node] = {0, 0};
}
pair<int, int> comb(pair<int, int> x, pair<int, int> y)
{
if (x.first == y.first)
return (x.second > y.second ? y : x);
return (x.first < y.first ? y : x);
}
void update(int idx, int val, int node = 1, int l = 1, int r = n)
{
if (l == r)
{
tree[node] = {val, idx};
return;
}
int mid = (l + r) / 2;
if (idx <= mid)
update(idx, val, node * 2, l, mid);
else
update(idx, val, node * 2 + 1, mid + 1, r);
tree[node] = comb(tree[node * 2], tree[node * 2 + 1]);
}
pair<int, int> query(int ql, int qr, int node = 1, int l = 1, int r = n)
{
if (ql <= l && r <= qr)
return tree[node];
if (qr < l || r < ql)
return {0, 0};
int mid = (l + r) / 2;
return comb(query(ql, qr, node * 2, l, mid), query(ql, qr, node * 2 + 1, mid + 1, r));
}
vector<int> lis()
{
build();
vector<int> ret;
for (int i = n; i >= 1; i--)
{
if (vis[arr[i]])
continue;
pair<int, int> hi = query(arr[i], n);
if (hi.first == 0)
update(arr[i], 1), p[arr[i]] = arr[i];
else
update(arr[i], hi.first + 1), p[arr[i]] = hi.second;
}
pair<int, int> hi = query(1, n);
if (hi.first == 0)
return {};
else
{
while (true)
{
ret.push_back(hi.second);
vis[hi.second] = 1;
if (hi.second == p[hi.second])
break;
hi.second = p[hi.second];
}
return ret;
}
}
int main()
{
cin >> n;
vector<int> loc(n + 1);
for (int i = 1; i <= n; i++)
cin >> arr[i], loc[arr[i]] = i;
int mx = 0;
vector<vector<int>> ans;
while (true)
{
vector<int> hi = lis();
if ((int)hi.size() < mx)
break;
mx = hi.size();
ans.push_back(hi);
}
cout << ans.size() << " " << mx << "\n";
for (auto v : ans)
{
for (auto s : v)
cout << loc[s] << " ";
cout << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
108 ms |
484 KB |
Output is correct |
31 |
Correct |
4 ms |
344 KB |
Output is correct |
32 |
Correct |
4 ms |
348 KB |
Output is correct |
33 |
Correct |
40 ms |
604 KB |
Output is correct |
34 |
Correct |
29 ms |
480 KB |
Output is correct |
35 |
Correct |
32 ms |
604 KB |
Output is correct |
36 |
Correct |
2 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
2 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
108 ms |
484 KB |
Output is correct |
31 |
Correct |
4 ms |
344 KB |
Output is correct |
32 |
Correct |
4 ms |
348 KB |
Output is correct |
33 |
Correct |
40 ms |
604 KB |
Output is correct |
34 |
Correct |
29 ms |
480 KB |
Output is correct |
35 |
Correct |
32 ms |
604 KB |
Output is correct |
36 |
Correct |
2 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
2 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
544 KB |
Output is correct |
47 |
Runtime error |
5 ms |
4188 KB |
Execution killed with signal 11 |
48 |
Halted |
0 ms |
0 KB |
- |