이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* Author: goats_9 */
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define LSOne(s) (s & -(s))
class BIT {
int n;
vector<ll> values;
public:
BIT(int _n) : n(_n), values(n + 1, 0LL) {}
void update(int l, int r, int v) {
if (r <= l) return;
for (; l <= n; l += LSOne(l)) values[l] += v;
for (; r <= n; r += LSOne(r)) values[r] -= v;
}
ll query(int i) {
if (i > n) return -1;
ll ret = 0;
for (; i; i -= LSOne(i)) ret += values[i];
return ret;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
BIT ft(n);
for (int i = 0; i < n; i++) ft.update(i + 1, i + 2, a[i]);
while (q--) {
char op;
cin >> op;
if (op == 'F') {
int c, h;
cin >> c >> h;
int l = 0, r = n + 1;
while (r - l > 1) {
int g = (l + r) / 2;
if (ft.query(g) >= h) r = g;
else l = g;
}
if (r > n) continue;
if (r + c > n) {
ft.update(r, r + c, 1);
continue;
}
int u = ft.query(r + c - 1);
int lt = r;
l = 0, r = n + 1;
while (r - l > 1) {
int g = (l + r) / 2;
if (ft.query(g) >= u) r = g;
else l = g;
}
int l1 = r;
l = 0, r = n + 1;
while (r - l > 1) {
int g = (l + r) / 2;
if (ft.query(g) <= u) l = g;
else r = g;
}
ft.update(lt, l1, 1);
ft.update(r - c + (l1 - lt), r, 1);
} else {
int m, M;
cin >> m >> M;
int l = 0, r = n + 1;
while (r - l > 1) {
int g = (l + r) / 2;
if (ft.query(g) >= m) r = g;
else l = g;
}
int lt = l;
l = 0, r = n + 1;
while (r - l > 1) {
int g = (l + r) / 2;
if (ft.query(g) > M) r = g;
else l = g;
}
cout << l - lt << '\n';
}
}
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... |