이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |