This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define task ""
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (b), _a = (a); i >= _a; --i)
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
const int dx[] = {-1, 0, 0, +1};
const int dy[] = {0, -1, +1, 0};
const int MAX = 100100;
int n, m;
int h[MAX];
int bit[MAX];
void update(int id, int delta) {
for (; id <= n; id += id & -id)
bit[id] += delta;
}
void update(int l, int r, int delta) {
update(l, +delta);
update(r + 1, -delta);
}
int get(int id) {
int res = 0;
for (; id > 0; id -= id & -id)
res += bit[id];
return res;
}
int getPos(int value) {
int id = 0, curValue = 0;
for (int j = 16; j >= 0; --j) if (id + (1 << j) <= n) {
if (curValue + bit[id + (1 << j)] <= value) {
curValue += bit[id + (1 << j)];
id += (1 << j);
}
}
return id;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> h[i];
}
sort(h + 1, h + 1 + n);
for (int i = 1; i <= n; ++i) {
update(i, i, h[i]);
}
for (int i = 1; i <= m; ++i) {
char op; cin >> op;
if (op == 'C') {
int l, r; cin >> l >> r;
cout << getPos(r) - getPos(l - 1) << '\n';
} else {
int c, h;cin >> c >> h;
int st = getPos(h - 1);
if (st + c >= n) update(st + 1, n, +1);
else {
int lastValue = get(st + c), lt = getPos(lastValue - 1);
if (lt - st <= c) {
update(st + 1, lt, +1);
c -= lt - st;
}
if (c > 0) {
int rt = getPos(lastValue);
update(max(lt + 1, rt - c + 1), rt, +1);
}
}
}
}
return 0;
}
Compilation message (stderr)
grow.cpp: In function 'int main()':
grow.cpp:53:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
grow.cpp:54:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |