제출 #1304463

#제출 시각아이디문제언어결과실행 시간메모리
1304463polishprogrammerFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
454 ms9948 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define fi first #define se second #define lld long double int n, wie; vector<ll> tree; int tree_size(int x) { int wynik = 1; while (wynik < x) wynik *= 2; return wynik * 2; } void update(int i, ll x) { i += wie / 2; tree[i] += x; while (i > 1) { i /= 2; tree[i] = tree[2 * i] + tree[2 * i + 1]; } } ll query(int l, int r) { l += wie / 2; r += wie / 2; ll res = 0; while (l <= r) { if (l % 2 == 1) res += tree[l++]; if (r % 2 == 0) res += tree[r--]; l /= 2; r /= 2; } return res; } void ctree() { cout << "drzewo" << endl; for (int poz = 0; (1 << (poz + 1)) <= wie; poz++) { for (int j = (1 << poz); j < (1 << (poz + 1)); j++) { cout << tree[j] << " "; } cout << endl; } cout << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll q, s, t, ilet = 0, iles = 0; cin >> n >> q >> s >> t; wie = tree_size(n + 1); tree.resize(wie, 0); vector<ll> arr(n + 1); cin >> arr[0]; for (int i = 1; i <= n; i++) { cin >> arr[i]; if (arr[i] > arr[i - 1]) iles += arr[i] - arr[i - 1]; else ilet += arr[i - 1] - arr[i]; } ll l, r, x, a, b; while (q--) { cin >> l >> r >> x; a = query(0, l - 1) + arr[l - 1]; b = query(0, l) + arr[l]; if (b > a) iles -= b - a; else ilet -= a - b; if (b + x > a) iles += b + x - a; else ilet += a - b - x; if (r + 1 <= n) { a = query(0, r) + arr[r]; b = query(0, r + 1) + arr[r + 1]; if (b > a) iles -= b - a; else ilet -= a - b; if (b > a + x) iles += b - x - a; else ilet += a - b + x; update(r + 1, -x); } update(l, x); cout << ilet * t - iles * s << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...