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 int long long
#define size(x) (int)x.size()
#define all(x) x.begin(), x.end()
template<class A, class S>
bool chmin(A &a, const S &s) {
return a > s ? (a = s) == s : false;
}
template<class A, class S>
bool chmax(A &a, const S &s) {
return a < s ? (a = s) == s : false;
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n, q, s, t;
cin >> n >> q >> s >> t;
vector<int> a(n + 1);
for(int i = 0; i <= n; i++) {
cin >> a[i];
}
vector<int> d(n + 1);
int ans = 0;
for(int i = 1; i <= n; i++) {
d[i] = a[i] - a[i - 1];
if(d[i] > 0){
ans -= d[i] * s;
} else {
ans -= d[i] * t;
}
}
while(q--) {
int l, r, x;
cin >> l >> r >> x;
if (l > 0 && l <= n) {
if(d[l] > 0){
ans += d[l] * s;
} else {
ans += d[l] * t;
}
}
if(r + 1 <= n) {
if(d[r + 1] > 0){
ans += d[r + 1] * s;
} else {
ans += d[r + 1] * t;
}
}
if (l > 0 && l <= n) {
d[l] = d[l] + x;
if(d[l] > 0){
ans -= d[l] * s;
} else {
ans -= d[l] * t;
}
}
if(r + 1 <= n){
d[r + 1] = d[r + 1] - x;
if(d[r + 1] > 0){
ans -= d[r + 1] * s;
} else {
ans -= d[r + 1] * t;
}
}
cout << ans << "\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... |