Submission #1163514

#TimeUsernameProblemLanguageResultExecution timeMemory
1163514hmm789Volontiranje (COCI21_volontiranje)C++20
110 / 110
221 ms102172 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;) { while(tmp.size() && v[i].size() && v[i].back() <= tmp.back()) v[i].pop_back(); if(v[i].empty()) goto ed; if(tmp.size() && a[v[i].back()] <= a[tmp.back()]) { i--; tmp.pop_back(); continue; } tmp.push_back(v[i].back()); v[i].pop_back(); i++; } ans.push_back(tmp); } 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...