#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){
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);
} else if(right_side < left_side){
Find(l , mid - 1);
} else {
Find(l , mid - 1);
Find(mid + 1 , r);
}
}
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);
return pos;
}
Compilation message
ricehub.cpp: In function 'void Find(int, int)':
ricehub.cpp:29:26: error: 'B' was not declared in this scope
if(how_many * mid <= B && !flag){
^