이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 0LL;
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);
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 lo;
};
while (q --) {
char type; cin >> type;
if (type == 'C') {
int mn, mx; cin >> mn >> mx;
cout << lowerBound(1, n, mx + 1) - lowerBound(1, n, mn) << '\n';
} else {
int number, height; cin >> number >> height;
int l = lowerBound(1, n, height);
int r = l + number - 1;
if (l > n) continue;
if (r >= n) {
f.modifyRange(l, n, 1);
continue;
}
int val = f.get(r);
int ll = lowerBound(l, n, val);
int rr = lowerBound(l, n, val + 1) - 1;
f.modifyRange(l, ll - 1, 1);
f.modifyRange(rr - (r - ll), rr, 1);
}
}
}
int main(void) {
cin.tie(0)->sync_with_stdio(0);
int test = 1;
// cin >> test;
while (test --) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |