이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |