Submission #960108

#TimeUsernameProblemLanguageResultExecution timeMemory
960108PetyVolontiranje (COCI21_volontiranje)C++14
0 / 110
19 ms47704 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e6+2; int aib[N], dp[N], n, a[N]; set<int>LIS[N]; void update (int x, int val) { for (int i = x; i <= n; i += (i & -i)) aib[i] = max(aib[i],val); } int query (int x) { int s= 0; for (int i = x; i; i -= (i & -i)) s = max(s, aib[i]); return s; } int main () { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; int mx = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; a[i] = x; dp[i] = query(x) + 1; update(x, dp[i]); LIS[dp[i]].insert(i); mx = max(mx, dp[i]); } vector<vector<int>>ans; while (LIS[mx].size()) { bool ok = 1; int last = *LIS[mx].rbegin(); LIS[mx].erase(last); vector<int>sir; sir.push_back(last); for (int i = mx - 1; i >= 1; i--) { bool gasit = 0; for (auto it : LIS[i]) { if (it < last && a[it] < a[last]) { last = it; sir.push_back(last); gasit = 1; break; } } LIS[i].erase(last); if (!gasit) {ok = 0; break;} } if (!ok) break; reverse(sir.begin(), sir.end()); ans.push_back(sir); } cout << ans.size() << " " << ans[0].size() << "\n"; for (auto s : ans) { for (auto it : s) cout << it << " "; cout << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...