제출 #29362

#제출 시각아이디문제언어결과실행 시간메모리
29362cdemirerFoehn Phenomena (JOI17_foehn_phenomena)C++14
0 / 100
23 ms11152 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<vector<int> > vvi; typedef vector<pair<int, int> > vii; typedef vector<vector<pair<int, int> > > vvii; #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) int N, Q, S, T; int A[200001]; ll res = 0; typedef struct Node_ { int llim, rlim; ll update; } Node; const int segsz = 524288; Node seg[segsz]; int offset = segsz/2; ll get(int x) { x += offset; ll ret = 0; while (x > 0) { ret += seg[x].update; x /= 2; } return ret; } void _update(int x, int l, int r, int dy) { int llim = seg[x].llim; int rlim = seg[x].rlim; int mid = (llim + rlim) / 2; if (l == llim && r == rlim) seg[x].update += dy; else if (l > mid) _update(2*x+1, l, r, dy); else if (r <= mid) _update(2*x, l, r, dy); else { _update(2*x, l, mid, dy); _update(2*x+1, mid+1, r, dy); } } void update(int l, int r, int dy) { _update(1, l, r, dy); } int main(int argc, char **argv) { //freopen("input", "r", stdin); //freopen("output", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cin >> N >> Q >> S >> T; for (int i = offset; i < segsz; i++) { seg[i].llim = seg[i].rlim = i - offset; seg[i].update = 0; } for (int i = offset-1; i > 0; i--) { seg[i].llim = seg[2*i].llim; seg[i].rlim = seg[2*i+1].rlim; seg[i].update = 0; } for (int i = 0; i < N+1; i++) { cin >> A[i]; seg[i+offset].update = A[i]; } for (int i = 1; i < N+1; i++) { if (A[i] == A[i-1]) continue; if (A[i] > A[i-1]) res -= S*(A[i]-A[i-1]); else res += T*(A[i-1]-A[i]); } for (int i = 0; i < Q; i++) { int l, r, dy; cin >> l >> r >> dy; ll a = get(l-1), b = get(l), c = get(r); ll d = (r+1<=N?get(r+1):c); ll old_effect = (a>b?T*(a-b):-S*(b-a)) + (c>d?T*(c-d):-S*(d-c)); update(l, r, dy); b += dy; c += dy; if (r+1>N) d = c; ll new_effect = (a>b?T*(a-b):-S*(b-a)) + (c>d?T*(c-d):-S*(d-c)); res += new_effect - old_effect; cout << res << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...