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 fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int,int> ii;
int n,q;
long long s,t,a[200005],b[200005],total,l,r,x;
int main(){
cin.tie(0),ios::sync_with_stdio(0);
cin >> n >> q >> s >> t;
for(int i = 0;i <= n;i++)
cin >> a[i];
for(int i = 1;i <=n;i++){
b[i] = a[i] - a[i-1];
if(a[i-1] < a[i])
total -= (a[i] - a[i-1])*s;
else
total -= (a[i] - a[i-1])*t;
}
while(q--){
cin >> l >> r >> x;
if(b[l] > 0)
total += b[l]*s;
else
total += b[l]*t;
b[l] += x;
if(b[l] > 0)
total -= b[l]*s;
else
total -= b[l]*t;
if(r+1 <= n){
if(b[r+1] > 0)
total += b[r+1]*s;
else
total += b[r+1]*t;
b[r+1] -= x;
if(b[r+1] > 0)
total -= b[r+1]*s;
else
total -= b[r+1]*t;
}
cout << total << "\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... |