Submission #232779

#TimeUsernameProblemLanguageResultExecution timeMemory
232779huangqrFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
144 ms8188 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...