Submission #457933

#TimeUsernameProblemLanguageResultExecution timeMemory
457933ftkbrianComparing Plants (IOI20_plants)C++14
0 / 100
1 ms256 KiB
#include "plants.h" #include<bits/stdc++.h> using namespace std; typedef int ll; #define pll pair<int,int> #define f first #define s second pll ST[808080]; int lz[808080],inf = 1e9,num[202020]; pll hap(pll a,pll b) { if(a.f <= b.f) return a; return b; } void busy(ll id) { lz[id*2] += lz[id]; lz[id*2+1] += lz[id]; ST[id*2].f += lz[id], ST[id*2+1].f += lz[id]; lz[id] = 0; } void upd(ll id,ll s,ll e,ll qs,ll qe,ll v) { if(s > qe || e < qs) return; if(s == e) { ST[id].f += v; ST[id].s = s; return; } if(qs <= s && e <= qe) { ST[id].f += v; lz[id] += v; return; } ll m = s+e>>1; busy(id); upd(id*2,s,m,qs,qe,v); upd(id*2+1,m+1,e,qs,qe,v); ST[id] = hap(ST[id*2],ST[id*2+1]); } pll query(ll id,ll s,ll e,ll qs,ll qe) { if(s > qe || e < qs) return {inf,-1}; if(qs <= s && e <= qe) return ST[id]; ll m = s+e>>1; busy(id); return hap(query(id*2,s,m,qs,qe),query(id*2+1,m+1,e,qs,qe)); } int n,hp; void init(int k, vector<int> r) { n = r.size(); for(int i = 0 ; i < n ; i++) upd(1,0,n-1,i,i,r[i]); for(int i = n-k+1 ; i < n ; i++) { hp += (r[i]>0?1:0); } int l = n-k+1,R = 0; while(R < n) { if(r[R] == 0 && hp == k-1) break; hp += (r[R]>0?1:0); hp -= (r[l]>0?1:0); l = (l+1)%n; R = (R+1)%n; } num[R] = 1; for(int i = 1 ; i < n ; i++) { upd(1,0,n-1,R,R,k); upd(1,0,n-1,max(R-k+1,0),R,-1); if(R-k+1 < 0) upd(1,0,n-1,n+R-k+1,n-1,-1); pll t = query(1,0,n-1,R,min(R+k-1,n-1)); if(t.f == 0) R = t.s; else R = query(1,0,n-1,0,R+k-1-n).s; } } int compare_plants(int x, int y) { if(num[x] < num[y]) return 1; return -1; }

Compilation message (stderr)

plants.cpp: In function 'void upd(ll, ll, ll, ll, ll, ll)':
plants.cpp:25:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |     ll m = s+e>>1;
      |             ^
plants.cpp: In function 'std::pair<int, int> query(ll, ll, ll, ll, ll)':
plants.cpp:33:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |     ll m = s+e>>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...