제출 #1109300

#제출 시각아이디문제언어결과실행 시간메모리
1109300mariaclaraFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
280 ms24924 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef tuple<ll,ll,ll> trio; typedef pair<int,int> pii; const int MAXN = 2e5+5; const ll INF = 1e9; #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define mk make_pair #define pb push_back #define fr first #define sc second int n, q, s, t, a[MAXN]; ll ans, seg[4*MAXN], lazy[4*MAXN], dif[MAXN]; void build(int node, int l, int r) { if(l == r) { seg[node] = a[l]; return; } int mid = (l+r)/2; build(2*node, l, mid); build(2*node+1, mid+1, r); } void prop(int node, int flag) { seg[node] += lazy[node]; if(!flag) { lazy[2*node] += lazy[node]; lazy[2*node+1] += lazy[node]; } lazy[node] = 0; } void update(int node, int l, int r, int p, int q, int x) { prop(node, l==r); if(r < p or q < l) return; if(p <= l and r <= q) { lazy[node] = x; prop(node, l==r); return; } int mid = (l+r)/2; update(2*node, l, mid, p, q, x); update(2*node+1, mid+1, r, p, q, x); } ll query(int node, int l, int r, int ind) { prop(node, l == r); if(ind == 0) return 0; if(l == r) return seg[node]; int mid = (l+r)/2; if(ind <= mid) return query(2*node, l, mid, ind); else return query(2*node+1, mid+1, r, ind); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> q >> s >> t; for(int i = 0; i <= n; i++) { cin >> a[i]; if(i == 0) continue; if(a[i] > a[i-1]) dif[i] = (ll)(a[i-1] - a[i]) * s; else dif[i] = (ll)(a[i-1] - a[i]) * t; ans += dif[i]; } build(1, 1, n); while(q--) { int L, R, X; cin >> L >> R >> X; update(1, 1, n, L, R, X); ans -= dif[L]; dif[L] = query(1, 1, n, L-1) - query(1, 1, n, L); if(dif[L] < 0) dif[L] *= s; else dif[L] *= t; ans += dif[L]; ans -= dif[R+1]; dif[R+1] = query(1, 1, n, R) - query(1, 1, n, min(R+1, n)); if(dif[R+1] < 0) dif[R+1] *= s; else dif[R+1] *= t; ans += dif[R+1]; cout << ans << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...