# include <bits/stdc++.h>
# define ll long long
using namespace std;
ll A[200001];
ll ans;
ll seg[800010];
void build(int lf, int rg, int nd) {
if(lf == rg) seg[nd] = A[lf];
else {
seg[nd] = 0ll;
int mid = (lf + rg)/2;
build(lf, mid, 2*nd+1);
build(mid+1, rg, 2*nd+2);
}
}
void upd(int lf, int rg, int nd, int clf, int crg, ll ad) {
if(clf > rg || crg < lf) return;
if(clf <= lf && rg <= crg) seg[nd] += ad;
else {
int mid = (lf + rg)/2;
upd(lf, mid, 2*nd+1, clf, crg, ad);
upd(mid+1, rg, 2*nd+2, clf, crg, ad);
}
}
ll qry(int lf, int rg, int nd, int pos, ll ad) {
if(lf == rg) return seg[nd] + ad;
else {
int mid = (lf + rg)/2;
if(pos <= mid) return qry(lf, mid, 2*nd+1, pos, ad + seg[nd]);
else return qry(mid+1, rg, 2*nd+2, pos, ad + seg[nd]);
}
}
int main() {
int N, Q;
ll S, T;
scanf("%d %d %lld %lld", &N, &Q, &S, &T);
for(int i=0;i<=N;i++) scanf("%lld", &A[i]);
ans = 0ll;
for(int i=0;i<N;i++) {
if(A[i] < A[i + 1]) {
ans -= S * (A[i + 1] - A[i]);
} else {
ans += T * (A[i] - A[i + 1]);
}
}
build(0, N, 0);
while(Q--) {
int l, r;
ll x;
scanf("%d %d %lld", &l, &r, &x);
if(l > 0) {
ll g = qry(0, N, 0, l - 1, 0);
ll h = qry(0, N, 0, l, 0);
if(g < h) ans += S * (h - g);
else ans -= T * (g - h);
h += x;
if(g < h) ans -= S * (h - g);
else ans += T * (g - h);
}
if(r + 1 <= N) {
ll g = qry(0, N, 0, r, 0);
ll h = qry(0, N, 0, r + 1, 0);
if(g < h) ans += S * (h - g);
else ans -= T * (g - h);
g += x;
if(g < h) ans -= S * (h - g);
else ans += T * (g - h);
}
upd(0, N, 0, l, r, x);
printf("%lld\n", ans);
}
}
Compilation message
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d %d %lld %lld", &N, &Q, &S, &T);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:44:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | for(int i=0;i<=N;i++) scanf("%lld", &A[i]);
| ~~~~~^~~~~~~~~~~~~~~
foehn_phenomena.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | scanf("%d %d %lld", &l, &r, &x);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 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 |
316 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
3 ms |
312 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
448 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
324 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
229 ms |
12772 KB |
Output is correct |
2 |
Correct |
223 ms |
13364 KB |
Output is correct |
3 |
Correct |
239 ms |
13900 KB |
Output is correct |
4 |
Correct |
223 ms |
13364 KB |
Output is correct |
5 |
Correct |
223 ms |
14452 KB |
Output is correct |
6 |
Correct |
111 ms |
13516 KB |
Output is correct |
7 |
Correct |
110 ms |
13476 KB |
Output is correct |
8 |
Correct |
217 ms |
14392 KB |
Output is correct |
9 |
Correct |
195 ms |
14684 KB |
Output is correct |
10 |
Correct |
189 ms |
13324 KB |
Output is correct |
11 |
Correct |
131 ms |
13440 KB |
Output is correct |
12 |
Correct |
114 ms |
14156 KB |
Output is correct |
13 |
Correct |
110 ms |
14380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 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 |
316 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
3 ms |
312 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
448 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
324 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
229 ms |
12772 KB |
Output is correct |
23 |
Correct |
223 ms |
13364 KB |
Output is correct |
24 |
Correct |
239 ms |
13900 KB |
Output is correct |
25 |
Correct |
223 ms |
13364 KB |
Output is correct |
26 |
Correct |
223 ms |
14452 KB |
Output is correct |
27 |
Correct |
111 ms |
13516 KB |
Output is correct |
28 |
Correct |
110 ms |
13476 KB |
Output is correct |
29 |
Correct |
217 ms |
14392 KB |
Output is correct |
30 |
Correct |
195 ms |
14684 KB |
Output is correct |
31 |
Correct |
189 ms |
13324 KB |
Output is correct |
32 |
Correct |
131 ms |
13440 KB |
Output is correct |
33 |
Correct |
114 ms |
14156 KB |
Output is correct |
34 |
Correct |
110 ms |
14380 KB |
Output is correct |
35 |
Correct |
227 ms |
12908 KB |
Output is correct |
36 |
Correct |
224 ms |
14256 KB |
Output is correct |
37 |
Correct |
232 ms |
15108 KB |
Output is correct |
38 |
Correct |
250 ms |
14968 KB |
Output is correct |
39 |
Correct |
236 ms |
14892 KB |
Output is correct |
40 |
Correct |
225 ms |
14960 KB |
Output is correct |
41 |
Correct |
227 ms |
14800 KB |
Output is correct |
42 |
Correct |
231 ms |
14800 KB |
Output is correct |
43 |
Correct |
224 ms |
14156 KB |
Output is correct |
44 |
Correct |
228 ms |
14508 KB |
Output is correct |
45 |
Correct |
244 ms |
14540 KB |
Output is correct |
46 |
Correct |
222 ms |
15664 KB |
Output is correct |
47 |
Correct |
113 ms |
14256 KB |
Output is correct |
48 |
Correct |
129 ms |
14212 KB |
Output is correct |
49 |
Correct |
216 ms |
13156 KB |
Output is correct |
50 |
Correct |
136 ms |
14028 KB |
Output is correct |
51 |
Correct |
111 ms |
14424 KB |
Output is correct |
52 |
Correct |
129 ms |
14092 KB |
Output is correct |