이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e5+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
ll n,q,S,T,x,sum,l,r,seg[4*N];
void ins(ll id,ll L,ll R,ll ql,ll qr,ll D){
if(L>=ql&&R<=qr){seg[id]+=D;return;}
if(L>=qr||R<=ql)return;
ll mid=(L+R)/2;
ins(id*2,L,mid,ql,qr,D);
ins(id*2+1,mid,R,ql,qr,D);
}
ll Q(ll id,ll L,ll R,ll to){
if(L==R-1)return seg[id];
ll mid=(L+R)/2;
if(to<mid){
return seg[id]+Q(id*2,L,mid,to);
}else{
return seg[id]+Q(id*2+1,mid,R,to);
}
}
ll ck(ll id){
if(id==n)return 0;
ll a=Q(1,0,n+1,id),b=Q(1,0,n+1,id+1);
return (a<b?-S*(b-a):(a-b)*T);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>q>>S>>T;
REP(i,n+1)cin>>x,ins(1,0,n+1,i,i+1,x);
REP(i,n+1)sum+=ck(i);
while(q--){
cin>>l>>r>>x;
sum-=(ck(l-1)+ck(r));
ins(1,0,n+1,l,r+1,x);
sum+=(ck(l-1)+ck(r));
cout<<sum<<"\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |