#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_N = 2e5;
const int MOD = 998244353;
struct Node {
int borders[2], dp[2][2];
};
Node segm[4*MAX_N];
void calc(int pos, int l, int r) {
segm[pos].borders[0] = segm[2*pos+1].borders[0];
segm[pos].borders[1] = segm[2*pos+2].borders[1];
for(int l=0; l<2; ++l) for(int m=0; m<2; ++m) for(int o=0; o<2; ++o) for(int r=0; r<2; ++r) {
if(o && m) {
if((segm[2*pos+1].borders[1] < 0) == (segm[2*pos+2].borders[0] < 0)) segm[pos].dp[l][r] = segm[2*pos+1].dp[l][m] + segm[2*pos+2].dp[o][r];
} else segm[pos].dp[l][r] = segm[2*pos+1].dp[l][m] + segm[2*pos+2].dp[o][r];
}
}
void update(int pos, int l, int r, int x, int val) {
if(l==r) {
segm[pos].borders[0] += val;
segm[pos].borders[1] += val;
segm[pos].dp[1][1] = abs(segm[pos].borders[0]);
return;
}
int m = (l+r)/2;
if(x <= m) update(2*pos+1, l, m, x, val);
else update(2*pos+2, m+1, r, x, val);
calc(pos, l, r);
}
void solve() {
for(int i=0; i<4*MAX_N; ++i) {
segm[i].borders[0] = segm[i].borders[1] = 0;
for(int j=0; j<2; ++j) for(int k=0; k<2; ++k) segm[i].dp[j][k] = 0;
}
int n, q;
cin >> n >> q;
int a[n];
for(int i=0; i<n; ++i) {
cin >> a[i];
if(i) update(1, 0, n-2, i-1, a[i]-a[i-1]);
}
while(q--) {
int l, r, x;
cin >> l >> r >> x;
--l, --r;
if(l) update(1, 0, n-2, l-1, x);
if(r != n-1) update(1, 0, n-2, r, -x);
cout << segm[1].dp[1][1] << endl;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1;
while(t--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
37968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
37968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
37968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |