Submission #512930

#TimeUsernameProblemLanguageResultExecution timeMemory
512930sidonTeams (CEOI11_tea)C++17
100 / 100
915 ms85620 KiB
#include <bits/stdc++.h> using namespace std; using T = array<int, 2>; class comp{ public: bool operator()(const T &x, const T &y) { return x[0] < y[0]; } }; const int Z = 1e6+1, oo = 2e9; int N, A[Z], S[Z], P[Z]; array<int, 2> DP[Z]; const T ID = {-oo, -1}; void build(int x) { priority_queue<array<int, 2>, vector<T>, comp> b; int r = 0; b.push(DP[0]); for(int i = 1; i <= N; i++) { int R = max(-1, i - A[S[i]]); while(r < R) b.push(DP[++r]); r = R; while(!empty(b) && (b.top()[1] < i - x || b.top()[1] > R)) b.pop(); if(empty(b)) { DP[i] = ID; } else { DP[i] = b.top(); P[i] = DP[i][1]; DP[i][1] = i; ++DP[i][0]; } } } int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> N; for(int i = 1; i <= N; i++) { cin >> A[i]; S[i] = i; } fill(DP, DP+Z, ID); DP[0] = {}; sort(S, S + N + 1, [&](int i, int j) { return A[i] < A[j]; }); build(1e6); int best = DP[N][0], sz = N; for(int j=1<<20; j/=2; ) { if(sz - j < A[S[N]]) continue; build(sz - j); if(DP[N][0] == best) sz -= j; } build(sz); int curr = P[N]; vector<vector<int>> res = {{}}; for(int i = N + 1; --i; ) { if(curr == i) { res.push_back({}); curr = P[curr]; } res.back().push_back(S[i]); } cout << size(res) << '\n'; for(auto &V : res) { cout << size(V); for(auto &i : V) cout << ' ' << i; cout << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...