This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
pll a = query(id*2,s,m,qs,qe);
pll b = query(id*2+1,m+1,e,qs,qe);
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(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++) {
r[R] += k;
for(int t = 0 ; t < k ; t++) {
r[R]--;
R = (R+n-1)%n;
}
hp = 0;
for(int i = n-k+1 ; i < n ; i++) {
hp += (r[i]>0?1:0);
}
l = n-k+1,R = 0;
while(R < n) {
if(r[R] == 0 && num[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] = i+1;
}
}
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;
| ^
plants.cpp:35:9: warning: variable 'a' set but not used [-Wunused-but-set-variable]
35 | pll a = query(id*2,s,m,qs,qe);
| ^
plants.cpp:36:9: warning: variable 'b' set but not used [-Wunused-but-set-variable]
36 | pll b = query(id*2+1,m+1,e,qs,qe);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |