#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=2e5+5;
int bit[N];
int arr[N];
int n,q;
void update(int idx, int val){
while(idx<N){
bit[idx]+=val;
idx+= idx & -idx;
}
}
int find(int idx){
if(idx==0)return 0;
int s=0;
while(idx>0){
s+=bit[idx];
idx-= idx & -idx;
}
return s;
}
int findpos(int h){
int lo=1;
int hi=n;
while(hi>=lo){
int mid=(hi+lo)/2;
if(find(mid)-find(mid-1)+arr[mid]<h){
lo=mid+1;
}
else{
hi=mid-1;
}
}
}
signed main(){
vector<int>v;
cin>>n>>q;
for(int i=1;i<=n;i++){
int a;
cin>>a;
v.pb(a);
}
sort(v.begin(),v.end());
for(int i=1;i<=n;i++){
arr[i]=v[i-1];
}
while(q--){
char c;
cin>>c;
if(c=='F'){
int x,h;
cin>>x>>h;
int lo=findpos(h);
if(n-lo+1<=x){
update(lo,1);
continue;
}
int r= lo+x-1;
int p=find(r)-find(r-1)+arr[r];
int z=findpos(p);
update(lo,1);
update(z,-1);
int cnt=r-z+1;
int y=findpos(p+1)-1;
z=y-cnt+1;
update(z,1);
update(y+1,-1);
}
else{
int l,r ;
cin>>l>>r;
}
}
}
Compilation message
grow.cpp: In function 'long long int findpos(long long int)':
grow.cpp:40:1: warning: no return statement in function returning non-void [-Wreturn-type]
40 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1040 ms |
3780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1045 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1053 ms |
604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1048 ms |
3796 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1064 ms |
3792 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1025 ms |
3624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1037 ms |
4036 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1060 ms |
3792 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1029 ms |
4304 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |