Submission #802188

#TimeUsernameProblemLanguageResultExecution timeMemory
802188JohannMizuyokan 2 (JOI23_mizuyokan2)C++14
0 / 100
459 ms2360 KiB
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef vector<ll> vi; typedef vector<vi> vvi; typedef pair<ll, ll> pii; typedef vector<pii> vpii; typedef vector<vpii> vvpii; #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() const int INF = 1e9; int N, Q; vi L; struct segtree { vi arr; int size; void init(int _size) { size = 1; while (size < _size) size *= 2; arr.assign(2 * size, -INF); } void set(int i, ll v) { i += size; while (i > 0) { arr[i] = max(arr[i], v); i /= 2; } } ll query(int l, int r) { return query(l, r, 1, 0, size); } ll query(int l, int r, int x, int lx, int rx) { if (l <= lx && rx <= r) return arr[x]; if (r <= lx || rx <= l) return -INF; int m = (lx + rx) / 2; return max(query(l, r, 2 * x, lx, m), query(l, r, 2 * x + 1, m, rx)); } }; segtree seg; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N; L.resize(N); for (int i = 0; i < N; ++i) cin >> L[i]; cin >> Q; while (Q--) { ll x, y, a, b; cin >> x >> y >> a >> b; --x; L[x] = y; vi B(L.begin() + a, L.begin() + b); vi pref(sz(B)); partial_sum(all(B), pref.begin()); // starting with lower piece seg.init(sz(B)); // seg used as dp // vi dp(sz(B), -INF); // dp[i] := number of zigzag pieces in prefix i with i as minimum vvpii activate(sz(B) + 1); seg.set(0, 1); for (int i = 1; i < sz(B); ++i) { for (pii tmp : activate[i]) seg.set(tmp.first, tmp.second); ll needed; needed = pref[i - 1] - B[i] - 1; pii ac; if (needed < 0) ac = {i, 1}; else { int r = upper_bound(all(pref), pref[i - 1] - B[i] - 1) - pref.begin(); ac = {i, max(0LL, seg.query(0, r)) + 2}; } needed = pref[i] + B[i] + 1; if (needed <= pref.back()) { int idx = lower_bound(all(pref), needed) - pref.begin(); if (idx < sz(activate)) activate[idx].push_back(ac); } } for (pii tmp : activate[sz(B)]) seg.set(tmp.first, tmp.second); ll ans = seg.query(0, seg.size); ll buffer = 0; for (int i = sz(B) - 1; i > 0; --i) { buffer += B[i]; if (buffer > B[i - 1]) ans = max(ans, seg.arr[seg.size + i - 1] + 1); } cout << ans << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...