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 <iostream>
using namespace std;
#define int long long
signed main(){
int n, q; cin >> n >> q;
int arr[n];
for (int x = 0; x < n; x++) cin >> arr[x];
int a,b,c;
for (int k = 0; k < q; k++){
cin >> a >> b >> c; a--; b--;
for (int x = a; x <= b; x++) arr[x] += c;
int sfmin = arr[0], sfmax = arr[0], ans = 0;
for (int x = 0; x < n; x++){
sfmin = min(sfmin, arr[x]);
sfmax = max(sfmax, arr[x]);
if (x != 0 && (arr[x-1] <= arr[x]) != (arr[x] <= arr[x+1])) ans += sfmax - sfmin, sfmin = arr[x+1], sfmax = arr[x+1];
}
ans += sfmax - sfmin;
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... |