This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
int st[400005];
vector <int> v;
int n, m, ans, llidx, lridx, rlidx, rridx, L, R;
int cons(int pos, int l, int r){
if(l==r){
st[pos]=v[l]-v[l-1];
return st[pos];
}
int mid=(l+r)/2;
st[pos]=cons(pos*2, l, mid)+cons(pos*2+1, mid+1, r);
return st[pos];
}
int find(int pos, int l, int r, int mn, int nw){
if(l==r){
return r;
}
int mid=(l+r)/2;
if(nw+st[pos*2]>=mn){
return find(pos*2, l, mid, mn, nw);
}
return find(pos*2+1, mid+1, r, mn, nw+st[pos*2]);
}
int fun(int pos, int l, int r, int k){
if(l==r and l==k){
return ans+st[pos];
}
int mid=(l+r)/2;
if(k<=mid){
return fun(pos*2, l, mid, k);
}
else{
ans+=st[pos*2];
return fun(pos*2+1, mid+1, r, k);
}
}
int upd(int pos, int l, int r, int q, int diff){
if(q==l and l==r){
st[pos]+=diff;
return st[pos];
}
else if(q<l or q>r){
return st[pos];
}
int mid=(l+r)/2;
st[pos]=upd(pos*2, l, mid, q, diff)+
upd(pos*2+1, mid+1, r, q, diff);
return st[pos];
}
int main(){
cin>>n>>m;
v.push_back(0);
v.push_back(INT_MAX);
for(int i=1; i<=n; i++){
int a;
cin>>a;
v.push_back(a);
}
sort(v.begin(), v.end());
cons(1, 1, n);
for(int i=1; i<=m; i++){
int a, b;
char c;
cin>>c>>a>>b;
if(c=='F'){
llidx=find(1, 1, n, b, 0);
ans=0;
L=fun(1, 1, n, llidx);
ans=0;
R=fun(1, 1, n, llidx+a-1);
rridx=find(1, 1, n, R+1, 0)-1;
if(llidx+a>=n){
//cout<<llidx<<endl;
upd(1, 1, n, llidx, 1);
}
else if(L==R){
//cout<<llidx<<" "<<rridx<<endl;
upd(1, 1, n, llidx, 1);
upd(1, 1, n, rridx+1, -1);
}
else{
lridx=find(1, 1, n, R, 0)-1;
rlidx=rridx-(a-(lridx-llidx+1)-1);
//cout<<llidx<<" "<<lridx<<" "<<rlidx<<" "<<rridx<<endl;
upd(1, 1, n, llidx, 1);
upd(1, 1, n, lridx+1, -1);
upd(1, 1, n, rlidx, 1);
upd(1, 1, n, rridx+1, -1);
}
/*for(int i=1; i<n*2; i++){
cout<<st[i]<<" ";
}
cout<<endl;*/
}
else{
if(a>st[1]){
cout<<0<<endl;
}
else {
cout<<find(1, 1, n, b+1, 0)-find(1, 1, n, a, 0)+1<<endl;
}
}
}
}
# | 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... |