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;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
void solve(){
ll n, q, s, t, pos = 0, neg = 0;
cin >> n >> q >> s >> t;
vector<ll> a(n+1), diff(n+1);
for(int i = 0; i <= n; i++)
cin >> a[i];
for(int i = 1; i <= n; i++){
diff[i] = a[i] - a[i-1];
if(a[i] >= a[i-1])
pos += diff[i];
else
neg += -diff[i];
}
//cout << neg*t - pos*s << '\n';
for(int i = 0; i < q; i++){
ll l, r, x;
cin >> l >> r >> x;
if(diff[l] < 0)
neg -= -diff[l];
else
pos -= diff[l];
diff[l] += x;
if(diff[l] < 0)
neg += -diff[l];
else
pos += diff[l];
if(r != n){
if(diff[r+1] < 0)
neg -= -diff[r+1];
else
pos -= diff[r+1];
diff[r+1] -= x;
if(diff[r+1] < 0)
neg += -diff[r+1];
else
pos += diff[r+1];
}
cout << neg*t - pos*s << '\n';
}
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |