Submission #305042

#TimeUsernameProblemLanguageResultExecution timeMemory
305042Wu_RenComparing Plants (IOI20_plants)C++11
100 / 100
1509 ms22768 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; int tag[1600010],mn[1600010],st[400010],t=0,n,k; vector<int>tmp1,tmp2; void pushdown(int t){ mn[t<<1]+=tag[t]; mn[t<<1|1]+=tag[t]; tag[t<<1]+=tag[t]; tag[t<<1|1]+=tag[t]; tag[t]=0; } void add(int ll,int rr,int l,int r,int t,int c){ if(rr<l||ll>r) return; if(ll<=l&&r<=rr){ tag[t]+=c; mn[t]+=c; return; } pushdown(t); int mid=(l+r)>>1; if(ll<=mid) add(ll,rr,l,mid,t<<1,c); if(mid<rr) add(ll,rr,mid+1,r,t<<1|1,c); mn[t]=min(mn[t<<1],mn[t<<1|1]); } int query(int l,int r,int t){ if(mn[t]>0) return -1; if(l==r) return l; pushdown(t); int mid=(l+r)>>1; if(mn[t<<1]>0) return query(mid+1,r,t<<1|1); else return query(l,mid,t<<1); } vector<int> work(vector<int> now){ vector<int>ans; ans.resize(now.size()); t=0,memset(tag,0,sizeof(tag)),memset(mn,0,sizeof(mn)); for(int i=0;i<2*n;i++) add(i,i,0,2*n-1,1,now[i]); for(int i=1;i<=2*n;i++){ int x=query(0,2*n-1,1); while(x<0&&t) add(st[t],2*n-1,0,2*n-1,1,-1),t--,x=query(0,2*n-1,1); ans[x]=i; add(x,x,0,2*n-1,1,1e9); add(x-k+1,x-1,0,2*n-1,1,-1); if(x-k+1<0) st[++t]=2*n+x-k; } return ans; } void init(int _k,vector<int> r){ n=r.size(),k=_k; for(int i=0;i<n;i++) r.push_back(r[i]); tmp1=work(r); for(int i=0;i<2*n;i++) r[i]=k-1-r[i]; tmp2=work(r); } int compare_plants(int x, int y){ if(x>y) return -compare_plants(y,x); if(tmp1[x]>tmp1[y]||tmp2[x+n]<tmp2[y]) return -1; if(tmp2[x]>tmp2[y]||tmp1[x+n]<tmp1[y]) return 1; 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...