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 "prize.h"
#include<bits/stdc++.h>
#define ii pair<int,int>
#define st first
#define nd second
#define pb push_back
using namespace std;
set<int> s;
int bg[200005][2];
int find_best(int n) {
queue<ii> q;
q.push({0,n-1});
while(!q.empty()) {
ii query=q.front();
q.pop();
if(query.st>query.nd) continue ;
vector<int> res;
int mid=(query.st+query.nd)/2;
cerr<<mid<<endl;
res=ask(mid);
if(res[0]==0 && res[1]==0) return mid;
bg[mid][0]=res[0];
bg[mid][1]=res[1];
auto rnx=s.lower_bound(mid);
auto lnx=s.lower_bound(mid);
if(res[1]) {
if(rnx==s.end() || bg[mid][1]>bg[*rnx][1] || bg[*rnx][0]>bg[mid][0]) q.push({mid+1,query.nd});
}
if(res[0]) {
if(lnx==s.begin() || bg[mid][1]<bg[*prev(lnx)][1] || bg[*prev(lnx)][0]<bg[mid][0]) q.push({query.st,mid-1});
}
s.insert(mid);
}
assert(0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |