#include<bits/stdc++.h>
using namespace std;
long long mas[200001];
long long tree[1000001];
void update(long long in,long long l,long long r,long long ot,long long du,long long k){
if(l>=ot && r<=du){
tree[in]+=k;
return ;
}
long long mid=(l+r)/2;
if(ot<=mid){
update(in*2,l,mid,ot,du,k);
}if(du>mid){
update(in*2+1,mid+1,r,ot,du,k);
}
return ;
}
long long ans(long long in,long long l,long long r,long long koj){
if(l==r){
return mas[l]+tree[in];
}
long long mid=(l+r)/2;
long long otg;
if(koj<=mid){
otg=ans(in*2,l,mid,koj);
}else{
otg=ans(in*2+1,mid+1,r,koj);
}
return otg+tree[in];
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
long long N,Q,S,T;
cin>>N>>Q>>S>>T;
long long nach=0;
cin>>mas[0];
for(long long i=1;i<=N;i++){
cin>>mas[i];
if(mas[i-1]<mas[i]){
nach-=(S*(mas[i]-mas[i-1]));
}else{
nach+=(T*(mas[i-1]-mas[i]));
}
}
//cout<<nach<<"\n";
long long l,r,x;
for(long long i=0;i<Q;i++){
cin>>l>>r>>x;
if(l!=0){
long long a1=ans(1,0,N,l-1);
long long a2=ans(1,0,N,l);
if(a1<a2){
nach+=(S*(a2-a1));
}else{
nach-=(T*(a1-a2));
}
}if(r!=N){
long long a1=ans(1,0,N,r);
long long a2=ans(1,0,N,r+1);
if(a1<a2){
nach+=(S*(a2-a1));
}else{
nach-=(T*(a1-a2));
}
}
update(1,0,N,l,r,x);
if(l!=0){
long long a1=ans(1,0,N,l-1);
long long a2=ans(1,0,N,l);
if(a1<a2){
nach-=(S*(a2-a1));
}else{
nach+=(T*(a1-a2));
}
}if(r!=N){
long long a1=ans(1,0,N,r);
long long a2=ans(1,0,N,r+1);
if(a1<a2){
nach-=(S*(a2-a1));
}else{
nach+=(T*(a1-a2));
}
}
cout<<nach<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
3 ms |
2560 KB |
Output is correct |
6 |
Correct |
3 ms |
2392 KB |
Output is correct |
7 |
Correct |
3 ms |
2392 KB |
Output is correct |
8 |
Correct |
3 ms |
2396 KB |
Output is correct |
9 |
Correct |
3 ms |
2396 KB |
Output is correct |
10 |
Correct |
3 ms |
2552 KB |
Output is correct |
11 |
Correct |
2 ms |
2416 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
13 |
Correct |
2 ms |
2396 KB |
Output is correct |
14 |
Correct |
2 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
2 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
265 ms |
9120 KB |
Output is correct |
2 |
Correct |
251 ms |
14928 KB |
Output is correct |
3 |
Correct |
257 ms |
15444 KB |
Output is correct |
4 |
Correct |
256 ms |
14960 KB |
Output is correct |
5 |
Correct |
253 ms |
16212 KB |
Output is correct |
6 |
Correct |
97 ms |
11088 KB |
Output is correct |
7 |
Correct |
97 ms |
10964 KB |
Output is correct |
8 |
Correct |
219 ms |
15864 KB |
Output is correct |
9 |
Correct |
215 ms |
16156 KB |
Output is correct |
10 |
Correct |
211 ms |
14960 KB |
Output is correct |
11 |
Correct |
113 ms |
11028 KB |
Output is correct |
12 |
Correct |
109 ms |
11604 KB |
Output is correct |
13 |
Correct |
95 ms |
11856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
3 ms |
2560 KB |
Output is correct |
6 |
Correct |
3 ms |
2392 KB |
Output is correct |
7 |
Correct |
3 ms |
2392 KB |
Output is correct |
8 |
Correct |
3 ms |
2396 KB |
Output is correct |
9 |
Correct |
3 ms |
2396 KB |
Output is correct |
10 |
Correct |
3 ms |
2552 KB |
Output is correct |
11 |
Correct |
2 ms |
2416 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
13 |
Correct |
2 ms |
2396 KB |
Output is correct |
14 |
Correct |
2 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
2 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
265 ms |
9120 KB |
Output is correct |
23 |
Correct |
251 ms |
14928 KB |
Output is correct |
24 |
Correct |
257 ms |
15444 KB |
Output is correct |
25 |
Correct |
256 ms |
14960 KB |
Output is correct |
26 |
Correct |
253 ms |
16212 KB |
Output is correct |
27 |
Correct |
97 ms |
11088 KB |
Output is correct |
28 |
Correct |
97 ms |
10964 KB |
Output is correct |
29 |
Correct |
219 ms |
15864 KB |
Output is correct |
30 |
Correct |
215 ms |
16156 KB |
Output is correct |
31 |
Correct |
211 ms |
14960 KB |
Output is correct |
32 |
Correct |
113 ms |
11028 KB |
Output is correct |
33 |
Correct |
109 ms |
11604 KB |
Output is correct |
34 |
Correct |
95 ms |
11856 KB |
Output is correct |
35 |
Correct |
251 ms |
14416 KB |
Output is correct |
36 |
Correct |
252 ms |
15808 KB |
Output is correct |
37 |
Correct |
260 ms |
16704 KB |
Output is correct |
38 |
Correct |
260 ms |
16468 KB |
Output is correct |
39 |
Correct |
261 ms |
16424 KB |
Output is correct |
40 |
Correct |
259 ms |
16424 KB |
Output is correct |
41 |
Correct |
279 ms |
16336 KB |
Output is correct |
42 |
Correct |
264 ms |
16468 KB |
Output is correct |
43 |
Correct |
268 ms |
15588 KB |
Output is correct |
44 |
Correct |
255 ms |
16172 KB |
Output is correct |
45 |
Correct |
264 ms |
16236 KB |
Output is correct |
46 |
Correct |
270 ms |
17212 KB |
Output is correct |
47 |
Correct |
101 ms |
11976 KB |
Output is correct |
48 |
Correct |
116 ms |
11744 KB |
Output is correct |
49 |
Correct |
247 ms |
14964 KB |
Output is correct |
50 |
Correct |
128 ms |
11600 KB |
Output is correct |
51 |
Correct |
102 ms |
11860 KB |
Output is correct |
52 |
Correct |
131 ms |
11676 KB |
Output is correct |