Submission #1163503

#TimeUsernameProblemLanguageResultExecution timeMemory
1163503hmm789Volontiranje (COCI21_volontiranje)C++20
50 / 110
1097 ms23112 KiB
#include <bits/stdc++.h> using namespace std; int fw[1000005]; void 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'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...