#include<bits/stdc++.h>
using namespace std;
#define int long long
struct seg{
int l, r, val, s, t, mid;
seg* ch[2] = {};
seg(int _l, int _r, int _s, int _t, vector<int> &arr):l(_l),r(_r),s(_s),t(_t){
if(l == r-1){
val = arr[l];
return;
}
mid = (l+r)/2;
ch[0] = new seg(l, mid, s, t, arr);
ch[1] = new seg(mid, r, s, t, arr);
pull();
}
int get(){
if(l == r-1){
if(val < 0){
return val*(0-t);
}
else{
return val*(0-s);
}
}
return val;
}
void pull(){
val = ch[0]->get() + ch[1]->get();
}
void add(int idx, int k){
if(l == r-1){
val += k;
return;
}
if(idx < mid){
ch[0]->add(idx, k);
}
else{
ch[1]->add(idx, k);
}
pull();
}
int query(int a, int b){
if(a <= l && r <= b){
return get();
}
int ans = 0;
if(a < mid){
ans += ch[0]->get();
}
if(b > mid){
ans += ch[1]->get();
}
return ans;
}
};
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n, q, s, t;
cin >> n >> q >> s >> t;
int sum;
cin >> sum;
vector<int> arr;
for(int i = 0, tmp; i < n; i++){
cin >> tmp;
arr.push_back(tmp - sum);
sum = tmp;
}
seg tr(0,n,s,t,arr);
for(int i = 0, a, b, c; i < q; i++){
cin >> a >> b >> c;
a--;
tr.add(a, c);
if(b < n){
tr.add(b, (0-c));
}
cout << tr.query(0, n) << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
596 KB |
Output is correct |
2 |
Correct |
4 ms |
724 KB |
Output is correct |
3 |
Correct |
5 ms |
652 KB |
Output is correct |
4 |
Correct |
4 ms |
724 KB |
Output is correct |
5 |
Correct |
4 ms |
708 KB |
Output is correct |
6 |
Correct |
5 ms |
648 KB |
Output is correct |
7 |
Correct |
5 ms |
724 KB |
Output is correct |
8 |
Correct |
5 ms |
724 KB |
Output is correct |
9 |
Correct |
5 ms |
724 KB |
Output is correct |
10 |
Correct |
5 ms |
700 KB |
Output is correct |
11 |
Correct |
4 ms |
724 KB |
Output is correct |
12 |
Correct |
4 ms |
748 KB |
Output is correct |
13 |
Correct |
4 ms |
724 KB |
Output is correct |
14 |
Correct |
5 ms |
716 KB |
Output is correct |
15 |
Correct |
4 ms |
724 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
6 ms |
724 KB |
Output is correct |
18 |
Correct |
4 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
571 ms |
40040 KB |
Output is correct |
2 |
Correct |
553 ms |
40596 KB |
Output is correct |
3 |
Correct |
558 ms |
41224 KB |
Output is correct |
4 |
Correct |
560 ms |
40628 KB |
Output is correct |
5 |
Correct |
565 ms |
41832 KB |
Output is correct |
6 |
Correct |
329 ms |
40780 KB |
Output is correct |
7 |
Correct |
343 ms |
40768 KB |
Output is correct |
8 |
Correct |
498 ms |
41520 KB |
Output is correct |
9 |
Correct |
504 ms |
41936 KB |
Output is correct |
10 |
Correct |
500 ms |
40628 KB |
Output is correct |
11 |
Correct |
348 ms |
40688 KB |
Output is correct |
12 |
Correct |
332 ms |
41548 KB |
Output is correct |
13 |
Correct |
340 ms |
41544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
596 KB |
Output is correct |
2 |
Correct |
4 ms |
724 KB |
Output is correct |
3 |
Correct |
5 ms |
652 KB |
Output is correct |
4 |
Correct |
4 ms |
724 KB |
Output is correct |
5 |
Correct |
4 ms |
708 KB |
Output is correct |
6 |
Correct |
5 ms |
648 KB |
Output is correct |
7 |
Correct |
5 ms |
724 KB |
Output is correct |
8 |
Correct |
5 ms |
724 KB |
Output is correct |
9 |
Correct |
5 ms |
724 KB |
Output is correct |
10 |
Correct |
5 ms |
700 KB |
Output is correct |
11 |
Correct |
4 ms |
724 KB |
Output is correct |
12 |
Correct |
4 ms |
748 KB |
Output is correct |
13 |
Correct |
4 ms |
724 KB |
Output is correct |
14 |
Correct |
5 ms |
716 KB |
Output is correct |
15 |
Correct |
4 ms |
724 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
6 ms |
724 KB |
Output is correct |
18 |
Correct |
4 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
571 ms |
40040 KB |
Output is correct |
23 |
Correct |
553 ms |
40596 KB |
Output is correct |
24 |
Correct |
558 ms |
41224 KB |
Output is correct |
25 |
Correct |
560 ms |
40628 KB |
Output is correct |
26 |
Correct |
565 ms |
41832 KB |
Output is correct |
27 |
Correct |
329 ms |
40780 KB |
Output is correct |
28 |
Correct |
343 ms |
40768 KB |
Output is correct |
29 |
Correct |
498 ms |
41520 KB |
Output is correct |
30 |
Correct |
504 ms |
41936 KB |
Output is correct |
31 |
Correct |
500 ms |
40628 KB |
Output is correct |
32 |
Correct |
348 ms |
40688 KB |
Output is correct |
33 |
Correct |
332 ms |
41548 KB |
Output is correct |
34 |
Correct |
340 ms |
41544 KB |
Output is correct |
35 |
Correct |
583 ms |
40084 KB |
Output is correct |
36 |
Correct |
556 ms |
41600 KB |
Output is correct |
37 |
Correct |
588 ms |
42396 KB |
Output is correct |
38 |
Correct |
580 ms |
42188 KB |
Output is correct |
39 |
Correct |
564 ms |
42280 KB |
Output is correct |
40 |
Correct |
549 ms |
42124 KB |
Output is correct |
41 |
Correct |
567 ms |
41920 KB |
Output is correct |
42 |
Correct |
561 ms |
42256 KB |
Output is correct |
43 |
Correct |
568 ms |
41524 KB |
Output is correct |
44 |
Correct |
555 ms |
41780 KB |
Output is correct |
45 |
Correct |
580 ms |
41732 KB |
Output is correct |
46 |
Correct |
603 ms |
42956 KB |
Output is correct |
47 |
Correct |
348 ms |
41428 KB |
Output is correct |
48 |
Correct |
348 ms |
41464 KB |
Output is correct |
49 |
Correct |
558 ms |
40516 KB |
Output is correct |
50 |
Correct |
361 ms |
41348 KB |
Output is correct |
51 |
Correct |
331 ms |
41644 KB |
Output is correct |
52 |
Correct |
359 ms |
41412 KB |
Output is correct |