#include<bits/stdc++.h>
using namespace std;
struct dataa{
long long fval = 0,lval = 0,lcount = 0,rcount =0,lazy =0,ans =0;
void add(long long left,long long right,long long val){
fval+=val;
lval+=val;
lazy+=val;
//sum += val *(right - left + 1);
}
};
long long S,T;
struct Segment_Tree{
vector<dataa>tree;
void build(long long node,long long left,long long right,vector<long long>&arr,long long n){
if (left == right){
tree[node].fval = arr[left];
tree[node].lval = arr[left];
return ;
}
long long mid = (left + right)>>1;
long long z = node + ((mid - left + 1)<<1);
build(node + 1,left,mid,arr,n);
build(z,mid + 1,right,arr,n);
tree[node] = combine(tree[node + 1],tree[z]);
}
void init(long long n,vector<long long>&arr){
tree.resize(2*n - 1);
build(0,0,n-1,arr,n);
}
dataa combine(dataa left,dataa right){
dataa res;
res.lval = right.lval;
res.fval = left.fval;
res.lcount = left.lcount + right.lcount + (left.lval < right.fval);
res.rcount = left.rcount + right.rcount + (left.lval >= right.fval);
res.ans = left.ans + right.ans;
res.ans -= max(0LL,(right.fval - left.lval)) * S;
res.ans += max(0LL,(left.lval - right.fval)) * T;
return res;
}
void push(long long node,long long left,long long right){
long long mid = (left + right)>>1;
long long z = node + ((mid - left + 1)<<1);
if (tree[node].lazy!=0){
tree[node + 1].add(left,right,tree[node].lazy);
tree[z].add(left,right,tree[node].lazy);
tree[node].lazy = 0;
}
}
dataa query(long long node,long long left,long long right,long long qleft,long long qright){
if (qright<left|| qleft > right)return {0,0,0,0,0};
if (qleft<=left && qright>=right){
return tree[node];
}
push(node,left,right);
long long mid = (left + right)>>1;
long long z = node + ((mid - left + 1)<<1);
return combine(query(node + 1,left,mid,qleft,qright),query(z,mid + 1,right,qleft,qright));
}
void update(long long node,long long left,long long right,long long uleft,long long uright,long long v){
if (left > uright || right < uleft) return;
if (uleft <= left && right <=uright){
tree[node].add(left,right,v);
return;
}
push(node,left,right);
long long mid = (left + right)>>1;
long long z = node + ((mid - left + 1)<<1);
if (uleft<=mid){
update(node + 1,left,mid,uleft,uright,v);
}
if (uright > mid){
update(z,mid + 1,right,uleft,uright,v);
}
tree[node] = combine(tree[node + 1],tree[z]);
}
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n,q;
cin>>n>>q>>S>>T;
++n;
vector<long long>arr(n);
for (long long i = 0;i<n;++i)cin>>arr[i];
Segment_Tree st;
st.init(n,arr);
for (long long i = 0;i<q;++i){
long long l,r,x;cin>>l>>r>>x;
st.update(0,0,n - 1,l,r,x);
dataa ans = st.query(0,0,n-1,0,n-1);
cout<<ans.ans<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
516 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
3 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
516 KB |
Output is correct |
13 |
Correct |
2 ms |
588 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
343 ms |
22448 KB |
Output is correct |
2 |
Correct |
303 ms |
23196 KB |
Output is correct |
3 |
Correct |
347 ms |
23604 KB |
Output is correct |
4 |
Correct |
314 ms |
22860 KB |
Output is correct |
5 |
Correct |
305 ms |
23500 KB |
Output is correct |
6 |
Correct |
163 ms |
24024 KB |
Output is correct |
7 |
Correct |
154 ms |
24000 KB |
Output is correct |
8 |
Correct |
284 ms |
23884 KB |
Output is correct |
9 |
Correct |
279 ms |
24272 KB |
Output is correct |
10 |
Correct |
256 ms |
22972 KB |
Output is correct |
11 |
Correct |
165 ms |
24040 KB |
Output is correct |
12 |
Correct |
147 ms |
24380 KB |
Output is correct |
13 |
Correct |
166 ms |
24768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
516 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
3 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
516 KB |
Output is correct |
13 |
Correct |
2 ms |
588 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
320 KB |
Output is correct |
22 |
Correct |
343 ms |
22448 KB |
Output is correct |
23 |
Correct |
303 ms |
23196 KB |
Output is correct |
24 |
Correct |
347 ms |
23604 KB |
Output is correct |
25 |
Correct |
314 ms |
22860 KB |
Output is correct |
26 |
Correct |
305 ms |
23500 KB |
Output is correct |
27 |
Correct |
163 ms |
24024 KB |
Output is correct |
28 |
Correct |
154 ms |
24000 KB |
Output is correct |
29 |
Correct |
284 ms |
23884 KB |
Output is correct |
30 |
Correct |
279 ms |
24272 KB |
Output is correct |
31 |
Correct |
256 ms |
22972 KB |
Output is correct |
32 |
Correct |
165 ms |
24040 KB |
Output is correct |
33 |
Correct |
147 ms |
24380 KB |
Output is correct |
34 |
Correct |
166 ms |
24768 KB |
Output is correct |
35 |
Correct |
309 ms |
22692 KB |
Output is correct |
36 |
Correct |
372 ms |
23984 KB |
Output is correct |
37 |
Correct |
338 ms |
24872 KB |
Output is correct |
38 |
Correct |
313 ms |
24628 KB |
Output is correct |
39 |
Correct |
330 ms |
24648 KB |
Output is correct |
40 |
Correct |
347 ms |
24676 KB |
Output is correct |
41 |
Correct |
336 ms |
24260 KB |
Output is correct |
42 |
Correct |
311 ms |
24400 KB |
Output is correct |
43 |
Correct |
333 ms |
23760 KB |
Output is correct |
44 |
Correct |
319 ms |
24088 KB |
Output is correct |
45 |
Correct |
322 ms |
23816 KB |
Output is correct |
46 |
Correct |
327 ms |
24396 KB |
Output is correct |
47 |
Correct |
167 ms |
28880 KB |
Output is correct |
48 |
Correct |
139 ms |
28880 KB |
Output is correct |
49 |
Correct |
307 ms |
27980 KB |
Output is correct |
50 |
Correct |
172 ms |
28664 KB |
Output is correct |
51 |
Correct |
157 ms |
29064 KB |
Output is correct |
52 |
Correct |
210 ms |
28924 KB |
Output is correct |