Submission #457943

#TimeUsernameProblemLanguageResultExecution timeMemory
457943ftkbrianComparing Plants (IOI20_plants)C++14
0 / 100
3 ms332 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; } for(int i = 1 ; i < n ; i++) { num[R] = 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); ///R의 왼쪽 편에 다음 R이 있는지 확인 pll t = query(1,0,n-1,max(R-k+1,0),R); if(R-k+1 < 0) { pll t2 = query(1,0,n-1,n+R-k+1,n-1); if(t2.f == 0) t = t2; } if(t.f == 0) { ll R2 = t.s; pll t2 = query(1,0,n-1,max(R2-k+1,0),max(R2-1,0)); if(t2.f != 0) { if(R2-k+1 < 0 && query(1,0,n-1,n+R2-k+1,n-1).f == 0) { continue; } R = R2; continue; } } ///R의 오른 편에 다음 R이 있는지 확인, 반드시 있어야 함 t = query(1,0,n-1,R,min(R+k-1,n-1)); if(R+k-1 >= n && t.f != 0) { t = query(1,0,n-1,0,R+k-1-n); } R = t.s; } num[R] = n; } 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...