#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
using vi = vector<int>;
using ll = long long;
const int mxN = (int)2e5+10;
const ll LINF = (ll)1e18;
int n, q;
ll mxsuf[mxN], mnsuf[mxN], pref[mxN];
array<ll,3> seg[mxN*2], Init={LINF,-LINF, 0ll};
void apply(int p, ll a, ll b, ll c){
seg[p][0] = min(a, max(seg[p][0]+c, b));
seg[p][1] = max(seg[p][1]+c, b);
seg[p][2] += c;
}
void prop(int p, int l, int r){
if(l==r or seg[p]==Init) return;
int mid = (l+r)/2; int rp = p+2*(mid-l+1);
auto [a,b,c] = seg[p]; // push down
apply(p+1,a,b,c), apply(rp,a,b,c); seg[p] = Init;
}
void upd(int i, int j, ll a, ll b, ll c, int p=0, int l=0, int r=n-1){
if(i>j or i>r or j<l) return;
if(i<=l and r<=j){ apply(p,a,b,c); return; }
prop(p,l,r); // propagate to preserve order
int mid = (l+r)/2; int rp = p+2*(mid-l+1);
upd(i,j,a,b,c,p+1,l,mid); upd(i,j,a,b,c,rp,mid+1,r);
}
ll query(int i, int p=0, int l=0, int r=n-1){
if(l==r) return min(seg[p][0],max(A[l]+seg[p][2],seg[p][1]));
prop(p,l,r); // propagate to preserve order
int mid = (l+r)/2; int rp = p+2*(mid-l+1);
if(i<=mid) return query(i,p+1,l,mid);
return query(i,rp,mid+1,r);
}
vi distribute_candies(vi c, vi l, vi r, vi v){
n = sz(c), q = sz(l); vector<int> ans(n,0);
if(*max_element(all(l))==0 and *min_element(all(r))==n-1){
mxsuf[q+1]=-LINF; mnsuf[q+1]=LINF; pref[0]=0;
for(int i = 0; i < q; i++) pref[i+1]=pref[i]+v[i];
for(int i = q; i >= 0; i--) mxsuf[i]=max(mxsuf[i+1],pref[i]);
for(int i = q; i >= 0; i--) mnsuf[i]=min(mnsuf[i+1],pref[i]);
for(int i = 0; i < n; i++){
int k = 0;
for(int j = 0; j < q; j++){
ans[i]+=v[j];
if(ans[i]<=0) ans[i]=0,k=-(j+1);
if(ans[i]>=c[i]) ans[i]=c[i],k=(j+1);
}
ans[i] = 0;
if(mxsuf[0]-mnsuf[0] < c[i]){
ans[i]+=pref[q]; continue;
}
int L = 0, R = q;
while(L<R){
int mid = (L+R+1)/2;
if(mxsuf[mid]-mnsuf[mid] >= c[i]) L=mid;
else R=mid-1;
}
L++;
if(v[L-1]>0) ans[i]=c[i];
ans[i]+=pref[q]-pref[L];
}
}
else{
fill(seg, seg+n*2,Init);
for(int i = 0; i < q; i++){
upd(l[i],r[i],INF,-INF,v[i]);
upd(l[i],r[i],c[l[i]],-INF,0);
upd(l[i],r[i],INF,0,0);
}
for(int i = 0; i < n; i++) ans[i]=query(i);
}
return ans;
}
Compilation message
candies.cpp: In function 'll query(int, int, int, int)':
candies.cpp:37:39: error: 'A' was not declared in this scope
37 | if(l==r) return min(seg[p][0],max(A[l]+seg[p][2],seg[p][1]));
| ^
candies.cpp: In function 'vi distribute_candies(vi, vi, vi, vi)':
candies.cpp:76:18: error: 'INF' was not declared in this scope; did you mean 'LINF'?
76 | upd(l[i],r[i],INF,-INF,v[i]);
| ^~~
| LINF