#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 res = 0;
for(int x = 1; x + 1 <= N; x++) {
if(A[x] == A[x + 1]) continue;
if(A[x] < A[x + 1]) {
int y = x;
while(y + 1 <= N && A[y] < A[y + 1]) y++;
res += A[y] - A[x];
x = y;
} else {
int y = x;
while(y + 1 <= N && A[y] > A[y + 1]) y++;
res += A[x] - A[y];
x = y;
}
}
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 |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |