#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 2e5+1;
const int TSIZE = 1 << 20;
ll T[TSIZE], a[MAXN], ans, n, q, s, t;
void build(int v, int l, int r) {
if (l == r) {
T[v]=a[l];
return;
}
int m=(l+r)/2;
build(2*v, l, m), build(2*v+1, m+1, r);
}
void update(int v, int l, int r, int ql, int qr, ll x) {
if (l > qr || r < ql) return;
if (l >= ql && r <= qr) {
T[v]+=x;
return;
}
int m=(l+r)/2;
update(2*v, l, m, ql, qr, x), update(2*v+1, m+1, r, ql, qr, x);
}
ll query(int v, int l, int r, int p, ll c) {
if (l == r) return T[v]+c;
int m=(l+r)/2;
if (p <= m) return query(2*v, l, m, p, c+T[v]);
return query(2*v+1, m+1, r, p, c+T[v]);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>q>>s>>t>>a[0];
for (int i=1; i<=n; ++i) cin>>a[i];
build(1, 0, n);
for (int i=0; i<n; ++i) {
if (a[i+1] > a[i]) ans-=s*(a[i+1]-a[i]);
else ans+=t*(a[i]-a[i+1]);
}
for (int i=1; i<=q; ++i) {
ll l, r, x;
cin>>l>>r>>x;
ll la=query(1, 0, n, l, 0), lla=query(1, 0, n, l-1, 0);
if (la > lla) ans+=s*(la-lla);
else ans-=t*(lla-la);
if (r < n) {
ll ra=query(1, 0, n, r, 0), rra=query(1, 0, n, r+1, 0);
if (rra > ra) ans+=s*(rra-ra);
else ans-=t*(ra-rra);
update(1, 0, n, l, r, x);
ra=query(1, 0, n, r, 0), rra=query(1, 0, n, r+1, 0);
if (rra > ra) ans-=s*(rra-ra);
else ans+=t*(ra-rra);
} else update(1, 0, n, l, r, x);
la=query(1, 0, n, l, 0), lla=query(1, 0, n, l-1, 0);
if (la > lla) ans-=s*(la-lla);
else ans+=t*(lla-la);
cout<<ans<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
380 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
3 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
0 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
400 ms |
12832 KB |
Output is correct |
2 |
Correct |
321 ms |
13448 KB |
Output is correct |
3 |
Correct |
398 ms |
14076 KB |
Output is correct |
4 |
Correct |
333 ms |
13432 KB |
Output is correct |
5 |
Correct |
329 ms |
14544 KB |
Output is correct |
6 |
Correct |
140 ms |
12620 KB |
Output is correct |
7 |
Correct |
127 ms |
12560 KB |
Output is correct |
8 |
Correct |
294 ms |
14312 KB |
Output is correct |
9 |
Correct |
253 ms |
14656 KB |
Output is correct |
10 |
Correct |
327 ms |
13376 KB |
Output is correct |
11 |
Correct |
154 ms |
12380 KB |
Output is correct |
12 |
Correct |
152 ms |
13228 KB |
Output is correct |
13 |
Correct |
126 ms |
13464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
380 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
3 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
0 ms |
324 KB |
Output is correct |
22 |
Correct |
400 ms |
12832 KB |
Output is correct |
23 |
Correct |
321 ms |
13448 KB |
Output is correct |
24 |
Correct |
398 ms |
14076 KB |
Output is correct |
25 |
Correct |
333 ms |
13432 KB |
Output is correct |
26 |
Correct |
329 ms |
14544 KB |
Output is correct |
27 |
Correct |
140 ms |
12620 KB |
Output is correct |
28 |
Correct |
127 ms |
12560 KB |
Output is correct |
29 |
Correct |
294 ms |
14312 KB |
Output is correct |
30 |
Correct |
253 ms |
14656 KB |
Output is correct |
31 |
Correct |
327 ms |
13376 KB |
Output is correct |
32 |
Correct |
154 ms |
12380 KB |
Output is correct |
33 |
Correct |
152 ms |
13228 KB |
Output is correct |
34 |
Correct |
126 ms |
13464 KB |
Output is correct |
35 |
Correct |
336 ms |
13016 KB |
Output is correct |
36 |
Correct |
369 ms |
14336 KB |
Output is correct |
37 |
Correct |
316 ms |
15180 KB |
Output is correct |
38 |
Correct |
338 ms |
14988 KB |
Output is correct |
39 |
Correct |
370 ms |
14960 KB |
Output is correct |
40 |
Correct |
349 ms |
14980 KB |
Output is correct |
41 |
Correct |
327 ms |
14756 KB |
Output is correct |
42 |
Correct |
375 ms |
14908 KB |
Output is correct |
43 |
Correct |
354 ms |
14172 KB |
Output is correct |
44 |
Correct |
353 ms |
14640 KB |
Output is correct |
45 |
Correct |
351 ms |
14520 KB |
Output is correct |
46 |
Correct |
359 ms |
15692 KB |
Output is correct |
47 |
Correct |
161 ms |
13156 KB |
Output is correct |
48 |
Correct |
149 ms |
13220 KB |
Output is correct |
49 |
Correct |
341 ms |
13176 KB |
Output is correct |
50 |
Correct |
181 ms |
13012 KB |
Output is correct |
51 |
Correct |
122 ms |
13340 KB |
Output is correct |
52 |
Correct |
181 ms |
13260 KB |
Output is correct |