# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
211756 | origami100 | Foehn Phenomena (JOI17_foehn_phenomena) | C++11 | 0 ms | 0 KiB |
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;
typedef long long ll;
ll main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, q, s, t;
cin >> n >> q >> s >> t;
ll pre;
cin >> pre;
vector <ll> diff;
ll pos = 0, neg = 0;
for(ll i = 0; i < n; i++){
ll a;
cin >> a;
diff.push_back(a - pre);
if(a - pre < 0) neg += a - pre;
else pos += a - pre;
pre = a;
}
/*for(ll j = 0; j < diff.size(); j++){
cout << diff[j] << ' ';
}*/
for(ll i = 0; i < q; i++){
ll l, r, x;
cin >> l >> r >> x;
if(diff[l - 1] < 0){
neg -= diff[l - 1];
}else{
pos -= diff[l - 1];
}
diff[l - 1] += x;
if(diff[l - 1] < 0){
neg += diff[l - 1];
}else{
pos += diff[l - 1];
}
if(r < n){
if(diff[r] < 0){
neg -= diff[r];
}else{
pos -= diff[r];
}
diff[r] -= x;
if(diff[r] < 0){
neg += diff[r];
}else{
pos += diff[r];
}
}
/*for(ll j = 0; j < diff.size(); j++){
cout << diff[j] << ' ';
}
cout << '\n';
cout << pos << ' ' << neg << '\n';*/
cout << 0 - ((pos * s) + (neg * t)) << '\n';
}
}