#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') {
// y이상인 것 중 최대 x개 +=1
const int it = bit.lower_bound(y);
bit.update(it, 1);
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);
// x개 update 해야 하는데
// (lo - it)개만 update
// 남은 개수 x - (lo - it)
bit.update(hi - (x - (lo - it)), 1);
bit.update(hi, -1);
}
} else {
// [x, y] 개수 세기
cout << bit.upper_bound(y) - bit.lower_bound(x) << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
16 ms |
1824 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 |
1 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 |
2 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
1484 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
1572 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
12 ms |
1680 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
1124 KB |
Output is correct |
2 |
Runtime error |
19 ms |
2148 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
16 ms |
1812 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
1588 KB |
Output is correct |