#include <bits/stdc++.h>
#define endl '\n'
#define eat cin
#define moo cout
#define int long long
using namespace std;
struct segtree{
int a[800005][2][2];
int b[800005];
void init(){
for(int i = 0; i < 800005; i++){
for(int j = 0; j < 2; j++){
for(int k = 0; k < 2; k++){
a[i][j][k] = 0;
}
}
b[i] = 0;
}
}
void upd(int i, int x, int l=0, int r=200000, int v=1){
if(i < l || i > r) return;
if(l == r){
b[v] += x;
a[v][0][0] = a[v][0][1] = a[v][1][0] = a[v][1][1] = 0;
if(b[v] > 0){
a[v][0][0] = b[v];
}else{
a[v][1][1] = -b[v];
}
return;
}
upd(i, x, l, (l+r)/2, v*2);
upd(i, x, (l+r)/2+1, r, v*2+1);
for(int i = 0; i < 2; i++){
for(int j = 0; j < 2; j++){
a[v][i][j] = 0;
for(int k = 0; k < 2; k++){
int c = a[v*2][i][k] + a[v*2+1][k][j];
a[v][i][j] = max(a[v][i][j], c);
}
}
}
}
int qry(){
return max({a[1][0][0], a[1][0][1], a[1][1][0], a[1][1][1]});
}
};
int N, Q, A[200000];
segtree S;
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
eat >> N >> Q;
S.init();
for(int i = 0; i < N; i++){
eat >> A[i];
}
for(int i = 0; i < N-1; i++){
S.upd(i, A[i+1] - A[i]);
}
for(int i = 0; i < Q; i++){
int l, r, x; eat >> l >> r >> x;
l -= 2, r--;
if(l >= 0){
S.upd(l, x);
}
if(r <= N-2){
S.upd(r, -x);
}
moo << S.qry() << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
31560 KB |
Output is correct |
2 |
Correct |
13 ms |
31572 KB |
Output is correct |
3 |
Correct |
13 ms |
31584 KB |
Output is correct |
4 |
Correct |
13 ms |
31572 KB |
Output is correct |
5 |
Correct |
13 ms |
31524 KB |
Output is correct |
6 |
Correct |
16 ms |
31748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
31560 KB |
Output is correct |
2 |
Correct |
13 ms |
31572 KB |
Output is correct |
3 |
Correct |
13 ms |
31584 KB |
Output is correct |
4 |
Correct |
13 ms |
31572 KB |
Output is correct |
5 |
Correct |
13 ms |
31524 KB |
Output is correct |
6 |
Correct |
16 ms |
31748 KB |
Output is correct |
7 |
Correct |
16 ms |
31696 KB |
Output is correct |
8 |
Correct |
15 ms |
31700 KB |
Output is correct |
9 |
Correct |
20 ms |
31760 KB |
Output is correct |
10 |
Correct |
16 ms |
31700 KB |
Output is correct |
11 |
Correct |
16 ms |
31700 KB |
Output is correct |
12 |
Correct |
16 ms |
31756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
31560 KB |
Output is correct |
2 |
Correct |
13 ms |
31572 KB |
Output is correct |
3 |
Correct |
13 ms |
31584 KB |
Output is correct |
4 |
Correct |
13 ms |
31572 KB |
Output is correct |
5 |
Correct |
13 ms |
31524 KB |
Output is correct |
6 |
Correct |
16 ms |
31748 KB |
Output is correct |
7 |
Correct |
16 ms |
31696 KB |
Output is correct |
8 |
Correct |
15 ms |
31700 KB |
Output is correct |
9 |
Correct |
20 ms |
31760 KB |
Output is correct |
10 |
Correct |
16 ms |
31700 KB |
Output is correct |
11 |
Correct |
16 ms |
31700 KB |
Output is correct |
12 |
Correct |
16 ms |
31756 KB |
Output is correct |
13 |
Correct |
315 ms |
42348 KB |
Output is correct |
14 |
Correct |
304 ms |
42248 KB |
Output is correct |
15 |
Correct |
299 ms |
42252 KB |
Output is correct |
16 |
Correct |
307 ms |
42184 KB |
Output is correct |
17 |
Correct |
289 ms |
42248 KB |
Output is correct |
18 |
Correct |
363 ms |
42912 KB |
Output is correct |