// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
int main() {
long long N,Q; cin >> N >> Q;
long long a[N];
for (long long i=0;i<N;i++) {
cin >> a[i];
}
//solve:
for (long long q=0;q<Q;q++) {
long long l,r,x; cin >> l >> r >> x;
l--; r--;
for (long long i=l;i<=r;i++) {
a[i] += x;
}
long long val = 0;
for (long long i=1;i<N;i++) {
val += abs(a[i]-a[i-1]);
if (i<(N-1)) {
if (!(((a[i-1]<a[i])&&(a[i]<a[i+1]))||((a[i-1]>a[i])&&(a[i]>a[i+1])))) {
val -= min(abs(a[i]-a[i-1]),abs(a[i]-a[i+1]));
}
}
}
cout << val <<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |