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<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define endl "\n"
#define out(x) cout<< #x << " = " << x << endl
int n,q; ll s,t;
ll arr[200005], diff[200005], ans;
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>q>>s>>t;
for (int i=0;i<=n;i++) cin>>arr[i];
for (int i=1;i<=n;i++) {
diff[i] = arr[i] - arr[i-1];
if (diff[i] > 0) ans -= s*diff[i];
else ans -= t*diff[i];
}
//out(ans);
while(q--){
int i,j; ll x; cin>>i>>j>>x;
if (diff[i] > 0) ans += s*diff[i];
else ans += t*diff[i];
if (j!=n){
if (diff[j+1] > 0) ans += s*diff[j+1];
else ans += t*diff[j+1];
}
diff[i] += x; diff[j+1] -= x;
if (diff[i] > 0) ans -= s*diff[i];
else ans -= t*diff[i];
if (j!=n){
if (diff[j+1] > 0) ans -= s*diff[j+1];
else ans -= t*diff[j+1];
}
//cout<<"#";
cout<<ans<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |