#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[x]));
//若右边超限制
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 'int Q(int, int, int, int, int)':
candies.cpp:43:46: error: 'x' was not declared in this scope
43 | if(L==R)return min((ll)lim,max(0ll,v+sum[x]));
| ^
candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:9:12: error: '__gnu_cxx::__alloc_traits<std::allocator<node>, node>::value_type' {aka 'struct node'} has no member named 'push_back'
9 | #define pb push_back
| ^~~~~~~~~
candies.cpp:60:14: note: in expansion of macro 'pb'
60 | Q[L].pb({i+1,V}),Q[R+1].pb({i+1,-V});
| ^~
candies.cpp:9:12: error: '__gnu_cxx::__alloc_traits<std::allocator<node>, node>::value_type' {aka 'struct node'} has no member named 'push_back'
9 | #define pb push_back
| ^~~~~~~~~
candies.cpp:60:33: note: in expansion of macro 'pb'
60 | Q[L].pb({i+1,V}),Q[R+1].pb({i+1,-V});
| ^~
candies.cpp:63:23: error: 'begin' was not declared in this scope
63 | for(auto t:Q[i]){
| ^
candies.cpp:63:23: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
from candies.cpp:1:
/usr/include/c++/10/valarray:1224:5: note: 'std::begin'
1224 | begin(const valarray<_Tp>& __va)
| ^~~~~
In file included from /usr/include/c++/10/filesystem:46,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
from candies.cpp:1:
/usr/include/c++/10/bits/fs_dir.h:549:3: note: 'std::filesystem::__cxx11::begin'
549 | begin(recursive_directory_iterator __iter) noexcept
| ^~~~~
candies.cpp:63:23: error: 'end' was not declared in this scope
63 | for(auto t:Q[i]){
| ^
candies.cpp:63:23: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
from candies.cpp:1:
/usr/include/c++/10/valarray:1244:5: note: 'std::end'
1244 | end(const valarray<_Tp>& __va)
| ^~~
In file included from /usr/include/c++/10/filesystem:46,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
from candies.cpp:1:
/usr/include/c++/10/bits/fs_dir.h:554:3: note: 'std::filesystem::__cxx11::end'
554 | end(recursive_directory_iterator) noexcept
| ^~~
candies.cpp:66:28: error: no match for call to '(std::vector<node>) (int, int, int&, int, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
66 | s[i]=Q(1,1,m,0,c[i]);
| ^