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>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
signed main(){
fastio
int n,q;
cin >> n >> q;
int arr[n+1];
for(int i = 1;i <= n;i++){
cin >> arr[i];
}
while(q--){
int l,r,x;
cin >> l >> r >> x;
for(int i = l;i <= r;i++) arr[i] += x;
if(n==1){
cout << 0 << "\n";
continue;
}
int ans = 0;
arr[0] = (arr[2] >= arr[1] ? -1e9 : 1e9);
int inc = -1, mx = 0, mn = 0;
for(int i = 1;i <= n;i++){
if(inc!=(arr[i]>=arr[i-1])){
ans += mx-mn;
mx = arr[i], mn = arr[i];
inc = (arr[i]>=arr[i-1]);
}else{
mx = max(arr[i],mx);
mn = min(arr[i],mn);
}
}
ans += mx-mn;
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... |