#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mxN = 1e6 + 5;
ll n,q,a[mxN],b[mxN];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> q;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	while(q--){
		ll l,r,x;
		cin >> l >> r >> x;
		for(int i = l; i <= r; i++) a[i] += x;
		for(int i = 1; i < n; i++) b[i] = a[i + 1] - a[i];
		ll ans = 0,sum[2] = {0, 0},i = 1;
		while(i < n){
			if((b[i] >= 0) != (b[i + 1] >= 0)){
				sum[0] = sum[1] = 0;
				while(i < n and (b[i] >= 0) != (b[i + 1] >= 0)){
					sum[i % 2] += abs(b[i]);
					i++;
				}
				sum[i % 2] += abs(b[i]);
				i++;
				ans += max(sum[0],sum[1]);
				continue;
			}
			ans += abs(b[i++]);
		}
		cout << ans << '\n';
	}
} 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |