Submission #1114908

#TimeUsernameProblemLanguageResultExecution timeMemory
1114908vladiliusGrowing Trees (BOI11_grow)C++17
100 / 100
105 ms6292 KiB
#include <bits/stdc++.h> using namespace std; const int msz = 1e5 + 5; vector<int> t(4 * msz), p(4 * msz, 0), a(msz); int n; void merge(int v){ int vv = 2 * v; t[v] = max(t[vv], t[vv + 1]); } void push(int v, int tl, int tr){ if (tl == tr || !p[v]){ return; } int vv = 2 * v; t[vv] += p[v]; t[vv + 1] += p[v]; p[vv] += p[v]; p[vv + 1] += p[v]; p[v] = 0; } void build(int v, int tl, int tr){ if (tl == tr){ t[v] = a[tl]; return; } int tm = (tl + tr) / 2, vv = 2 * v; build(vv, tl, tm); build(vv + 1, tm + 1, tr); merge(v); } void add(int v, int tl, int tr, int l, int r){ if (l > tr || r < tl || tl > tr){ return; } if (l <= tl && tr <= r){ t[v]++; p[v]++; return; } push(v, tl, tr); int tm = (tl + tr) / 2, vv = 2 * v; add(vv, tl, tm, l, r); add(vv + 1, tm + 1, tr, l, r); merge(v); } int find(int v, int tl, int tr, int val){ if (tl == tr){ if (t[v] >= val){ return tl; } return n + 1; } push(v, tl, tr); int tm = (tl + tr) / 2, vv = 2 * v; if (t[vv] >= val){ return find(vv, tl, tm, val); } return find(vv + 1, tm + 1, tr, val); } int get(int v, int tl, int tr, int pos){ if (tl == tr){ return t[v]; } push(v, tl, tr); int tm = (tl + tr) / 2, vv = 2 * v; if (pos <= tm){ return get(vv, tl, tm, pos); } return get(vv + 1, tm + 1, tr, pos); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int m; cin>>n>>m; for (int i = 1; i <= n; i++){ cin>>a[i]; } sort(a.begin() + 1, a.begin() + n + 1); build(1, 1, n); while (m--){ char type; int x, y; cin>>type>>x>>y; if (type == 'F'){ if (t[1] < y){ continue; } int l = find(1, 1, n, y), r = min(n, l + x - 1); if (r == n){ add(1, 1, n, l, n); continue; } int ar = get(1, 1, n, r + 1); int j = find(1, 1, n, ar), rp = find(1, 1, n, ar + 1) - 1; add(1, 1, n, l, j - 1); add(1, 1, n, rp + j - x - l + 1, rp); } else { int l = find(1, 1, n, x), r = find(1, 1, n, y + 1); 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...