Submission #1020165

#TimeUsernameProblemLanguageResultExecution timeMemory
1020165DucNguyen2007Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
97 ms13272 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pll pair<ll,ll> #define fi first #define se second const ll inf=2e18; const int maxN=3e5+5; int n,q; ll a[maxN+1],b[maxN+1],s,t,ans=0; void add(int i) { if(b[i]>0) { ans+=(b[i]*s); } else ans+=(b[i]*t); } void del(int i) { if(b[i]>0) { ans-=(b[i]*s); } else ans-=(b[i]*t); } int main() { //freopen("","r",stdin); //freopen("","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>q>>s>>t; for(int i=0;i<=n;i++) { cin>>a[i]; } for(int i=1;i<=n;i++) { b[i]=a[i]-a[i-1]; if(b[i]>0) { ans-=(b[i]*s); } else ans-=(b[i]*t); } while(q--) { int l,r; ll x; cin>>l>>r>>x; add(l); if(r+1<=n) { add(r+1); } b[l]+=x; if(r+1<=n) { b[r+1]-=x; } del(l); if(r+1<=n) { del(r+1); } cout<<ans<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...