This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define v vector
#define int long long
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define ff first
#define ss second
#define inp_v(vec) for (auto &i : vec) cin >> i;
#define prt_v(vec) for (auto i : vec) cout << i << endl;
#define MS(x) memset(x, 0, sizeof(x))
#define gcd(a,b) __gcd(a, b);
#define lcm(a,b) (a*(b/gcd(a,b)))
#define lb lower_bound
#define ub upper_bound
bool chmin(int &a, int b){return b<a?a=b, true:false;}
bool chmax(int &a, int b){return b>a?a=b, true:false;}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int N, q, s, t;cin>>N>>q>>s>>t;
int A[N+5];
for(int i=0;i<=N;i++)cin>>A[i];
vector<int>sum(N+5);
sum[0]=A[0];
int sump=0, sumn=0;
for(int i=1;i<=N;i++){
if(A[i-1]>=A[i]){
sum[i]=(A[i-1]-A[i]);
sump+=sum[i];
}
else{
sum[i]=(A[i-1]-A[i]);
sumn+=sum[i];
}
}
// for(int i=0;i<=N;i++)cout<<sum[i]<<" ";
// cout<<endl;
while(q--){
int l, r, num;cin>>l>>r>>num;
r++;
if(sum[l]>=0){
sump-=sum[l];
}
else{
sumn-=sum[l];
}
if(r!=N+1){
if(sum[r]>=0){
sump-=sum[r];
}
else sumn-=sum[r];
}
sum[l]-=num;
if(sum[r]!=N+1)sum[r]+=num;
if(sum[l]>=0){
sump+=sum[l];
}
else sumn+=sum[l];
if(r!=N+1){
if(sum[r]>=0)sump+=sum[r];
else sumn+=sum[r];
}
// for(int i=0;i<=N;i++)cout<<sum[i]<<" ";
// cout<<endl;
// cout<<sump<<" "<<sumn<<endl;
cout<<sump*t+sumn*s<<endl;
// if(sum[l]<0){
// }
// else{
// }
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |