#include <bits/stdc++.h>
using namespace std;
#define sp << " " <<
#define int long long
#define vi vector<int>
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
const int N = 1e5+1;
vi a(N,0),bit(N,0);
int n;
void add(int p,int v) {
for (int i=p;i<=n;i+=i&-i) bit[i]+=v;
}
int get(int p) {
int ans = 0;
for (int i=p;i>0;i-=i&-i) ans+=bit[i];
return ans;
}
void solve() {
int q;
cin >> n >> q;
F(i,n) cin >> a[i];
sort(a.begin()+1,a.begin()+n+1);
while (q--) {
char cc;
cin >> cc;
if (cc == 'F') {
int c,h;
cin >> c >> h;
int l = 1;
int r = n;
while (l<=r) {
int m = (l+r) >> 1;
if (get(m)+a[m] >= h) r = m-1;
else l = m+1;
}
int L = l;
int R = L+c-1;
if (R >= n) {
add(l,1);
continue;
}
l = R;
r = n;
while (l<=r) {
int m = (l+r) >> 1;
if (get(m)+a[m] <= a[R]) l = m+1;
else r = m-1;
}
int lastp = r;
l = L;
r = R;
while (l<=r) {
int m = (l+r) >> 1;
if (a[m]+get(m) < a[R]) l = m+1;
else r = m-1;
}
int used= r-L+1;
int rem = c-used;
add(L,1);
add(L+used,-1);
add(max(L,lastp-rem+1),1);
add(lastp+1,-1);
}
else {
int l,r;
cin >> l >> r;
int l2 = 1;
int r2 = n;
while (l2<=r2) {
int m = (l2+r2) >> 1;
if (a[m]+get(m) >= l) r2 = m-1;
else l2 = m+1;
}
int firs = l2;
l2 = 1;
r2 = n;
while (l2<=r2) {
int m = (l2+r2) >> 1;
if (a[m]+get(m) <= r) l2 = m+1;
else r2 = m-1;
}
int lst = r2;
cout << lst-firs+1 << '\n';
}
}
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
int t = 1;
//cin >> t;
F(i,t) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
40 ms |
3156 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1884 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
3032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
3156 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
39 ms |
3084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
48 ms |
2892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
3084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
83 ms |
3556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
50 ms |
3416 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
84 ms |
4396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |