This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |