#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
pair<int, int> tree[N * 4];
vector<vector<int>> ans;
int arr[N];
int mx = 0;
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));
}
void lis()
{
build();
vector<int> ret;
for (int i = n; i >= 1; i--)
{
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, update(hi.second, 0);
}
pair<int, int> hi = query(1, n);
mx = hi.first;
while (hi.first == mx)
{
vector<int> tmp;
while (true)
{
tmp.push_back(hi.second);
update(hi.second, 0);
if (hi.second == p[hi.second])
break;
hi.second = p[hi.second];
}
ans.push_back(tmp);
hi = query(1, n);
}
}
int main()
{
cin >> n;
vector<int> loc(n + 1);
for (int i = 1; i <= n; i++)
cin >> arr[i], loc[arr[i]] = i;
lis();
cout << ans.size() << " " << mx << "\n";
for (auto v : ans)
{
for (auto s : v)
cout << loc[s] << " ";
cout << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
length of the longest increasing subsequence doesn't match |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
length of the longest increasing subsequence doesn't match |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
length of the longest increasing subsequence doesn't match |
4 |
Halted |
0 ms |
0 KB |
- |