Submission #960110

#TimeUsernameProblemLanguageResultExecution timeMemory
960110PetyVolontiranje (COCI21_volontiranje)C++14
10 / 110
20 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()) { int last = *LIS[mx].begin(); last = -last; 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) break; } if (sir.size() < mx) continue; 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; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:55:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   55 |     if (sir.size() < mx) continue;
      |         ~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...