제출 #239109

#제출 시각아이디문제언어결과실행 시간메모리
239109aggu_01000101Foehn Phenomena (JOI17_foehn_phenomena)C++14
30 / 100
1068 ms16120 KiB
#include <bits/stdc++.h> #define int long long #define INF 1000000000000000 #define lchild(i) (i*2 + 1) #define rchild(i) (i*2 + 2) #define mid(l, u) ((l+u)/2) #define x(p) p.first #define y(p) p.second #define MOD 998244353 using namespace std; const int N = 200005; int n, q, s, t; int a[N]; int seg[4*N]; int laz[4*N]; int build(int l, int u, int i){ laz[i] = 0; if(l==u) return seg[i] = a[l]; return seg[i] = min(build(l, mid(l, u), lchild(i)),build(mid(l, u) + 1, u, rchild(i))); } int query(int l, int u, int i, int uu){ if(laz[i]!=0){ seg[i]+=laz[i]; if(l!=u){ laz[lchild(i)]+=laz[i]; laz[rchild(i)]+=laz[i]; } laz[i] = 0; } if(l>=uu && u<=uu) return seg[i]; if(l>uu || u<uu) return INF; return min(query(l, mid(l, u), lchild(i), uu), query(mid(l, u)+1, u, rchild(i), uu)); } int update(int l, int u, int i, int ll, int uu, int x){ if(laz[i]!=0){ seg[i]+=laz[i]; if(l!=u){ laz[lchild(i)]+=laz[i]; laz[rchild(i)]+=laz[i]; } laz[i] = 0; } if(l>=ll && u<=uu){ seg[i]+=x; if(l!=u){ laz[lchild(i)]+=x; laz[rchild(i)]+=x; } return seg[i]; } if(l>uu || u<ll) return seg[i]; return seg[i] = min(update(l, mid(l, u), lchild(i), ll, uu, x), update(mid(l, u)+1, u, rchild(i), ll, uu, x)); } int toadd(int a, int b){ int tr = 0; if(b>=a){ tr = (b-a)*(-s); } else{ tr = (a-b)*t; } return tr; } int get(int i){ return query(0, n, 0, i); } signed main(){ cin>>n>>q>>s>>t; for(int i = 0;i<=n;i++) cin>>a[i]; int curr = 0; for(int i = 0;i<n;i++){ curr+=toadd(a[i], a[i+1]); } build(0, n, 0); while(q--){ int l, r, x; cin>>l>>r>>x; if(l>0) curr-=(toadd(get(l-1), get(l))); if(r<n) curr-=(toadd(get(r), get(r+1))); update(0, n, 0, l, r, x); if(l>0) curr+=(toadd(get(l-1), get(l))); if(r<n) curr+=(toadd(get(r), get(r+1))); cout<<curr<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...