#include <bits/stdc++.h>
using namespace std;
template <typename T>
class BIT {
const int n;
vector<T> tree;
public:
BIT(int _n) : n(_n), tree(n + 1) {}
void update(int i, T val) {
assert(0 <= i and i <= n);
for (++i; i <= n; i += i & -i)
tree[i] += val;
}
T query(int i) {
assert(0 <= i and i <= n);
T ret = 0;
for (; i; i &= i - 1)
ret += tree[i];
return ret;
}
T query(int l, int r) {
assert(0 <= l and l <= r and r <= n);
return query(r) - query(l);
}
T get(int i) {
assert(0 <= i and i < n);
return i & 1 ? query(i, i + 1) : tree[i + 1];
}
int lower_bound(T k) {
if (k <= 0) return -1;
int x = 0;
for (int pw = 1 << __lg(n); pw; pw >>= 1)
if ((x | pw) <= n && tree[x | pw] < k)
k -= tree[x |= pw];
return x;
}
int upper_bound(T k) {
if (k < 0) return -1;
int x = 0;
for (int pw = 1 << __lg(n); pw; pw >>= 1)
if ((x | pw) <= n && tree[x | pw] <= k)
k -= tree[x |= pw];
return x;
}
};
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
#ifdef palilo
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
int n, m;
cin >> n >> m;
vector<int> a(n);
for (auto& x : a) cin >> x;
sort(a.begin(), a.end());
BIT<int> bit(n);
for (int i = 0; i < n; ++i)
bit.update(i, a[i] - (i ? a[i - 1] : 0));
for (int x, y; m--;) {
char op;
cin >> op >> x >> y;
if (op == 'F') {
const int it = bit.lower_bound(y);
if (it + x < n) {
const int last_value = bit.query(it + x);
const int lo = bit.lower_bound(last_value);
const int hi = bit.upper_bound(last_value);
bit.update(lo, -1);
bit.update(hi - (x - (lo - it)), 1);
bit.update(hi, -1);
}
bit.update(it, 1);
} else {
cout << bit.upper_bound(y) - bit.lower_bound(x) << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
18 ms |
1776 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
12 ms |
1484 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
14 ms |
1640 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
1740 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
1036 KB |
Output is correct |
2 |
Runtime error |
16 ms |
1644 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
1808 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
1596 KB |
Output is correct |