example :
check(...)://O(logX)
...
l=MIN,r=MAX,ans;
while(l<=r) {
mid=l+r>>1;
bool flag=true;
for(int i=1;i<=n;i++)
if(!check(i,mid))
flag=false;
if(flag) r=mid-1,ans=mid;
else l=mid+1;
}
//O(nlogVlogX)
//->
shuffle(id+1,id+n+1);
int ans=MIN;
for(int i=1;i<=n;i++) {
if(check(i,ans)) continue;
ll l=MIN,r=MAX;
while(l<=r) {
ll mid=l+r>>1;
if(check(i,mid)) r=mid-1,ans=mid;
else l=mid+1;
}
}
//O(nlogX+lognlogVlogX)