Submission #491657

#TimeUsernameProblemLanguageResultExecution timeMemory
491657Bench0310Teams (CEOI11_tea)C++17
40 / 100
2583 ms43284 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=1000005; vector<array<int,2>> tree(4*N,{0,0}); void update(int idx,int l,int r,int pos,int x) { if(l==r) tree[idx]={x,pos}; else { int m=(l+r)/2; if(pos<=m) update(2*idx,l,m,pos,x); else update(2*idx+1,m+1,r,pos,x); tree[idx]=max(tree[2*idx],tree[2*idx+1]); } } array<int,2> query(int idx,int l,int r,int ql,int qr) { if(ql>qr) return {-1,0}; if(l==ql&&r==qr) return tree[idx]; int m=(l+r)/2; return max(query(2*idx,l,m,ql,min(qr,m)),query(2*idx+1,m+1,r,max(ql,m+1),qr)); } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<array<int,2>> a(n+1,{0,0}); for(int i=1;i<=n;i++) { cin >> a[i][0]; a[i][1]=i; } sort(a.begin(),a.end()); vector<int> p(n+1,0); auto go=[&](int lim)->int { int t=0; update(1,0,n,0,0); for(int i=1;i<=n;i++) { auto [x,j]=query(1,0,n,max(0,i-lim),i-a[i][0]); if(x==-1) update(1,0,n,i,-1); else { update(1,0,n,i,x+1); p[i]=j; t=x+1; } } for(int i=1;i<=4*n;i++) tree[i]={-1,0}; return t; }; int cnt=go(n); int l=0,r=n; while(l<r-1) { int m=(l+r)/2; if(go(m)==cnt) r=m; else l=m; } cout << cnt << "\n"; go(r); int idx=n; while(idx>=1) { cout << idx-p[idx] << " "; for(int i=p[idx]+1;i<=idx;i++) cout << a[i][1] << " \n"[i==idx]; idx=p[idx]; } return 0; }
#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...