This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
VI BIT;
void add(int i, int s) {
while (i < BIT.size()) BIT[i] += s, i += i&-i;
}
void add(int l, int r, int s) {
add(l, s);
if (r+1 < BIT.size()) add(r+1, -s);
}
int get(int i) {
int ret = 0;
while (i > 0) ret += BIT[i], i -= i&-i;
return ret;
}
int ubound(int x) {
int l = 0, r = BIT.size();
while (l + 1 < r) {
int m = (l + r) / 2;
if (get(m) > x) r = m;
else l = m;
}
return r;
}
int lbound(int x) {
int l = 0, r = BIT.size();
while (l + 1 < r) {
int m = (l + r) / 2;
if (get(m) >= x) r = m;
else l = m;
}
return r;
}
int answer(int L, int R) {
return ubound(R)-lbound(L);
}
void solve() {
int n, q;
cin >> n >> q;
VI a(n);
for (int& x : a) cin >> x;
sort(all(a));
BIT = VI(n+1);
rep(i, n) add(i+1, i+1, a[i]);
while (q--) {
char t;
cin >> t;
if (t == 'C') {
int l, r;
cin >> l >> r;
cout << answer(l, r) << endl;
} else {
int c, h;
cin >> c >> h;
int l = lbound(h);
if (l+c-1 > n) add(l, n, +1);
else {
int r = lbound(get(l+c-1))-1;
add(l, r, +1);
int cnt = l+c-1-r;
r = ubound(get(l+c-1))-1;
l = r - cnt + 1;
add(l, r, +1);
}
/* replr(i, 1, n) cout << get(i) << " "; */
/* cout << endl; */
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1;
/* cin >> t; */
while (t--) solve();
}
Compilation message (stderr)
grow.cpp: In function 'void add(int, int)':
grow.cpp:35:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | while (i < BIT.size()) BIT[i] += s, i += i&-i;
| ~~^~~~~~~~~~~~
grow.cpp: In function 'void add(int, int, int)':
grow.cpp:39:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if (r+1 < BIT.size()) add(r+1, -s);
| ~~~~^~~~~~~~~~~~
# | 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... |