#include<bits/stdc++.h>
using namespace std;
int l;
vector<int> f;
void update(int idx , int d){
++idx;
while(idx <= l){
f[idx] += d;
idx += idx & (-idx);
}
}
int sum(int idx){
long long sum = 0;
while(idx){
sum += f[idx];
idx -= idx & (-idx);
}
return sum;
}
int pos , flag , cur_rice;
void Find(int l , int r , long long B){
int mid = (l + r) >> 1;
int how_many = sum(r) - sum(l - 1);
if(how_many * mid <= B && !flag){
if(how_many > cur_rice){
pos = mid;
cur_rice = how_many;
}
return;
}
int left_side = sum(mid) - sum(l - 1);
int right_side = sum(r) - sum(mid - 1);
if(left_side < right_side){
Find(mid + 1 , r , B);
} else if(right_side < left_side){
Find(l , mid - 1 , B);
} else {
Find(l , mid - 1 , B);
Find(mid + 1 , r , B);
}
}
int besthub(int R , int L , vector<int> X , long long B){
l = L;
int mx = -1;
for(int i = 0; i < R; ++i){
update(X[i] , 1);
mx = max(mx , X[i]);
}
Find(0 , mx , B);
return pos;
}
Compilation message
/tmp/ccAkTpyi.o: In function `main':
grader.cpp:(.text.startup+0x92): undefined reference to `besthub(int, int, int*, long long)'
collect2: error: ld returned 1 exit status