Submission #209972

#TimeUsernameProblemLanguageResultExecution timeMemory
209972AlainSuFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
831 ms13176 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN=200200; long long n,q,s,t,d[MAXN]={},a[MAXN]={},ans=0; void output(); void input() { cin>>n>>q>>s>>t; for (int i=0;i<=n;i++) cin>>a[i]; for (int i=1;i<=n;i++) { d[i]=a[i]-a[i-1]; if (d[i]>0) ans-=d[i]*s; else ans-=d[i]*t; } } void process(long long l,long long r,long long v) { long long ndl=d[l]+v,ndr=d[r]-v; if (d[l]<=0 && ndl<=0) ans+=(d[l]-ndl)*t; if (d[l]<=0 && ndl>0) ans=ans-ndl*s+d[l]*t; if (d[l]>0 && ndl<=0) ans=ans-ndl*t+d[l]*s; if (d[l]>0 && ndl>0) ans+=(d[l]-ndl)*s; if (r<=n) { if (d[r]<=0 && ndr<=0) ans+=(d[r]-ndr)*t; if (d[r]<=0 && ndr>0) ans=ans-ndr*s+d[r]*t; if (d[r]>0 && ndr<=0) ans=ans-ndr*t+d[r]*s; if (d[r]>0 && ndr>0) ans+=(d[r]-ndr)*s; } d[l]+=v; d[r]-=v; } void output() { cout<<ans<<endl; } int main() { int x,y,v; input(); for (int i=1;i<=q;i++) { cin>>x>>y>>v; process(x,y+1,v); output(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...