제출 #129302

#제출 시각아이디문제언어결과실행 시간메모리
129302trinhhungFoehn Phenomena (JOI17_foehn_phenomena)C++14
0 / 100
1069 ms1424 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, ans, s, t, q; int a[N], node[4 * N], p[N]; bool f[N]; void build_tree(int i, int l, int r){ if(l > r) return; if(l == r){ p[i] = node[i] = a[l - 1] - a[l]; if(node[i] < 0) node[i] *= t; else node[i] *= s; return; } int mid = (l + r) / 2; build_tree(i * 2, l, mid); build_tree(i * 2 + 1, mid + 1, r); node[i] = node[i * 2] + node[i * 2 + 1]; //node[i].t = node[i * 2].t + node[i * 2 + 1].t; //node[i].s = node[i * 2].s + node[i * 2 + 1].s; } void update_2(int i, int l, int r, int pos, int val){ if(l > r || l > pos || r < pos) return; if(l == r){ if(l == pos) { p[i] -= val; if(p[i] < 0) node[i] = p[i] * t; else node[i] = p[i] * s; } return; } int mid = (l + r) / 2; update_2(i * 2, l, mid, pos, val); update_2(i * 2 + 1, mid + 1, r, pos, val); node[i] = node[i * 2] + node[i * 2 + 1]; } void update(int i, int l, int r, int pos, int val){ if(l > r || l > pos || r < pos) return; if(l == r){ if(l == pos) { p[i] += val; if(p[i] < 0) node[i] = p[i] * t; else node[i] = p[i] * s; } return; } int mid = (l + r) / 2; update(i * 2, l, mid, pos, val); update(i * 2 + 1, mid + 1, r, pos, val); node[i] = node[i * 2] + node[i * 2 + 1]; } signed main(){ //ios_base::sync_with_stdio(false); //cin.tie(nullptr); //freopen("ANTS.INP", "r", stdin); //freopen("ANTS.OUT", "w", stdout); cin >> n >> q >> t >> s; for(int i = 0; i <= n; ++ i) cin >> a[i]; build_tree(1, 1, n); while(q --){ int l, r, x; cin >> l >> r >> x; update_2(1, 1, n, l, x); if(r < n) update(1, 1, n, r + 1, x); cout << node[1] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...