# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1163499 | hmm789 | Volontiranje (COCI21_volontiranje) | C++20 | 0 ms | 320 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int fw[1000005];
int update(int x, int v) {
for(x++; x < 1000005; x += x&-x) fw[x] = max(fw[x], v);
}
int query(int x) {
int ans = 0;
for(x++; x; x -= x&-x) ans = max(ans, fw[x]);
return ans;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, lis = 0;
cin >> n;
int a[n], dp[n];
vector<int> v[n+1];
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) {
dp[i] = query(a[i]-1)+1;
update(a[i], dp[i]);
v[dp[i]].push_back(i);
lis = max(lis, dp[i]);
}
for(int i = 1; i <= n; i++) reverse(v[i].begin(), v[i].end());
vector<vector<int>> ans;
while(1) {
vector<int> tmp;
for(int i = 1; i <= lis; i++) {
while(tmp.size() && v[i].size() && v[i].back() <= tmp.back()) v[i].pop_back();
if(v[i].empty()) goto ed;
tmp.push_back(v[i].back());
}
int idx = -1;
for(int i = 1; i < tmp.size(); i++) if(a[tmp[i-1]] >= a[tmp[i]]) {
idx = i; break;
}
if(idx == -1) {
for(int i = 1; i <= lis; i++) v[i].pop_back();
ans.push_back(tmp);
} else v[idx].pop_back();
}
ed:;
cout << ans.size() << " " << lis << '\n';
for(auto i : ans) {
for(auto j : i) cout << j+1 << " ";
cout << '\n';
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |