제출 #869780

#제출 시각아이디문제언어결과실행 시간메모리
869780epicci23Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
92 ms13096 KiB
#include "bits/stdc++.h" using namespace std; #define pb push_back #define endl "\n" #define int long long #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH * SIMPLIFY THE PROBLEM * READ THE STATEMENT CAREFULLY !!! if there is an specified/interesting smth(i.e. constraint) in the statement, then you must be careful about that */ void solve(){ int n,q,s,t; cin >> n >> q >> s >> t; s*=-1; t*=-1; int ar[n+5]; int diff[n+5]; for(int i=0;i<=n;i++) cin >> ar[i]; for(int i=1;i<=n;i++) diff[i]=ar[i]-ar[i-1]; int ans=0; for(int i=1;i<=n;i++){ if(diff[i]>0) ans+=s*diff[i]; else ans+=t*diff[i]; } while(q--){ int l,r,x; cin >> l >> r >> x; if(diff[l]>0) ans-=s*diff[l]; else ans-=t*diff[l]; if(r+1<=n){ if(diff[r+1]>0) ans-=s*diff[r+1]; else ans-=t*diff[r+1]; } diff[l]+=x; diff[r+1]-=x; if(diff[l]>0) ans+=s*diff[l]; else ans+=t*diff[l]; if(r+1<=n){ if(diff[r+1]>0) ans+=s*diff[r+1]; else ans+=t*diff[r+1]; } cout << ans << endl; } } int32_t main(){ cin.tie(0); ios::sync_with_stdio(0); int t=1;//cin >> t; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...