Submission #1030248

#TimeUsernameProblemLanguageResultExecution timeMemory
1030248ArthuroWichGrowing Trees (BOI11_grow)C++17
100 / 100
596 ms8396 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int #pragma GCC optimize("O3") #pragma GCC target("avx2") int arr[100005], seg[4*100005], lazy[4*100005]; void lazypropagate(int n, int l, int r) { if (lazy[n]) { seg[n] += lazy[n]; if (l != r) { lazy[2*n] += lazy[n]; lazy[2*n+1] += lazy[n]; } lazy[n] = 0; } } void build(int n, int l, int r) { if (l == r) { seg[n] = arr[l]; } else { int m = (l+r)/2; build(2*n, l, m); build(2*n+1, m+1, r); seg[n] = max(seg[2*n], seg[2*n+1]); } } void update(int n, int l, int r, int a, int b, int v) { lazypropagate(n, l, r); if (b < l || r < a) { return; } else if (a <= l && r <= b) { lazy[n] = v; lazypropagate(n, l, r); } else { int m = (l+r)/2; update(2*n, l, m, a, b, v); update(2*n+1, m+1, r, a, b, v); seg[n] = max(seg[2*n], seg[2*n+1]); } } int query(int n, int l, int r, int a, int b) { if (b < l || r < a) { return 0; } lazypropagate(n, l, r); if (a <= l && r <= b) { return seg[n]; } else { int m = (l+r)/2; return max(query(2*n, l, m, a, b), query(2*n+1, m+1, r, a, b)); } } int search(int n, int h) { int l = 0, r = n-1; while(l < r) { int m = (l+r)/2, v; v = query(1, 0, n-1, m, m); if (v >= h) { r = m; } else { l = m+1; } } if (query(1, 0, n-1, l, l) < h) { return n; } return l; } void solve() { int n, m; cin >> n >> m; vector<int> a(n); for (int &x : a) { cin >> x; } sort(a.begin(), a.end()); for (int i = 0; i < n; i++) { arr[i] = a[i]; } build(1, 0, n-1); while(m--) { char ch; cin >> ch; if (ch == 'F') { int c, h, ind1, ind2, ind3, hm; cin >> c >> h; ind1 = search(n, h); if (ind1 == n) { continue; } if (ind1+c >= n) { update(1, 0, n-1, ind1, n-1, 1); continue; } hm = query(1, 0, n-1, ind1+c-1, ind1+c-1); ind2 = search(n, hm); if (ind1 == ind2) { ind3 = search(n, hm+1); update(1, 0, n-1, ind3-c, ind3-1, 1); continue; } update(1, 0, n-1, ind1, ind2-1, 1); c -= ind2-ind1; ind3 = search(n, hm+1); update(1, 0, n-1, ind3-c, ind3-1, 1); } else { int mn, mx; cin >> mn >> mx; cout << search(n, mx+1)-search(n, mn) << "\n"; } } } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int t; t = 1; while(t--) { solve(); } }
#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...