#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 200;
ll t[4 * N][2][2];
bool sign[4 * N][2][2][2];
void umax(ll &a, bool& L, bool& R, ll val, bool& uL, bool& uR){
if(val > a){
a = val;
L = uL;
R = uR;
}
}
void combine(int v, int l, int r){
for(int x = 0; x <= 1; x ++){
for(int y = 0; y <= 1; y ++){
t[v][x][y] = -1;
umax(t[v][x][y], sign[v][x][y][0], sign[v][x][y][1], abs(t[l][x][0]) + abs(t[r][0][y]), sign[l][x][0][0], sign[r][0][y][1]);
umax(t[v][x][y], sign[v][x][y][0], sign[v][x][y][1], abs(t[l][x][1]) + abs(t[r][0][y]), sign[l][x][1][0], sign[r][0][y][1]);
umax(t[v][x][y], sign[v][x][y][0], sign[v][x][y][1], abs(t[l][x][0]) + abs(t[r][1][y]), sign[l][x][0][0], sign[r][1][y][1]);
if(sign[l][x][1][1] == sign[r][1][y][0])
umax(t[v][x][y], sign[v][x][y][0], sign[v][x][y][1], abs(t[l][x][1]) + abs(t[r][1][y]), sign[l][x][1][0], sign[r][1][y][1]);
}
}
}
void modify(int v, int tl, int tr, int pos, ll x){
if(tl == tr){
t[v][1][1] += x;
sign[v][1][1][0] = sign[v][1][1][1] = (t[v][1][1] >= 0);
return;
}
int tm = (tl + tr) / 2;
if(pos <= tm)
modify(v * 2, tl, tm, pos, x);
else
modify(v * 2 + 1, tm + 1, tr, pos, x);
combine(v, v * 2, v * 2 + 1);
}
int main(){
ios_base :: sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, q;
cin >> n >> q;
vector<ll> a(n), d(n - 1);
for(int i = 0; i < n; i ++)
cin >> a[i];
for(int i = 1; i < n; i ++)
d[i - 1] = a[i - 1] - a[i];
for(int i = 0; i < n - 1; i ++)
modify(1, 0, n - 2, i, d[i]);
while(q --){
int l, r;
ll x;
cin >> l >> r >> x;
if(l > 1)
modify(1, 0, n - 2, l - 2, -x);
if(r < n)
modify(1, 0, n - 2, r - 1, x);
cout << max(max(t[1][0][0], t[1][1][1]),
max(t[1][1][0], t[1][0][1])) << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
8 ms |
716 KB |
Output is correct |
8 |
Correct |
12 ms |
716 KB |
Output is correct |
9 |
Correct |
12 ms |
716 KB |
Output is correct |
10 |
Correct |
8 ms |
716 KB |
Output is correct |
11 |
Correct |
8 ms |
716 KB |
Output is correct |
12 |
Correct |
10 ms |
720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
8 ms |
716 KB |
Output is correct |
8 |
Correct |
12 ms |
716 KB |
Output is correct |
9 |
Correct |
12 ms |
716 KB |
Output is correct |
10 |
Correct |
8 ms |
716 KB |
Output is correct |
11 |
Correct |
8 ms |
716 KB |
Output is correct |
12 |
Correct |
10 ms |
720 KB |
Output is correct |
13 |
Correct |
953 ms |
33164 KB |
Output is correct |
14 |
Correct |
885 ms |
33072 KB |
Output is correct |
15 |
Correct |
912 ms |
33024 KB |
Output is correct |
16 |
Correct |
934 ms |
33028 KB |
Output is correct |
17 |
Correct |
886 ms |
32956 KB |
Output is correct |
18 |
Correct |
793 ms |
33688 KB |
Output is correct |