#include <bits/stdc++.h>
using namespace std;
inline namespace
{
template <typename T>
struct PURS
{
PURS(int _n) : n(_n), tree(n + 1, 0) {}
void add(int p, T t)
{
for (p++; p <= n; p += p & -p)
tree[p] += t;
}
T sum(int l, int r)
{
T ret = 0;
for (; r; r -= r & -r)
ret += tree[r];
for (; l; l -= l & -l)
ret -= tree[l];
return ret;
}
T sum(int l = 0) { return sum(l, n); }
private:
int n;
vector<int> tree;
};
} // namespace
void solve()
{
int n, m;
cin >> n >> m;
vector<long> a(n);
for (long &x : a)
cin >> x;
sort(a.begin(), a.end());
PURS<long> purs(n);
auto add_height = [&](int l, int r, long x) -> void
{
purs.add(l, x);
purs.add(r, -x);
};
auto get_height = [&](int p) -> long
{ return purs.sum(0, p + 1); };
for (int i = 0; i < n; i++)
add_height(i, i + 1, a[i]);
for (int z = 0; z < m; z++)
{
char t;
cin >> t;
if (t == 'F')
{
int c;
long h;
cin >> c >> h;
int p = n, lo = 0;
while (lo < p)
{
int mid = (lo + p) / 2;
if (get_height(mid) >= h)
p = mid;
else
lo = mid + 1;
}
if (p + c < n)
{
long y = get_height(p + c - 1);
int i = n, j = p, lo = p, hi = n;
while (lo < i)
{
int mid = (lo + i) / 2;
if (get_height(mid) >= y)
i = mid;
else
lo = mid + 1;
}
while (j < hi)
{
int mid = (j + hi) / 2;
if (get_height(mid) <= y)
j = mid + 1;
else
hi = mid;
}
add_height(p, i, 1);
add_height(j - c + i - p, j, 1);
}
else
add_height(p, n, 1);
}
else if (t == 'C')
{
long x, y;
cin >> x >> y;
int l = n, r = 0, lo = 0, hi = n;
while (lo < l)
{
int mid = (lo + l) / 2;
if (get_height(mid) >= x)
l = mid;
else
lo = mid + 1;
}
while (r < hi)
{
int mid = (r + hi) / 2;
if (get_height(mid) <= y)
r = mid + 1;
else
hi = mid;
}
cout << r - l << '\n';
}
}
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(NULL);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
2728 KB |
Output is correct |
2 |
Correct |
96 ms |
3028 KB |
Output is correct |
3 |
Correct |
42 ms |
2892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
44 ms |
1436 KB |
Output is correct |
6 |
Correct |
54 ms |
1616 KB |
Output is correct |
7 |
Correct |
4 ms |
340 KB |
Output is correct |
8 |
Correct |
31 ms |
1128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
1588 KB |
Output is correct |
2 |
Correct |
54 ms |
1692 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
38 ms |
1288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
1896 KB |
Output is correct |
2 |
Correct |
62 ms |
1712 KB |
Output is correct |
3 |
Correct |
7 ms |
468 KB |
Output is correct |
4 |
Correct |
59 ms |
1784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
2192 KB |
Output is correct |
2 |
Correct |
89 ms |
2536 KB |
Output is correct |
3 |
Correct |
16 ms |
872 KB |
Output is correct |
4 |
Correct |
42 ms |
2556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
2300 KB |
Output is correct |
2 |
Correct |
93 ms |
2656 KB |
Output is correct |
3 |
Correct |
45 ms |
2764 KB |
Output is correct |
4 |
Correct |
17 ms |
844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
2388 KB |
Output is correct |
2 |
Correct |
76 ms |
2628 KB |
Output is correct |
3 |
Correct |
45 ms |
2892 KB |
Output is correct |
4 |
Correct |
16 ms |
844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
3040 KB |
Output is correct |
2 |
Correct |
93 ms |
2560 KB |
Output is correct |
3 |
Correct |
30 ms |
2320 KB |
Output is correct |
4 |
Correct |
78 ms |
2552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
2852 KB |
Output is correct |
2 |
Correct |
100 ms |
3012 KB |
Output is correct |
3 |
Correct |
113 ms |
3260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
3788 KB |
Output is correct |