#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin() , (x).end()
const ll MOD = 998244353;
const long double EPS = 0.000000001;
ll n, q, arr[200005], st[200005];
void build(int v, int l, int r) {
if(l==r) {
st[v]=arr[l]; return;
}
build(v*2, l, (l+r)/2);
build(v*2+1, (l+r)/2+1, r);
if(r-l==1) {
st[v]=max(st[v*2], st[v*2+1])-min(st[v*2], st[v*2+1]);
return;
}
st[v]=st[v*2]+st[v*2+1];
}
void update(int v, int l, int r, int lo, int hi, ll val) {
if(l>hi||r<lo) return;
if(l>=lo&&r<=hi) {
if(l==r) st[v]+=val;
if(r-l>1) st[v]+=val;
return;
}
update(v*2, l, (l+r)/2, lo, hi, val);
update(v*2+1, (l+r)/2+1, r, lo, hi, val);
if(r-l==1) {
st[v]=max(st[v*2], st[v*2+1])-min(st[v*2], st[v*2+1]);
return;
}
if(r-l==1) {
st[v]=max(st[v*2], st[v*2+1])-min(st[v*2], st[v*2+1]);
return;
}
st[v]=st[v*2]+st[v*2+1];
}
int32_t main()
{
ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
cin>>n>>q;
for(int l=1;l<=n;l++) cin>>arr[l];
build(1, 1, n);
while(q--) {
ll a, b, w; cin>>a>>b>>w;
update(1, 1, n, a, b, w);
cout<<st[1]<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |