Submission #524803

#TimeUsernameProblemLanguageResultExecution timeMemory
524803EvangSjeckanje (COCI21_sjeckanje)C++17
110 / 110
356 ms20744 KiB
// press "Read Editorial" on // https://dmoj.ca/problem/coci20c5p5 #include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9; // some random large number const int N = 8e5+5; int n, n2, q, m[N]; ll x[N], a[N], b[N], c[N], d[N]; int sign(ll v){ if(v ==0) return 0; if(v <0) return -1; return 1; } void pull(int i){ a[i] = max({b[2*i]+c[2*i+1], b[2*i]+a[2*i+1], a[2*i]+c[2*i+1]}); b[i] = max({b[2*i]+d[2*i+1], b[2*i]+b[2*i+1], a[2*i]+d[2*i+1]}); c[i] = max({d[2*i]+c[2*i+1], d[2*i]+a[2*i+1], c[2*i]+c[2*i+1]}); d[i] = max({d[2*i]+b[2*i+1], c[2*i]+d[2*i+1], d[2*i]+d[2*i+1]}); if(m[i]+1<n+n2 && sign(x[m[i]]) != sign(x[m[i]+1])) return; a[i] = max(a[i], a[2*i]+a[2*i+1]); b[i] = max(b[i], a[2*i]+b[2*i+1]); c[i] = max(c[i], c[2*i]+a[2*i+1]); d[i] = max(d[i], c[2*i]+b[2*i+1]); } void evan(int i, int l, int r){ if(i>=n) return; m[i] = (l+r)/2; evan(2*i, l, m[i]); evan(2*i+1, m[i]+1, r); } void upd(int i, int v){ x[i] += v; a[i] = abs(x[i]); for(i /= 2; i > 0; i /= 2) pull(i); } void upd(int l, int r, int v){ l += n-1; r += n-1; if(l>n) upd(l-1, -v); if(r<n+n2) upd(r, v); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n2 >> q; if(n2==1){ while(q--) cout << 0 << '\n'; return 0; } --n2; n = 1; while(n<n2) n *= 2; evan(1, n, 2*n-1); for(int i = n; i <= n+n2; ++i) cin >> x[i]; for(int i = n; i < n+n2; ++i) { x[i] -= x[i + 1]; a[i] = abs(x[i]); b[i] = c[i] = -inf; } for(int i = n+n2; i < 2*n; ++i){ x[i] = 0; a[i] = 0; b[i] = c[i] = -inf; } for(int i = n-1; i > 0; --i) pull(i); while(q--){ int l, r, v; cin >> l >> r >> v; upd(l, r, v); cout << max({a[1], b[1], c[1], d[1]}) << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...