This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 2e5 + 5;
int N, Q;
ll A[MX];
ll calc() {
ll lo = A[1], hi = A[1], res = 0;
for(int x = 2; x <= N; x++) {
if(lo <= A[x] && A[x] <= hi) {
res += hi - lo;
lo = A[x], hi = A[x];
continue;
}
lo = min(lo, A[x]);
hi = max(hi, A[x]);
}
res += hi - lo;
return res;
}
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> N >> Q;
for(int i = 1; i <= N; i++) cin >> A[i];
for(int i = 1; i <= Q; i++) {
ll l, r, x;
cin >> l >> r >> x;
for(int j = l; j <= r; j++) A[j] += x;
cout << calc() << '\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... |