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 s second
#define f first
#define ll long long
#define left (h<<1),l,((l + r)>>1)
#define right ((h<<1)|1),((l + r)>>1) + 1,r
#define pii pair<int,int>
#define int ll
using namespace std;
const int N = 2e5 + 5;
int a[N],A[N],b[N],S,T;
int getans(int x,int y){
if (x < y) return -S*(y-x);
return (x - y)*T;
}
void upd(int h,int l,int r,int L,int R,int val){
//neli
for (int i = L; i <= R; i++)
b[i] += val;
}
int get(int h,int l,int r,int idx){
return b[idx];
}
void UPD(int h,int l,int r,int L,int R,int val){
for (int i = L; i <= R; i++)
A[i] += val;
}
int GET(int h,int l,int r,int idx){
return A[idx];
}
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,q;
cin>>n>>q>>S>>T;
++n;
for (int i = 1; i <= n; i++){
cin >> a[i];
int val = getans(a[i - 1],a[i]);
upd(1,1,n,i,n,val);
UPD(1,1,n,i,i,a[i]);
}
while (q--){
int l,r,x;
cin>>l>>r>>x;
l++,r++;
UPD(1,1,n,l,r,x);
int newx = GET(1,1,n,l - 1);
int newy = GET(1,1,n,l);
int oldx = newx;
int oldy = newy - x;
int oldval = getans(oldx,oldy);
int newval = getans(newx,newy);
upd(1,1,n,l,n,newval - oldval);
if (r + 1 <= n){
newx = GET(1,1,n,r);
newy = GET(1,1,n,r+1);
oldx = newx - x;
oldy = newy;
oldval = getans(oldx,oldy);
newval = getans(newx,newy);
upd(1,1,n,r+1,n,newval - oldval);
}
cout<<get(1,1,n,n)<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |