이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll asize=2e5+5;
ll n,q,s,t,d[asize],pdsum=0,ndsum=0;
int main(){
ios_base::sync_with_stdio(0),cin.tie(NULL);
cin>>n>>q>>s>>t;
ll k,pre,a,b,c;
n++;
for(int i=0;i<n;i++){
cin>>k;
if(i){
d[i]=k-pre;
if(d[i]>=0)pdsum+=d[i];
else ndsum-=d[i];
}
pre=k;
}
/* cout<<"d array\n";
for(int i=0;i<n;i++){
cout<<d[i]<<" ";
}
cout<<"\npdsum="<<pdsum<<"\tndsum="<<ndsum<<"\n";*/
for(int i=0;i<q;i++){
cin>>a>>b>>c;
ll ov=d[a];
d[a]+=c;
if(ov>=0){
if(d[a]>0)pdsum+=c;
else{
pdsum-=ov;
ndsum-=(c+ov);
}
}
else{
if(d[a]<0)ndsum-=c;
else{
ndsum+=ov;
pdsum+=(c+ov);
}
}
b++;
if(b==n)goto cont;
ov=d[b];
c=-c;
d[b]+=c;
if(ov>=0){
if(d[b]>0)pdsum+=c;
else{
pdsum-=ov;
ndsum-=(c+ov);
}
}
else{
if(d[b]<0)ndsum-=c;
else{
ndsum+=ov;
pdsum+=(c+ov);
}
}
cont:
/* cout<<"d array\n";
for(int i=0;i<n;i++){
cout<<d[i]<<" ";
}
cout<<"\npdsum="<<pdsum<<"\tndsum="<<ndsum<<"\n";*/
cout<<ndsum*t-pdsum*s<<"\n";
}
return 0;
}
/*
ll ftp[asize],ftn[asize],n=asize,q,s,t;
void update(ll ft[],ll p,ll v){
for(;p<=n;p+=(p & -p))ft[p]+=v;
return;
}
ll query(ll ft[],ll p){
ll ans=0;
for(;p>0;p-=(p & -p))ans+=ft[p];
return ans;
}
void rupdate(ll l, ll r,ll v){
update(ftm,l,v);
update(ftm,r+1,-v);
update(ftc,l,-1*(l-1)*v);
update(ftc,r+1,r*v);
return;
}
ll rquery(ll l,ll r){
return r*query(ftm,r)+query(ftc,r)-(l-1)*query(ftm,l-1)-query(ftc,l-1);
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |