Submission #587031

#TimeUsernameProblemLanguageResultExecution timeMemory
5870318e7Fish 2 (JOI22_fish2)C++17
25 / 100
4075 ms4888 KiB
//Challenge: Accepted #include <bits/stdc++.h> using namespace std; #ifdef zisk void debug(){cout << endl;} template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r) { while (l != r) cout << *l << " ", l++; cout << endl; } #else #define debug(...) 0 #define pary(...) 0 #endif #define ll long long #define maxn 100005 #define pii pair<int, int> #define ff first #define ss second #define io ios_base::sync_with_stdio(0);cin.tie(0); int a[maxn], b[maxn], lef[maxn], rig[maxn]; int lc[maxn], rc[maxn], cnt[maxn]; ll pref[maxn]; void dfs(int n, int par) { if (lc[n] != -1) dfs(lc[n], n); if (rc[n] != -1) dfs(rc[n], n); ll sum = pref[rig[n]] - (lef[n] ? pref[lef[n]-1] : 0); if (sum >= b[par]) cnt[n] = 1 + cnt[lc[n]] + cnt[rc[n]]; else cnt[n] = 0; } int main() { io int n, q; cin >> n; for (int i = 1;i <= n;i++) cin >> a[i]; cin >> q; while (q--) { int type; cin >> type; if (type == 1) { int x, y; cin >> x >> y; a[x] = y; } else { int l, r; cin >> l >> r; int s = r - l + 1; for (int i = l;i <= r;i++) b[i-l] = a[i]; for (int i = 0;i < s;i++) { pref[i] = b[i] + (i ? pref[i-1] : 0); cnt[i] = 0; rig[i] = s-1; lef[i] = 0; lc[i] = rc[i] = -1; } stack<int> stk; for (int i = 0;i < s;i++) { while (stk.size() && b[i] >= b[stk.top()]) { lc[i] = stk.top(); rig[stk.top()] = i-1; stk.pop(); } if (stk.size()) { rc[stk.top()] = i; lef[i] = stk.top()+1; } stk.push(i); } while (stk.size() > 1) stk.pop(); int root = stk.top(); dfs(root, root); cout << cnt[root] << "\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...