Submission #582445

#TimeUsernameProblemLanguageResultExecution timeMemory
582445Shreyan_PaliwalGrowing Trees (BOI11_grow)C++17
100 / 100
111 ms3008 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 100000; int n, q, a[maxn], bit[maxn]; void upd(int l, int r, int k) { if (r < l) return; for (; l < n; l |= l + 1) bit[l] += k; for ( ++r; r < n; r |= r + 1) bit[r] -= k; } int qry(int k) { int ret = 0; for ( ; k >= 0; k &= k + 1, --k) ret += bit[k]; return ret; } template<class T, class U> T firstTrue(T lo, T hi, U f) { // benjamin qi assert(lo <= hi); ++hi; while (lo < hi) { T mid = lo + (hi - lo) / 2; f(mid) ? hi = mid : lo = mid + 1; } return lo; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> q; for (int i = 0; i < n; ++i) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; ++i) upd(i, i, a[i]); for (int i = 0; i < q; ++i) { char c; int a, b; cin >> c >> a >> b; if (c == 'F') { int l = firstTrue(0, n - 1, [&](int i) { return qry(i) >= b; }); if (l == n) continue; int r = l + a - 1; if (r >= n - 1) { upd(l, n - 1, 1); continue; } int k = qry(r); int l_ = firstTrue(l, n - 1, [&](int i) { return qry(i) >= k; }); int r_ = firstTrue(l_, n - 1, [&](int i) { return qry(i) > k; }) - 1; upd(l, l_ - 1, 1); upd(r_ - (a - (l_ - l)) + 1, r_, 1); } else { int l = firstTrue(0, n - 1, [&](int i) { return qry(i) >= a; }); int r = firstTrue(0, n - 1, [&](int i) { return qry(i) > b; }); cout << r - l << '\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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...