#include <bits/stdc++.h>
#define z exit(0)
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;
pair<int,int> to_upd[2];
ll bit[N], a[N];
void upd(int i, ll v){ for(; i<N; i+=i&-i) bit[i] += v;}
int qry(int i){ ll r = 0; for(; i; i-=i&-i) r += bit[i]; return r;}
void UPD(int l, int r){ upd(l, +1); upd(r+1, -1);}
ll A(int i){ return a[i] + qry(i);}
signed main(){
int n, q; scanf("%d %d", &n, &q);
for(int i = 1; i<=n; ++i) scanf("%lld", a+i);
sort(a+1, a+1+n);
for(int i = 0, c, h, l, r, L, R, sz; i<q; ++i){
char op; scanf(" %c", &op);
if(op == 'F'){
scanf("%d %d", &c, &h);
int low = 1, high = n, st = n+1, ed = -1;
while(low <= high){
int mid = low + ((high-low)>>1);
if(A(mid) >= h) high = mid-1, st = mid;
else low = mid+1;
}
if(st > n) continue;
ed = min(n, st+c-1);
ll val = A(ed);
low = 1; high = ed; l = n+1; r = -1;
while(low <= high){
int mid = low + ((high-low)>>1);
if(A(mid) < val) low = mid+1;
else if(A(mid) == val) high = mid-1, l = mid;
}
low = ed; high = n;
while(low <= high){
int mid = low + ((high-low)>>1);
if(A(mid) > val) high = mid-1;
else if(A(mid) == val) low = mid+1, r = mid;
}
if(l > r) continue;
L = st; R = l-1; sz = 0;
if(L <= R) to_upd[sz++] = {L, R};
int rem = c-l+st;
L = r - rem + 1; R = r;
if(L <= R) to_upd[sz++] = {L, R};
sort(to_upd, to_upd+sz); sz = unique(to_upd, to_upd+sz) - to_upd;
for(int j = 0; j<sz; ++j) UPD(to_upd[j].first, to_upd[j].second);
}else{
scanf("%d %d", &l, &r);
int low = 1, high = n; L = n+1; R = -1;
while(low <= high){
int mid = low + ((high-low)>>1);
if(A(mid) >= l) high = mid-1, L = mid;
else low = mid+1;
}
low = 1; high = n;
while(low <= high){
int mid = low + ((high-low)>>1);
if(A(mid) <= r) low = mid+1, R = mid;
else high = mid-1;
}
if(L <= n && R >= 1 && L <= R) printf("%d\n", R-L+1);
else puts("0");
}
}
}
Compilation message
grow.cpp: In function 'int main()':
grow.cpp:13:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | int n, q; scanf("%d %d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~~
grow.cpp:14:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | for(int i = 1; i<=n; ++i) scanf("%lld", a+i);
| ~~~~~^~~~~~~~~~~~~
grow.cpp:17:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | char op; scanf(" %c", &op);
| ~~~~~^~~~~~~~~~~~
grow.cpp:19:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | scanf("%d %d", &c, &h);
| ~~~~~^~~~~~~~~~~~~~~~~
grow.cpp:50:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scanf("%d %d", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
46 ms |
3012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Incorrect |
2 ms |
496 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
38 ms |
1696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
1616 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
49 ms |
2492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
65 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
40 ms |
2608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
88 ms |
3324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
63 ms |
3156 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
85 ms |
4256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |