제출 #525649

#제출 시각아이디문제언어결과실행 시간메모리
525649GurbanFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
349 ms19004 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn=2e5+5; int n,q,s,t; int a[maxn]; ll T[4 * maxn][2]; void prop(int nd){ if(!T[nd][1]) return; T[nd<<1][0] += T[nd][1]; T[nd<<1][1] += T[nd][1]; T[nd<<1 | 1][0] += T[nd][1]; T[nd<<1 | 1][1] += T[nd][1]; T[nd][1] = 0; } void upd(int a,int b,int val,int l,int r,int nd){ if(r < a or l > b) return; if(l >= a and r <= b){ T[nd][0] += val; T[nd][1] += val; return; } int md = (l + r) >> 1; prop(nd); upd(a,b,val,l,md,nd<<1); upd(a,b,val,md+1,r,nd<<1 | 1); } ll tap(int pos,int l,int r,int nd){ if(l == r) return T[nd][0]; prop(nd); int md = (l + r) >> 1; if(pos <= md) return tap(pos,l,md,nd<<1); return tap(pos,md+1,r,nd<<1 | 1); } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> n >> q >> s >> t; for(int i = 0;i <= n;i++){ cin >> a[i]; upd(i,i,a[i],0,n,1); } ll jog = 0; for(int i = 0;i < n;i++){ if(a[i + 1] > a[i]) jog -= 1ll * s * (a[i + 1] - a[i]); else jog += 1ll * t * (a[i] - a[i + 1]); } // cout<<jog<<'\n'; while(q--){ int l,r,x; cin >> l >> r >> x; ll lft = tap(l-1,0,n,1); ll cep = tap(l,0,n,1); ll sag = tap(r,0,n,1); ll rgt = tap(r + 1,0,n,1); // cout<<lft<<' '<<cep<<' '<<sag<<' '<<rgt<<'\n'; if(lft < cep) jog += 1ll * s * (cep - lft); else jog -= 1ll * t * (lft - cep); if(r + 1 <= n){ if(sag < rgt) jog += 1ll * s * (rgt - sag); else jog -= 1ll * t * (sag - rgt); } upd(l,r,x,0,n,1); if(lft < cep + x){ jog -= 1ll * s * (cep + x - lft); } else jog += 1ll * t * (lft - cep - x); if(r + 1 <= n){ if(rgt > sag + x){ jog -= 1ll * s * (rgt - x - sag); } else jog += 1ll * t * (sag + x - rgt); } cout<<jog<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...