Submission #1051592

#TimeUsernameProblemLanguageResultExecution timeMemory
1051592gagik_2007Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
664 ms20820 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pii; typedef pair<ll, ll> pll; #define ff first #define ss second ll ttt; const ll INF=1e18; const ll MOD=1e9+7; const ll N=200007; ll n,m,k; ll t[4*N]; ll lazy[8*N]; ll a[N]; void push(ll v, ll tl, ll tr){ if(lazy[v]!=0){ ll len=tr-tl+1; t[v]+=lazy[v]*len; lazy[2*v]+=lazy[v]; lazy[2*v+1]+=lazy[v]; lazy[v]=0; } } void build(ll v, ll tl, ll tr){ if(tl==tr){ t[v]=a[tl]; } else{ ll tm=(tl+tr)/2; build(2*v,tl,tm); build(2*v+1,tm+1,tr); t[v]=t[2*v]+t[2*v+1]; } } void add(ll v, ll tl, ll tr, ll l, ll r, ll vl){ push(v,tl,tr); if(l>r)return; if(l==tl&&r==tr){ lazy[v]+=vl; push(v,tl,tr); } else{ ll tm=(tl+tr)/2; add(2*v,tl,tm,l,min(r,tm),vl); push(v,tl,tr); add(2*v+1,tm+1,tr,max(tm+1,l),r,vl); push(v,tl,tr); t[v]=t[2*v]+t[2*v+1]; } } ll getsum(ll v, ll tl, ll tr, ll l, ll r){ push(v,tl,tr); if(l>r)return 0; if(tl==l&&tr==r){ return t[v]; } else{ ll tm=(tl+tr)/2; push(v,tl,tr); return getsum(2*v,tl,tm,l,min(r,tm))+ getsum(2*v+1,tm+1,tr,max(tm+1,l),r); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("Ainput.txt","r",stdin); // freopen("Aoutput.txt","w",stdout); ll s,t; cin>>n>>m>>s>>t; n++; for(ll i=0;i<n;i++){ cin>>a[i]; } build(1,0,n-1); ll ans=0; for(ll i=0;i<n-1;i++){ if(a[i]<a[i+1]){ ans-=s*(a[i+1]-a[i]); } else{ ans+=t*(a[i]-a[i+1]); } } for(ll i=0;i<m;i++){ ll l,r; ll w; cin>>l>>r>>w; a[l-1]=getsum(1,0,n-1,l-1,l-1); a[l]=getsum(1,0,n-1,l,l); // cout<<a[l-1]<<" "<<a[l]<<endl; // cout<<"OK"<<endl; if(r!=n-1){ a[r]=getsum(1,0,n-1,r,r); a[r+1]=getsum(1,0,n-1,r+1,r+1); // cout<<a[r]<<" "<<a[r+1]<<endl; } if(a[l-1]<a[l]){ ans+=s*(a[l]-a[l-1]); } else{ ans-=t*(a[l-1]-a[l]); } if(r!=n-1){ if(a[r]<a[r+1]){ ans+=s*(a[r+1]-a[r]); } else{ ans-=t*(a[r]-a[r+1]); } } add(1,0,n-1,l,r,w); a[l-1]=getsum(1,0,n-1,l-1,l-1); a[l]=getsum(1,0,n-1,l,l); // cout<<a[l-1]<<" "<<a[l]<<endl; // cout<<"OK"<<endl; if(r!=n-1){ a[r]=getsum(1,0,n-1,r,r); a[r+1]=getsum(1,0,n-1,r+1,r+1); // cout<<a[r]<<" "<<a[r+1]<<endl; } if(a[l-1]<a[l]){ ans-=s*(a[l]-a[l-1]); } else{ ans+=t*(a[l-1]-a[l]); } if(r!=n-1){ if(a[r]<a[r+1]){ ans-=s*(a[r+1]-a[r]); } else{ ans+=t*(a[r]-a[r+1]); } } cout<<ans<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...