#include<bits/stdc++.h>
using namespace std;
const int N = 2e6 + 7;
const int inf = 1e9 + 7;
const long long infll = 1e18 + 7;
int n, q;
long long a[N], b[N], dp[N][2];
long long GetResult() {
for (int i = 1; i < n; i++) {
b[i] = a[i] - a[i + 1];
dp[i][0] = dp[i][1] = -infll;
}
dp[1][0] = 0;
dp[1][1] = abs(b[1]);
for (int i = 2; i < n; i++) {
if ((b[i - 1] < 0 && b[i] > 0) || (b[i - 1] > 0 && b[i] < 0)) {
dp[i][1] = dp[i - 1][0] + abs(b[i]);
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
}
else {
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + abs(b[i]);
}
}
return max(dp[n - 1][0], dp[n - 1][1]);
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; i++) cin >> a[i];
while (q--) {
int l, r;
long long v;
cin >> l >> r >> v;
for (int i = l; i <= r; i++) a[i] += v;
cout << GetResult();
if (q > 0) cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
36 ms |
604 KB |
Output is correct |
8 |
Correct |
37 ms |
604 KB |
Output is correct |
9 |
Correct |
35 ms |
604 KB |
Output is correct |
10 |
Correct |
35 ms |
600 KB |
Output is correct |
11 |
Correct |
36 ms |
604 KB |
Output is correct |
12 |
Correct |
27 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
36 ms |
604 KB |
Output is correct |
8 |
Correct |
37 ms |
604 KB |
Output is correct |
9 |
Correct |
35 ms |
604 KB |
Output is correct |
10 |
Correct |
35 ms |
600 KB |
Output is correct |
11 |
Correct |
36 ms |
604 KB |
Output is correct |
12 |
Correct |
27 ms |
604 KB |
Output is correct |
13 |
Execution timed out |
2071 ms |
9140 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |