Submission #738204

#TimeUsernameProblemLanguageResultExecution timeMemory
738204bobthebuilderComparing Plants (IOI20_plants)C++17
14 / 100
79 ms4172 KiB
#include "plants.h" #include<bits/stdc++.h> using namespace std; #define sz(x) (int)x.size() #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define pb push_back #define lowb(x) (x&(-x)) #define ALL(_x) _x.begin(),_x.end() #define pii pair<int,int> #define f first #define s second #define SORT_UNIQUE(x) sort(ALL(x)),x.erase(unique(ALL(x)),x.end()) #define ll long long #define MNTO(x,y) x=min(x,y) #define MXTO(x,y) x=max(x,y) const int maxn=2e5+5; const int INF=0x3f3f3f3f; namespace { int seg[4*maxn],pos[4*maxn]; int arr[maxn]; int lazy[4*maxn]; int ans[maxn]; int cur; int k; int n; } void pushdown(int idx,int l,int r){ if(!lazy[idx]){ return; } seg[idx]+=lazy[idx]; if(l==r){ lazy[idx]=0; return; } lazy[idx*2]+=lazy[idx]; lazy[idx*2+1]+=lazy[idx]; lazy[idx]=0; } void build(int idx,int l,int r){ if(l==r){ seg[idx]=arr[l]; pos[idx]=l; return; } int mid=(l+r)/2; build(idx*2,l,mid),build(idx*2+1,mid+1,r); seg[idx]=min(seg[idx*2],seg[idx*2+1]); if(seg[idx]==seg[idx*2]) pos[idx]=pos[idx*2]; else pos[idx]=pos[idx*2+1]; } void upd(int idx,int l,int r,int ql,int qr,int x){ pushdown(idx,l,r); if(r<ql or l>qr) return; if(ql<=l and r<=qr){ lazy[idx]+=x; pushdown(idx,l,r); return; } int mid=(l+r)/2; upd(idx*2,l,mid,ql,qr,x); upd(idx*2+1,mid+1,r,ql,qr,x); seg[idx]=min(seg[idx*2],seg[idx*2+1]); if(seg[idx]==seg[idx*2]) pos[idx]=pos[idx*2]; else pos[idx]=pos[idx*2+1]; } pii query(int idx,int l,int r,int ql,int qr){ if(ql>qr) return {INF,-1}; pushdown(idx,l,r); if(r<ql or l>qr) return {INF,-1}; if(ql<=l and r<=qr){ return {seg[idx],pos[idx]}; } int mid=(l+r)/2; return min(query(idx*2,l,mid,ql,qr),query(idx*2+1,mid+1,r,ql,qr)); } void get(int z){ pii mn; if(z-k<0){ mn=min(query(1,0,n-1,0,z-1),query(1,0,n-1,n+(z-k),n-1)); } else{ mn=query(1,0,n-1,z-k,z-1); } if(mn.f==0){ get(mn.s); } ans[z]=cur--; if(z-k<0){ upd(1,0,n-1,0,z-1,-1); upd(1,0,n-1,n+(z-k),n-1,-1); } else{ upd(1,0,n-1,z-k,z-1,-1); } upd(1,0,n-1,z,z,INF); } void init(int K, std::vector<int> r) { k=K; --k; n=sz(r); REP(i,n){ arr[i]=r[i]; } cur=n; build(1,0,n-1); while(cur>0){ int z=query(1,0,n-1,0,n-1).s; get(z); } } int compare_plants(int x, int y) { if(ans[x]>ans[y]){ return 1; } 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...