/*
www.youtube.com/YugiHackerChannel
oj.vnoi.info/user/YugiHackerKhongCopCode
*/
#include<bits/stdc++.h>
#define el cout<<"\n"
#define f0(i,n) for(int i=0;i<n;++i)
#define f1(i,n) for(int i=1;i<=n;++i)
#define maxn 200005
using namespace std;
int n, a[maxn], q;
long long d[maxn];
struct Node
{
long long f[2][2];
int L, R;
Node(){memset(f, -60, sizeof f);}
Node(long long x){
memset(f, -60, sizeof f);
f[0][0] = 0;
f[1][1] = abs(x);
if (x < 0) L = R = -1;
else if (x > 0) L = R = 1;
else L = R = 0;
}
friend Node operator + (Node a, Node b)
{
Node ans;
ans.L = a.L, ans.R = b.R;
f0 (x, 2) f0 (y, 2)
{
f0 (i, 2) f0 (j, 2)
if (i + j!= 2) ans.f[x][y] = max(ans.f[x][y], a.f[x][i] + b.f[j][y]);
if (a.R * b.L >= 0) ans.f[x][y] = max(ans.f[x][y], a.f[x][1] + b.f[1][y]);
}
return ans;
}
long long get()
{
long long ans = 0;
f0 (i, 2) f0 (j, 2) ans = max(ans, f[i][j]);
return ans;
}
}t[maxn*4];
void up(int id, int l, int r, int pos)
{
if (pos < l || r < pos) return;
if (l == r)
{
t[id] = Node(d[l]);
return;
}
int m = (l+r)/2;
up(id*2, l, m, pos);
up(id*2+1, m+1, r, pos);
t[id] = t[id*2] + t[id*2+1];
}
main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> q;
f1 (i, n) cin >> a[i];
--n;
f1 (i, n) d[i] = a[i+1] - a[i], up(1, 1, n, i);
while (q--)
{
int l, r, x; cin >> l >> r >> x;
d[l-1] += x;
d[r] -= x;
up(1, 1, n, l-1); up(1, 1, n, r);
cout << t[1].get(); el;
}
}
Compilation message (stderr)
Main.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
62 | main()
| ^~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |