#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
//using namespace __gnu_pbds;
/*
ll add(ll x,ll y){
x+=y;
if(x<0){
x%=mod;
x+=mod;
}else{
if(x>=mod) x%=mod;
}
return x;
}
ll mul(ll a,ll b){
ll ans = (a*b)%mod;
if(ans<0) ans+=mod;
return ans;
}
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
return uniform_int_distribution<ll>(l,r)(rng);
}
*/
#define maxn 100005
ll n,q;
ll a[maxn];
ll t[2*maxn],ls[2*maxn],rs[2*maxn],tsz = 0,root = 0;
void init(ll &v,ll tl,ll tr){
if(!v) v = ++tsz;
if(tl==tr){t[v] = a[tl];return;}
ll mid = (tl+tr)/2;
init(ls[v],tl,mid);
init(rs[v],mid+1,tr);
}
void upd(ll v,ll tl,ll tr,ll l,ll r,ll x){
if(l>r||tl>r||l>tr||tl>tr) return;
if(tl>=l&&tr<=r){t[v]+=x;return;}
ll mid = (tl+tr)/2;
upd(ls[v],tl,mid,l,r,x);
upd(rs[v],mid+1,tr,l,r,x);
}
ll get(ll v,ll tl,ll tr,ll i){
if(tl==tr) return t[v];
ll mid = (tl+tr)/2;
if(i<=mid) return t[v] + get(ls[v],tl,mid,i);
return t[v] + get(rs[v],mid+1,tr,i);
}
ll get(ll h){
ll l = 1,r = n,mid,rez = n+1;
while(l<=r){
mid = (l+r)/2;
if(get(1,1,n,mid)>=h) rez = mid,r = mid-1;
else l = mid+1;
}
return rez;
}
void tc(){
cin >> n >> q;
for(ll i = 1;i<=n;i++) cin >> a[i];
sort(a+1,a+1+n);
init(root,1,n);
while(q--){
char ch;
cin >> ch;
if(ch=='F'){
ll c,h;
cin >> c >> h;
ll rez = get(h);
ll tl = rez,tr = min(n,rez+c-1);
ll val = get(1,1,n,tr);
if(tr==n||get(1,1,n,tr)!=get(1,1,n,tr+1)){
upd(1,1,n,tl,tr,1);
continue;
}
ll tl2 = tr,tr2 = tr;
for(ll j = 19;j>=0;j--){
if(tl2-(1<<j)>=1&&get(1,1,n,tl2-(1<<j))==val) tl2-=(1<<j);
if(tr2+(1<<j)<=n&&get(1,1,n,tr2+(1<<j))==val) tr2+=(1<<j);
}
upd(1,1,n,tl,tl2-1,1);
upd(1,1,n,tr2-(c-(tl2-tl))+1,tr2,1);
}else{
ll hmin,hmax;
cin >> hmin >> hmax;
cout<<get(hmax+1)-get(hmin)<<endl;
}
}
}
int main(){
daj_mi_malo_vremena
int t; t = 1;
while(t--){
tc();
}
return 0;
}
/**
5 7
1 3 2 5 2
F 2 1
C 3 6
F 2 3
C 6 8
F 2 1
F 2 2
C 3 5
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
238 ms |
5300 KB |
Output is correct |
2 |
Correct |
327 ms |
6676 KB |
Output is correct |
3 |
Correct |
118 ms |
6460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
468 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
103 ms |
1672 KB |
Output is correct |
6 |
Correct |
136 ms |
1916 KB |
Output is correct |
7 |
Correct |
10 ms |
596 KB |
Output is correct |
8 |
Correct |
55 ms |
1356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
1040 KB |
Output is correct |
2 |
Correct |
133 ms |
2108 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
73 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
1076 KB |
Output is correct |
2 |
Correct |
138 ms |
2004 KB |
Output is correct |
3 |
Correct |
16 ms |
808 KB |
Output is correct |
4 |
Correct |
140 ms |
2140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
245 ms |
4048 KB |
Output is correct |
2 |
Correct |
369 ms |
5660 KB |
Output is correct |
3 |
Correct |
56 ms |
1620 KB |
Output is correct |
4 |
Correct |
75 ms |
5632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
297 ms |
4624 KB |
Output is correct |
2 |
Correct |
381 ms |
6056 KB |
Output is correct |
3 |
Correct |
79 ms |
5828 KB |
Output is correct |
4 |
Correct |
40 ms |
1632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
231 ms |
4824 KB |
Output is correct |
2 |
Correct |
258 ms |
6484 KB |
Output is correct |
3 |
Correct |
91 ms |
6428 KB |
Output is correct |
4 |
Correct |
44 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
346 ms |
5240 KB |
Output is correct |
2 |
Correct |
370 ms |
5972 KB |
Output is correct |
3 |
Correct |
65 ms |
6388 KB |
Output is correct |
4 |
Correct |
161 ms |
6400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
333 ms |
5208 KB |
Output is correct |
2 |
Correct |
302 ms |
6792 KB |
Output is correct |
3 |
Correct |
300 ms |
7516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
351 ms |
6304 KB |
Output is correct |