Submission #711942

#TimeUsernameProblemLanguageResultExecution timeMemory
711942kostia244Fish 2 (JOI22_fish2)C++17
13 / 100
4049 ms4536 KiB
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2") #include<bits/stdc++.h> #define all(x) begin(x), end(x) using namespace std; using ll = long long; const int inf = 1'000'000'003; int main() { cin.tie(0)->sync_with_stdio(0); int n, q; cin >> n; vector<int> a(n); for(auto &i : a) cin >> i; vector<int> die(n + 1); vector<array<int, 3>> useful; auto add = [&](int l, int r) { if(l < r) { die[l]++; die[r]--; } }; auto scan = [&](vector<array<int, 3>> ind, int mode) { vector<array<ll, 3>> st; for(auto [i, ls, rs] : ind) { ll sum = ls; while(st.size() && a[st.back()[0]] < a[i]) { sum += st.back()[1]; sum += a[st.back()[0]]; st.pop_back(); } if(sum < a[i]) { if(mode == 0) {//fwd add(st.empty() ? ind[0][0] : st.back()[0] + 1, i); } else { add(i + 1, st.empty() ? ind[0][0] + 1 : st.back()[0]); } } st.push_back({i, min<ll>(sum, inf)}); } }; cin >> q; for(int t, l, r, i = 0; i < q; i++) { cin >> t >> l >> r; --l; if(t == 1) { a[l] = r; } else { die.assign(n + 1, 0); useful.clear(); for(int i = l; i < r; i++) useful.push_back({i, 0, 0}); scan(useful, 0); reverse(all(useful)); for(auto &[i, ls, rs] : useful) swap(ls, rs); scan(useful, 1); int ans = 0, cur = 0; for(int i = l; i < r; i++) { cur += die[i]; ans += !cur; } 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...