#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T>
struct Fenwick {
vector<T> t;
int sz;
Fenwick() = default;
Fenwick(int n) {
init(n);
}
void init(int n) {
t.assign(n, 0);
sz = n;
}
void modify(int i, T v) {
for (; i < sz; i |= (i + 1)) {
t[i] += v;
}
}
T get(int i) {
T ans = 0;
for (; i > -1; i = ((i + 1) & i) - 1) {
ans += t[i];
}
return ans;
}
//[l, r)
T get(int l, int r) {
return get(r - 1) - get(l - 1);
}
//[l, r)
void modify(int l, int r, T v) {
modify(l, v);
modify(r, -v);
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q, s, t;
cin >> n >> q >> s >> t;
vector<ll> a(n + 1);
Fenwick<ll> fn(n + 1);
for (int i = 0; i <= n; ++i) {
cin >> a[i];
fn.modify(i, i + 1, a[i]);
}
auto upd = [&](int i) {
if (i > n) return 0ll;
a[i] = fn.get(i), a[i - 1] = fn.get(i - 1);
return (a[i] > a[i - 1] ? -s : t) * (ll)abs(a[i] - a[i - 1]);
};
ll ans = 0;
for (int i = 1; i <= n; ++i) {
ans += upd(i);
}
while (q--) {
int l, r, x;
cin >> l >> r >> x;
ans -= upd(l);
ans -= upd(r + 1);
fn.modify(l, r + 1, x);
ans += upd(l);
ans += upd(r + 1);
cout << ans << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
304 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
4888 KB |
Output is correct |
2 |
Correct |
140 ms |
5436 KB |
Output is correct |
3 |
Correct |
155 ms |
6184 KB |
Output is correct |
4 |
Correct |
128 ms |
5204 KB |
Output is correct |
5 |
Correct |
145 ms |
12032 KB |
Output is correct |
6 |
Correct |
95 ms |
11084 KB |
Output is correct |
7 |
Correct |
96 ms |
11020 KB |
Output is correct |
8 |
Correct |
134 ms |
11764 KB |
Output is correct |
9 |
Correct |
160 ms |
12112 KB |
Output is correct |
10 |
Correct |
125 ms |
10820 KB |
Output is correct |
11 |
Correct |
102 ms |
10948 KB |
Output is correct |
12 |
Correct |
124 ms |
11632 KB |
Output is correct |
13 |
Correct |
98 ms |
11880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
304 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
133 ms |
4888 KB |
Output is correct |
23 |
Correct |
140 ms |
5436 KB |
Output is correct |
24 |
Correct |
155 ms |
6184 KB |
Output is correct |
25 |
Correct |
128 ms |
5204 KB |
Output is correct |
26 |
Correct |
145 ms |
12032 KB |
Output is correct |
27 |
Correct |
95 ms |
11084 KB |
Output is correct |
28 |
Correct |
96 ms |
11020 KB |
Output is correct |
29 |
Correct |
134 ms |
11764 KB |
Output is correct |
30 |
Correct |
160 ms |
12112 KB |
Output is correct |
31 |
Correct |
125 ms |
10820 KB |
Output is correct |
32 |
Correct |
102 ms |
10948 KB |
Output is correct |
33 |
Correct |
124 ms |
11632 KB |
Output is correct |
34 |
Correct |
98 ms |
11880 KB |
Output is correct |
35 |
Correct |
144 ms |
10368 KB |
Output is correct |
36 |
Correct |
174 ms |
11768 KB |
Output is correct |
37 |
Correct |
155 ms |
12620 KB |
Output is correct |
38 |
Correct |
154 ms |
12480 KB |
Output is correct |
39 |
Correct |
137 ms |
12424 KB |
Output is correct |
40 |
Correct |
145 ms |
12364 KB |
Output is correct |
41 |
Correct |
138 ms |
12264 KB |
Output is correct |
42 |
Correct |
156 ms |
12364 KB |
Output is correct |
43 |
Correct |
141 ms |
11636 KB |
Output is correct |
44 |
Correct |
192 ms |
11940 KB |
Output is correct |
45 |
Correct |
140 ms |
12000 KB |
Output is correct |
46 |
Correct |
146 ms |
13124 KB |
Output is correct |
47 |
Correct |
94 ms |
11648 KB |
Output is correct |
48 |
Correct |
105 ms |
11632 KB |
Output is correct |
49 |
Correct |
186 ms |
10732 KB |
Output is correct |
50 |
Correct |
100 ms |
11520 KB |
Output is correct |
51 |
Correct |
100 ms |
11892 KB |
Output is correct |
52 |
Correct |
102 ms |
11764 KB |
Output is correct |