Submission #480920

#TimeUsernameProblemLanguageResultExecution timeMemory
480920LoboFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
189 ms6692 KiB
#include <bits/stdc++.h> using namespace std; const long long INFll = (long long) 1e18 + 10; const int INFii = (int) 1e9 + 10; typedef long long ii; typedef int ll; typedef long double dbl; #define endl '\n' #define sc second #define fr first #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() #define maxn 220000 ii n, q, s, t, bit[maxn]; void att(ii pos, ii val) { for(ii i = pos; i <= n && i > 0; i+= i&-i) bit[i]+= val; } ii qrr(ii pos) { ii sum = 0; for(ii i = pos; i > 0; i-= i&-i) sum+= bit[i]; return sum; } int main() { ios::sync_with_stdio(false); cin.tie(0); //freopen("in.in", "r", stdin); //freopen("out.out", "w", stdout); cin >> n >> q >> s >> t; for(ii i = 0; i <= n; i++) { ii a; cin >> a; att(i,a); att(i+1,-a); } ii up = 0; ii dw = 0; for(ii i = 1; i <= n; i++) { ii l1 = qrr(i-1); ii l2 = qrr(i); if(l1 < l2) { up+= abs(l1-l2); } else { dw+= abs(l1-l2); } } while(q--) { ii l, r, x; cin >> l >> r >> x; ii l1 = qrr(l-1); ii l2 = qrr(l); if(l1 < l2) { up-= abs(l1-l2); } else { dw-= abs(l1-l2); } ii r1 = qrr(r); ii r2 = qrr(r+1); if(r1 < r2 && r != n) { up-= abs(r1-r2); } else if(r != n) { dw-= abs(r1-r2); } att(l,x); att(r+1,-x); l1 = qrr(l-1); l2 = qrr(l); if(l1 < l2) { up+= abs(l1-l2); } else { dw+= abs(l1-l2); } r1 = qrr(r); r2 = qrr(r+1); if(r1 < r2 && r != n) { up+= abs(r1-r2); } else if(r != n) { dw+= abs(r1-r2); } cout << dw*t - up*s << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...