#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK "task"
#define all(x) x.begin(), x.end()
using namespace std;
const int N = 2e5 + 7;
const int MOD = 1e9 + 7; // 998244353;
const int INF = 1e9 + 7;
const long long INFLL = 1e18 + 7;
typedef long long ll;
template <class X, class Y> bool minimize(X &a, Y b) {
if (a > b) return a = b, true;
return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
if (a < b) return a = b, true;
return false;
}
struct FenwickTree {
vector<ll> bit;
int n;
FenwickTree(int n = 0) {
this->n = n;
bit.resize(n + 7);
}
ll get(int i) {
ll res = 0;
for (; i > 0; i -= i & -i) res += bit[i];
return res;
}
ll getRange(int l, int r) {
if (r > l) return 0;
return get(r) - get(l - 1);
}
void modify(int i, int v) {
for (; i <= n; i += i & -i) bit[i] += v;
}
void modifyRange(int l, int r, int v) {
if (r < l) return;
modify(l, v);
modify(r + 1, -v);
}
} f;
int n, q;
int a[N];
void solve(void) {
cin >> n >> q;
f = FenwickTree(n + 1);
for (int i = 1; i <= n; i ++) cin >> a[i];
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i ++) f.modifyRange(i, i, a[i]);
auto lowerBound = [&](int lo, int hi, int val) -> int {
assert(lo <= hi); hi ++;
while (lo < hi) {
int mid = (lo + hi) >> 1;
if (f.get(mid) >= val) hi = mid;
else
lo = mid + 1;
}
return hi;
};
auto upperBound = [&](int lo, int hi, int val) -> int {
assert(lo <= hi); hi ++;
while (lo < hi) {
int mid = (lo + hi) >> 1;
if (f.get(mid) > val) hi = mid;
else
lo = mid + 1;
}
return hi;
};
while (q --) {
char type; cin >> type;
if (type == 'C') {
int mn, mx; cin >> mn >> mx;
cout << upperBound(1, n, mx) - lowerBound(1, n, mn) << '\n';
} else {
int number, height; cin >> number >> height;
int l = lowerBound(1, n, height);
int r = l + number - 1;
if (r >= n) {
f.modifyRange(1, n, 1);
continue;
}
int val = f.get(r);
int ll = lowerBound(l, n, val);
int rr = upperBound(r, n, val) - 1;
f.modifyRange(l, ll - 1, 1);
f.modifyRange(rr - (number - ll), rr, 1);
}
}
}
int main(void) {
cin.tie(0)->sync_with_stdio(0);
int test = 1;
// cin >> test;
while (test --) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
65 ms |
1380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
50 ms |
656 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
38 ms |
548 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
67 ms |
1100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
58 ms |
1248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
64 ms |
1312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
115 ms |
1388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
78 ms |
1368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
109 ms |
1908 KB |
Output isn't correct |