#include <bits/stdc++.h>
#include "candies.h"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
int n,m;
ll sum[N<<2],mx[N<<2],mn[N<<2];//区间和,前缀最值
struct node{int x,v;};
#define ls (p<<1)
#define rs (p<<1|1)
#define mid ((L+R)>>1)
void up(int p){
sum[p]=sum[ls]+sum[rs];
mx[p]=max(mx[ls],sum[ls]+mx[rs]);
mn[p]=min(mn[ls],sum[ls]+mn[rs]);
}
void modify(int p,int L,int R,int x,int v){
if(L>x||R<x)return;
if(L==R){
sum[p]+=v;
mx[p]=mn[p]=v;
return;
}
modify(ls,L,mid,x,v),modify(rs,mid+1,R,x,v);
up(p);
}
int Q(int p,int L,int R,int v,int lim){//线段树上二分
//找到位置直接做
if(L==R)return min((ll)lim,max(0ll,v+sum[p]));
//若右边超限制
if(mx[rs]-mn[rs]>=lim)return Q(rs,mid+1,R,v,lim);
//否则先做左边
v=Q(ls,L,mid,v,lim);
//如果右边会<0
if(v+mn[rs]<0)return sum[rs]-mn[rs];
//如果右边会>lim
if(v+mx[rs]>lim)return sum[rs]-(mx[rs]-lim);
return v+sum[rs];
}
vi distribute_candies(vi c,vi l,vi r,vi v){
n=c.size(),m=l.size();
vi s;
vector <node> Q[N];
rep(i,0,m-1){
int L=l[i],R=r[i],V=v[i];
Q[L].pb({i+1,V}),Q[R+1].pb({i+1,-V});
}
rep(i,0,n-1){//扫描线
for(auto t:Q[i]){
modify(1,1,m,t.x,t.v);
}
s[i]=Q(1,1,m,0,c[i]);
}
return s;
}
int main(){
return 0;
}
Compilation message
candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:66:28: error: 'Q' cannot be used as a function
66 | s[i]=Q(1,1,m,0,c[i]);
| ^