Submission #1019609

#TimeUsernameProblemLanguageResultExecution timeMemory
1019609TAhmed33Volontiranje (COCI21_volontiranje)C++98
110 / 110
206 ms105104 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e6 + 25; int p[MAXN], n; int cur[MAXN]; vector <int> dd[MAXN]; void solve () { cin >> n; cur[0] = -MAXN; for (int i = 1; i <= n; i++) { cin >> p[i]; cur[i] = MAXN; } int v = 0; for (int i = 1; i <= n; i++) { int g = upper_bound(cur, cur + n + 1, p[i]) - cur; dd[g].push_back(i); cur[g] = p[i]; v = max(v, g); } for (int i = 1; i <= v; i++) { reverse(dd[i].begin(), dd[i].end()); } vector <vector <int>> ans; while (true) { bool f = 0; for (int i = 1; i < v; i++) { if (dd[i].empty() || dd[i + 1].empty()) { f = 1; break; } while (!dd[i + 1].empty() && dd[i + 1].back() < dd[i].back()) { dd[i + 1].pop_back(); } if (p[dd[i + 1].back()] < p[dd[i].back()]) { dd[i].pop_back(); i -= 2; if (i == -1) i = 0; } } if (f) { break; } vector <int> gg; for (int i = 1; i <= v; i++) { if (dd[i].empty()) { f = 1; break; } gg.push_back(dd[i].back()); dd[i].pop_back(); } if (f) { break; } ans.push_back(gg); } cout << int(ans.size()) << ' ' << v << '\n'; for (auto i : ans) { for (auto j : i) { cout << j << " "; } cout << '\n'; } return; } signed main () { ios::sync_with_stdio(0); cin.tie(0); int tc = 1; //cin >> tc; while (tc--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...