#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q, s, t;
cin >> n >> q >> s >> t;
vector<ll> a (n+1, 0);
for (int i = 0; i < n+1; i++) {
cin >> a[i];
}
vector<ll> d (n, 0);
ll sum = 0;
for (int i = 0; i < n; i++) {
d[i] = a[i] - a[i+1];
if (d[i] >= 0) {
sum += d[i]*t;
}
else {
sum += d[i]*s;
}
}
for (int i = 0; i < q; i++) {
ll l = 0, r = 0, x = 0;
cin >> l >> r >> x;
if (l != 0) {
if (d[l-1] >= 0) {
sum -= d[l-1]*t;
}
else {
sum -= d[l-1]*s;
}
d[l-1] -= x;
if (d[l-1] >= 0) {
sum += d[l-1]*t;
}
else {
sum += d[l-1]*s;
}
}
if (r != n) {
if (d[r] >= 0) {
sum -= d[r]*t;
}
else {
sum -= d[r]*s;
}
d[r] += x;
if (d[r] >= 0) {
sum += d[r]*t;
}
else {
sum += d[r]*s;
}
}
cout << sum << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
536 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
10320 KB |
Output is correct |
2 |
Correct |
53 ms |
10924 KB |
Output is correct |
3 |
Correct |
70 ms |
11464 KB |
Output is correct |
4 |
Correct |
53 ms |
10832 KB |
Output is correct |
5 |
Correct |
66 ms |
12328 KB |
Output is correct |
6 |
Correct |
52 ms |
11076 KB |
Output is correct |
7 |
Correct |
47 ms |
11092 KB |
Output is correct |
8 |
Correct |
61 ms |
11856 KB |
Output is correct |
9 |
Correct |
55 ms |
12216 KB |
Output is correct |
10 |
Correct |
54 ms |
10836 KB |
Output is correct |
11 |
Correct |
43 ms |
11100 KB |
Output is correct |
12 |
Correct |
46 ms |
11856 KB |
Output is correct |
13 |
Correct |
45 ms |
11856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
536 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
58 ms |
10320 KB |
Output is correct |
23 |
Correct |
53 ms |
10924 KB |
Output is correct |
24 |
Correct |
70 ms |
11464 KB |
Output is correct |
25 |
Correct |
53 ms |
10832 KB |
Output is correct |
26 |
Correct |
66 ms |
12328 KB |
Output is correct |
27 |
Correct |
52 ms |
11076 KB |
Output is correct |
28 |
Correct |
47 ms |
11092 KB |
Output is correct |
29 |
Correct |
61 ms |
11856 KB |
Output is correct |
30 |
Correct |
55 ms |
12216 KB |
Output is correct |
31 |
Correct |
54 ms |
10836 KB |
Output is correct |
32 |
Correct |
43 ms |
11100 KB |
Output is correct |
33 |
Correct |
46 ms |
11856 KB |
Output is correct |
34 |
Correct |
45 ms |
11856 KB |
Output is correct |
35 |
Correct |
53 ms |
10392 KB |
Output is correct |
36 |
Correct |
56 ms |
11856 KB |
Output is correct |
37 |
Correct |
57 ms |
12624 KB |
Output is correct |
38 |
Correct |
56 ms |
12384 KB |
Output is correct |
39 |
Correct |
60 ms |
12372 KB |
Output is correct |
40 |
Correct |
57 ms |
12392 KB |
Output is correct |
41 |
Correct |
57 ms |
12368 KB |
Output is correct |
42 |
Correct |
57 ms |
12448 KB |
Output is correct |
43 |
Correct |
55 ms |
11604 KB |
Output is correct |
44 |
Correct |
56 ms |
12116 KB |
Output is correct |
45 |
Correct |
52 ms |
12116 KB |
Output is correct |
46 |
Correct |
57 ms |
13136 KB |
Output is correct |
47 |
Correct |
47 ms |
11864 KB |
Output is correct |
48 |
Correct |
49 ms |
11760 KB |
Output is correct |
49 |
Correct |
58 ms |
10772 KB |
Output is correct |
50 |
Correct |
48 ms |
11428 KB |
Output is correct |
51 |
Correct |
49 ms |
11860 KB |
Output is correct |
52 |
Correct |
48 ms |
11600 KB |
Output is correct |