| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1355855 | waygonz | Growing Trees (BOI11_grow) | C++20 | 63 ms | 1716 KiB |
#include <bits/stdc++.h>
using namespace std;
struct FenwickTree {
int N;
vector<int> fw;
void update(int x, int v) {
if (x <= 0) return;
while (x <= N) fw[x] += v, x += x & -x;
}
void range_update(int l, int r, int v) {
if (r < l) return;
update(l, v);
update(r+1, -v);
}
int query(int x) {
int res = 0;
while (x > 0) res += fw[x], x -= x & -x;
return res;
}
int low(int x) {
int l = 1, r = N+1;
while (l < r) {
int mid = (l + r) / 2;
if (query(mid) >= x) r = mid;
else l = mid + 1;
}
return l;
}
int high(int x) {
int l = 0, r = N;
while (l < r) {
int mid = (l + r + 1) / 2;
if (query(mid) <= x) l = mid;
else r = mid - 1;
}
return l;
}
} T;
int n, m;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
T.N = n, T.fw.resize(n+1);
vector<int> a(n+1);
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a.begin() + 1, a.end());
for (int i = 1; i <= n; i++) T.range_update(i, i, a[i]);
while (m--) {
char t; cin >> t;
if (t == 'F') {
int c, h;
cin >> c >> h;
int l = T.low(h), r = min(n, l + c - 1);
if (r < l) continue;
int x = T.query(r);
int ll = T.low(x), rr = T.high(x);
T.range_update(l, ll-1, 1);
T.range_update(rr - r + ll, rr, 1);
} else {
int l, r;
cin >> l >> r;
cout << max(0, T.high(r) - T.low(l) + 1) << '\n';
}
}
}| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
