제출 #986369

#제출 시각아이디문제언어결과실행 시간메모리
986369Pyqe팀들 (IOI15_teams)C++17
77 / 100
1217 ms524288 KiB
#include "teams.h" #include <bits/stdc++.h> using namespace std; #define mp make_pair #define fr first #define sc second long long n,nn,fq[500069],inf=1e18; pair<long long,long long> a[2][500069],sk[200069]; struct segtree { long long l,r,sm; segtree *p[2]; void bd(long long lh,long long rh) { l=lh; r=rh; sm=0; if(l!=r) { long long ii,md=(l+r)/2; for(ii=0;ii<2;ii++) { p[ii]=new segtree; p[ii]->bd(!ii?l:md+1,!ii?md:r); } } } void ud(long long x,long long w) { if(l>=x&&r<=x) { sm+=w; } else { long long ii; segtree *tmp; for(ii=0;ii<2;ii++) { if(p[ii]->l<=x&&p[ii]->r>=x) { tmp=p[ii]; p[ii]=new segtree; *p[ii]=*tmp; p[ii]->ud(x,w); } } sm=p[0]->sm+p[1]->sm; } } long long qr(long long lh,long long rh,segtree *sr) { if(l>rh||r<lh) { return 0; } else if(l>=lh&&r<=rh) { return sm-sr->sm; } else { return p[0]->qr(lh,rh,sr->p[0])+p[1]->qr(lh,rh,sr->p[1]); } } long long bl(long long x,segtree *sr) { if(l==r) { return l; } else { long long ii; for(ii=0;ii<2;ii++) { if(x<=p[ii]->sm-sr->p[ii]->sm) { return p[ii]->bl(x,sr->p[ii]); } x-=p[ii]->sm-sr->p[ii]->sm; } return -1; } } } sg[500069]; void init(int on,int la[],int ra[]) { long long i,k,l; n=on; for(i=1;i<=n;i++) { k=la[i-1]; l=ra[i-1]; a[0][i]={k,l}; } sort(a[0]+1,a[0]+n+1); for(i=1;i<=n;i++) { l=a[0][i].sc; fq[l]++; a[1][i]={l,fq[l]}; } sort(a[1]+1,a[1]+n+1); for(i=n;i;i--) { l=a[0][i].sc; a[0][i].sc=lower_bound(a[1]+1,a[1]+n+1,mp(l,fq[l]))-a[1]; fq[l]--; } sg[0].bd(1,n); for(i=1;i<=n;i++) { l=a[0][i].sc; sg[i]=sg[i-1]; sg[i].ud(l,1); } } int can(int sz,int qq[]) { long long i,k,l,w,sm; sort(qq,qq+sz); nn=0; for(i=0;i<sz;i++) { sm=qq[i]; k=upper_bound(a[0]+1,a[0]+n+1,mp(sm,inf))-a[0]-1; l=lower_bound(a[1]+1,a[1]+n+1,mp(sm,0ll))-a[1]-1; for(;nn;nn--) { w=sg[k].qr(l+1,sk[nn].sc-1,&sg[sk[nn].fr]); if(w>sm) { break; } l=max(l,sk[nn].sc); sm-=w; } l=sg[k].bl(sg[k].qr(1,l,&sg[sk[nn].fr])+sm,&sg[sk[nn].fr]); if(l==-1) { return 0; } nn++; sk[nn]={k,l}; } return 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...