#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 = abs(b[1]);
for(int i = 2; i < n; i++){
if((b[i - 1] >= 0) != (b[i] >= 0)){
if(abs(b[i - 1]) < abs(b[i])) ans += abs(b[i]) - abs(b[i - 1]);
}
else 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... |