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>
using namespace std;
int n;
int t[100010],a[100010];
void update(int x,int I) {
while(x<=n) t[x]+=I,x+=x&-x;
}
int query(int x) {
int ans=0; while(x) ans+=t[x],x-=x&-x; return ans;
}
//写个假的二分
int search_lower(int x) { //第一个大于等于x
int l=1,r=n,mid;
while(l<=r) {
mid=(l+r)/2;
if(query(mid)<x) l=mid+1;
else r=mid-1;
}
return r+1;
}
int search_upper(int x) { //第一个大于x
int l=1,r=n,mid;
while(l<=r) {
mid=(l+r)/2;
if(query(mid)<=x) l=mid+1;
else r=mid-1;
}
return r+1;
}
int main() {
int m,i,j;
char c;
int x,y,t,t2;
cin>>n>>m;
for(i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+n+1);
for(i=1;i<=n;i++) update(i,a[i]-a[i-1]);
for(i=1;i<=m;i++) {
cin>>c>>x>>y;
if(c=='F') {
t=search_lower(y);
update(t,1);
update(t+x-1,-1);
t2=search_upper(query(t+x-1))-1;
update(t2,1);
update(t2+1,-1);
} else cout<<search_upper(y)-search_lower(x)<<endl;
}
return 0;
}
Compilation message (stderr)
grow.cpp: In function 'int main()':
grow.cpp:31:10: warning: unused variable 'j' [-Wunused-variable]
31 | int m,i,j;
| ^
# | 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... |