#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct node {
ll sum, lmin, rmin, mn, a[2];
};
node operator +(node l, node r) {
node rt;
ll md=l.a[1];
rt.sum=l.sum+r.sum-md;
rt.lmin=min(l.lmin+r.mn, l.sum+r.lmin-md);
rt.rmin=min(r.rmin+l.mn, r.sum+l.rmin-md);
rt.mn=min(l.mn+r.mn, l.rmin+r.lmin-md);
rt.a[0]=l.a[0], rt.a[1]=r.a[1];
return rt;
}
node st[1<<20];
void upd1(int i, int s, int e, int t, int ty, int v) {
if (t<s||t>e) return ;
if (s==e) {
st[i].sum+=v;
st[i].a[ty]+=v;
st[i].lmin=st[i].rmin=st[i].sum;
st[i].mn=min(0ll, st[i].sum);
return ;
}
int m=(s+e)/2;
if (t<=m) upd1(i*2, s, m, t, ty, v);
else upd1(i*2+1, m+1, e, t, ty, v);
st[i]=st[i*2]+st[i*2+1];
}
void upd2(int i, int s, int e, int t, int v) {
if (s==e) {
st[i].sum-=v;
st[i].lmin=st[i].rmin=st[i].sum;
st[i].mn=min(0ll, st[i].sum);
return ;
}
int m=(s+e)/2;
if (t<=m) upd2(i*2, s, m, t, v);
else upd2(i*2+1, m+1, e, t, v);
st[i]=st[i*2]+st[i*2+1];
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int q, l;
cin>>q>>l;
vector<ll> arr(q+2);
ll sum=0;
for (int l=0; l<q; l++) {
int t, x, a;
cin>>t>>x>>a;
x++;
arr[x]+=a;
if (t==1) upd1(1, 1, (q+1)/2, x/2, 1, a), upd1(1, 1, (q+1)/2, x/2+1, 0, a);
else sum+=a, upd2(1, 1, (q+1)/2, (x+1)/2, a);
cout<<sum+st[1].mn<<'\n';
}
return 0;
}#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct node {
ll sum, lmin, rmin, mn, a[2];
};
node operator +(node l, node r) {
node rt;
ll md=l.a[1];
rt.sum=l.sum+r.sum-md;
rt.lmin=min(l.lmin+r.mn, l.sum+r.lmin-md);
rt.rmin=min(r.rmin+l.mn, r.sum+l.rmin-md);
rt.mn=min(l.mn+r.mn, l.rmin+r.lmin-md);
rt.a[0]=l.a[0], rt.a[1]=r.a[1];
return rt;
}
node st[1<<20];
void upd1(int i, int s, int e, int t, int ty, int v) {
if (t<s||t>e) return ;
if (s==e) {
st[i].sum+=v;
st[i].a[ty]+=v;
st[i].lmin=st[i].rmin=st[i].sum;
st[i].mn=min(0ll, st[i].sum);
return ;
}
int m=(s+e)/2;
if (t<=m) upd1(i*2, s, m, t, ty, v);
else upd1(i*2+1, m+1, e, t, ty, v);
st[i]=st[i*2]+st[i*2+1];
}
void upd2(int i, int s, int e, int t, int v) {
if (s==e) {
st[i].sum-=v;
st[i].lmin=st[i].rmin=st[i].sum;
st[i].mn=min(0ll, st[i].sum);
return ;
}
int m=(s+e)/2;
if (t<=m) upd2(i*2, s, m, t, v);
else upd2(i*2+1, m+1, e, t, v);
st[i]=st[i*2]+st[i*2+1];
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int q, l;
cin>>q>>l;
vector<ll> arr(q+2);
ll sum=0;
for (int l=0; l<q; l++) {
int t, x, a;
cin>>t>>x>>a;
x++;
arr[x]+=a;
if (t==1) upd1(1, 1, (q+1)/2, x/2, 1, a), upd1(1, 1, (q+1)/2, x/2+1, 0, a);
else sum+=a, upd2(1, 1, (q+1)/2, (x+1)/2, a);
cout<<sum+st[1].mn<<'\n';
}
return 0;
}
Compilation message
sugar.cpp:69:2: error: stray '#' in program
69 | }#include <bits/stdc++.h>
| ^
sugar.cpp:69:3: error: 'include' does not name a type
69 | }#include <bits/stdc++.h>
| ^~~~~~~
sugar.cpp:74:8: error: redefinition of 'struct node'
74 | struct node {
| ^~~~
sugar.cpp:6:8: note: previous definition of 'struct node'
6 | struct node {
| ^~~~
sugar.cpp:78:6: error: redefinition of 'node operator+(node, node)'
78 | node operator +(node l, node r) {
| ^~~~~~~~
sugar.cpp:10:6: note: 'node operator+(node, node)' previously defined here
10 | node operator +(node l, node r) {
| ^~~~~~~~
sugar.cpp:89:6: error: redefinition of 'node st [1048576]'
89 | node st[1<<20];
| ^~
sugar.cpp:21:6: note: 'node st [1048576]' previously declared here
21 | node st[1<<20];
| ^~
sugar.cpp:91:6: error: redefinition of 'void upd1(int, int, int, int, int, int)'
91 | void upd1(int i, int s, int e, int t, int ty, int v) {
| ^~~~
sugar.cpp:23:6: note: 'void upd1(int, int, int, int, int, int)' previously defined here
23 | void upd1(int i, int s, int e, int t, int ty, int v) {
| ^~~~
sugar.cpp:106:6: error: redefinition of 'void upd2(int, int, int, int, int)'
106 | void upd2(int i, int s, int e, int t, int v) {
| ^~~~
sugar.cpp:38:6: note: 'void upd2(int, int, int, int, int)' previously defined here
38 | void upd2(int i, int s, int e, int t, int v) {
| ^~~~
sugar.cpp:119:5: error: redefinition of 'int main()'
119 | int main() {
| ^~~~
sugar.cpp:51:5: note: 'int main()' previously defined here
51 | int main() {
| ^~~~