#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int n, q, s, t; cin>>n>>q>>s>>t;
vector<int> alt(n+1);
vector<int> pre(n+1, 0);
for(int i=0; i<=n; i++) cin>>pre[i];
alt[0]=0;
int ans=0;
for(int i=1; i<=n; i++) {alt[i]=pre[i]-pre[i-1];ans-=(alt[i]*(alt[i]>0?s:t));}//cout<<ans<<'\n';}
//cout<<ans;
for(int i=0; i<q; i++){
int l, r, x;cin>>l>>r>>x;
if((alt[l]>=0||alt[l]<=-1*x)&&x>=0){
//cout<<'a';
ans-=(x*(alt[l]>=0?s:t));
}else if((alt[l]<=0||alt[l]>=x)&&x<0){
ans-=(x*(alt[l]<=0?t:s));
//cout<<'b';
}else if(alt[l]<0){
ans+=(alt[l]*t);
ans+=((alt[l]+x)*(-1)*s);
//cout<<"c";
}
else if(alt[l]>0){
//cout<<'d';
ans+=(alt[l]*s);
ans+=((x-alt[l])*t);
}
if(r!=n){
if((alt[r+1]>=0||alt[r+1]<=-1*x)&&x>=0){
ans+=(x*(alt[r+1]>=0?s:t));
}else if((alt[r+1]<=0||alt[r+1]>=x)&&x<0){
ans+=(x*(alt[r+1]<=0?t:s));
}else if(alt[r+1]<0){
ans-=(alt[r+1]*s);
ans-=((alt[r+1]+x)*(-1)*t);
}
else if(alt[r+1]>0){
ans-=(alt[r+1]*t);
ans-=((x-alt[r+1])*s);
}
//alt[l]+=x;
alt[r+1]-=x;}
alt[l]+=x;
//for(int x:alt) cout<<x<<' ';
cout<<ans<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
4932 KB |
Output is correct |
2 |
Correct |
70 ms |
5556 KB |
Output is correct |
3 |
Correct |
73 ms |
6108 KB |
Output is correct |
4 |
Correct |
67 ms |
5380 KB |
Output is correct |
5 |
Correct |
81 ms |
6136 KB |
Output is correct |
6 |
Correct |
62 ms |
6408 KB |
Output is correct |
7 |
Correct |
61 ms |
6480 KB |
Output is correct |
8 |
Correct |
72 ms |
6280 KB |
Output is correct |
9 |
Correct |
78 ms |
6684 KB |
Output is correct |
10 |
Correct |
71 ms |
5384 KB |
Output is correct |
11 |
Correct |
59 ms |
6480 KB |
Output is correct |
12 |
Correct |
60 ms |
6740 KB |
Output is correct |
13 |
Correct |
72 ms |
7504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |