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>
#define pb push_back
#define fs first
#define sc second
#define mp make_pair
using namespace std;
long long n,q,s,t;
long long a[200005];
long long sim[200005];
pair<long long,long long> diff;
int main(){
cin >> n >> q >> s >> t;
for(int i = 0; i < n + 1; i++){
cin >> a[i];
}
diff = mp(0,0);
for(int i = 0; i < n; i++){
sim[i] = a[i + 1] - a[i];
if(sim[i] > 0){
diff.fs = diff.fs + sim[i];
}else{
diff.sc = diff.sc + abs(sim[i]);
}
}
for(int i = 0; i < q; i++){
long long a,b,x; cin >> a >> b >> x;
if(a != 0){
if(sim[a - 1] > 0){
diff.fs -= sim[a - 1];
}else{
diff.sc -= abs(sim[a - 1]);
}
// if(i == 2) cout << a << " " << sim[a - 1] << " " << diff.sc << " here\n";
sim[a - 1] += x;
if(sim[a - 1] > 0){
diff.fs += sim[a - 1];
}else{
diff.sc += abs(sim[a - 1]);
}
}
if(b != n){
if(sim[b] > 0){
diff.fs -= sim[b];
}else{
diff.sc -= abs(sim[b]);
}
sim[b] -= x;
if(sim[b] > 0){
diff.fs += sim[b];
}else{
diff.sc += abs(sim[b]);
}
}
// cout << diff.fs << " " << diff.sc << " ini\n";
cout << - diff.fs * s + diff.sc * t << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |