#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lc 2 * no
#define rc 2 * no + 1
int n = 1e5 + 5,q;
vi bit(n);
void update(int i,int inc)
{
for (;i<=n;i+=i&(-i))bit[i] += inc;
}
void update(int i,int j,int inc)
{
update(i,inc);
update(j + 1,-inc);
}
int sum(int i)
{
int ret = 0;
for (;i>0;i-=i&(-i))ret += bit[i];
return ret;
}
int lowerBound(int h)
{
int l = 1,r = n,ans = n;
while (l <= r){
int mid = (l + r)/2;
if (sum(mid) >= h){
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
return ans;
}
int Lower2(int h)
{
int l = 1,r = n,ans = 1;
while (l <= r){
int mid = (l + r)/2;
if (sum(mid) <= h){
ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
return ans;
}
int main()
{
fast;
cin>>n>>q;
vi a(n + 1);
for (int i = 1;i<=n;i++)cin>>a[i];
sort(a.begin() + 1,a.end());
for (int i = 1;i<=n;i++)update(i,i,a[i]);
while (q--){
char x;
cin>>x;
if (x == 'F'){
int c,h;
cin>>c>>h;
if (sum(n) < h)continue;
int first = lowerBound(h);//first index to be updated
if (sum(first) < h)continue;
int Last = min(n,first + c - 1);//last index to be updated
if (first + c - 1 >= n)c = n - c;
int val = sum(Last);//height of the last index to be updated
int pos1 = lowerBound(val),pos2 = Lower2(val);
int rem = c - (pos1 - first);
update(first,pos1 - 1,1);
update(pos2 - rem + 1,pos2,1);
}
else{
int mn,mx;
cin>>mn>>mx;
int L1 = lowerBound(mn),L2 = Lower2(mx);
if (sum(1) > mx or sum(n) < mn)cout<<0<<'\n';
else cout<<L2 - L1 + 1<<'\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
65 ms |
1068 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
716 KB |
Output is correct |
2 |
Correct |
3 ms |
716 KB |
Output is correct |
3 |
Incorrect |
4 ms |
728 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
1008 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
68 ms |
1024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
60 ms |
1100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
128 ms |
1224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
103 ms |
1064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
125 ms |
1608 KB |
Output isn't correct |