Submission #113638

#TimeUsernameProblemLanguageResultExecution timeMemory
113638popovicirobertFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
206 ms12308 KiB
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long #define ull unsigned long long // 217 // 44 using namespace std; struct Fenwick { vector <ll> aib; int n; inline void init(int _n) { n = _n; aib.resize(n + 1, 0); } inline void update(int pos, int val) { for(int i = pos; i <= n; i += lsb(i)) { aib[i] += val; } } inline ll query(int pos) { ll ans = 0; for(int i = pos; i > 0; i -= lsb(i)) { ans += aib[i]; } return ans; } }; inline ll get(ll h1, ll h2, int s, int t) { if(h1 < h2) return -1LL * (h2 - h1) * s; return 1LL * (h1 - h2) * t; } int main() { //ifstream cin("A.in"); //ofstream cout("A.out"); int i, n, q, s, t; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> q >> s >> t; ll cur = 0; vector <int> a(n + 2); for(i = 1; i <= n + 1; i++) { cin >> a[i]; if(i > 1) { cur += get(a[i - 1], a[i], s, t); } } Fenwick fen; fen.init(n + 1); while(q > 0) { q--; int l, r, x; cin >> l >> r >> x; l++, r++; if(l > 1) { cur -= get(a[l - 1] + fen.query(l - 1), a[l] + fen.query(l), s, t); } if(r <= n) { cur -= get(a[r] + fen.query(r), a[r + 1] + fen.query(r + 1), s, t); } fen.update(l, x); fen.update(r + 1, -x); if(l >= 1) { cur += get(a[l - 1] + fen.query(l - 1), a[l] + fen.query(l), s, t); } if(r <= n) { cur += get(a[r] + fen.query(r), a[r + 1] + fen.query(r + 1), s, t); } cout << cur << "\n"; } //cin.close(); //cout.close(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...