Submission #834771

#TimeUsernameProblemLanguageResultExecution timeMemory
834771mat_jurGrowing Trees (BOI11_grow)C++17
0 / 100
125 ms3240 KiB
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << "," << p.second << ")"; return o;} auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";for(auto e:x)o<< e << ", ";return o<<"}";} #define debug(X) cerr << "["#X"]:" << X << '\n'; #else #define debug(X) ; #endif #define ll long long #define all(x) (x).begin(), (x).end() int main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(all(a)); int base = 1; while (base < n) base *= 2; struct Node { int mx, lazy; Node() { mx = lazy = 0; } }; vector<Node> tree(2*base); for (int i = 0; i < n; i++) { tree[base+i].mx = a[i]; } for (int i = base-1; i >= 1; i--) { tree[i].mx = max(tree[2*i].mx, tree[2*i+1].mx); } auto push_to_sons = [&](int v) { if (tree[v].lazy == 0) return; int x = tree[v].lazy; tree[2*v].mx += x; tree[2*v+1].mx += x; tree[2*v].lazy += x; tree[2*v+1].lazy += x; tree[v].lazy = 0; }; function<void(int, int, int, int, int, int)> update = [&](int l, int r, int x, int v, int a, int b) { if (r < a || b < l) return; if (l <= a && b <= r) { tree[v].mx += x; tree[v].lazy += x; return; } push_to_sons(v); int mid = (a+b)/2; update(l, r, x, 2*v, a, mid); update(l, r, x, 2*v+1, mid+1, b); tree[v].mx = max(tree[2*v].mx, tree[2*v+1].mx); }; function<int(int, int, int, int)> find = [&](int x, int v, int a, int b) { if (tree[v].mx < x) return -1; if (a == b) return a; push_to_sons(v); int mid = (a+b)/2; int y = find(x, 2*v, a, mid); if (y != -1) return y; return find(x, 2*v+1, mid+1, b); }; function<int(int, int, int, int)> val = [&](int x, int v, int a, int b) { if (a == b) return tree[v].mx; push_to_sons(v); int mid = (a+b)/2; if (x <= mid) return val(x, 2*v, a, mid); else return val(x, 2*v+1, mid+1, b); }; while (m--) { char c; cin >> c; if (c == 'F') { int c, h; cin >> c >> h; int idx = find(h, 1, 0, base-1); if (idx == -1) continue; int fi = find(val(idx+c-1, 1, 0, base-1), 1, 0, base-1); int last = find(val(idx+c-1, 1, 0, base-1)+1, 1, 0, base-1)-1; if (idx != fi) { update(idx, fi-1, 1, 1, 0, base-1); update(last-(c-(fi-idx))+1, last, 1, 1, 0, base-1); } else { update(idx, idx+c-1, 1, 1, 0, base-1); } } else { int minn, maxx; cin >> minn >> maxx; int low = find(minn, 1, 0, base-1), up = find(maxx+1, 1, 0, base-1); if (low == -1) {cout << 0 << '\n'; continue;} if (up == -1) {cout << n-low << '\n'; continue;} up--; cout << up-low+1 << '\n'; } } return 0; }
#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...