#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';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |