이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <chrono>
#include "prize.h"
using namespace std;
const int bont = 511;
int ert = 0;
mt19937 rng2(chrono::steady_clock::now().time_since_epoch().count());
int megold(int l, int r, vector<int> ansl, vector<int> ansr){
if(l+1 >= r) return -1;
int m1 = (l+r)/2;
int m2 = m1;
vector<int> ans = ask(m1);
if(ans[0] + ans[1] == 0) return m1;
vector<int> ans2 = ans;
while(m1-1 > l && ans[0]+ans[1] != ert){
m1--;
ans = ask(m1);
if(ans[0] + ans[1] == 0) return m1;
}
while(m2+1 < r && ans2[0]+ans2[1] != ert){
m2++;
ans2 = ask(m2);
if(ans2[0] + ans2[1] == 0) return m2;
}
return max((ansl[0] < ans[0] ? megold(l, m1, ansl, ans) : -1), (ans2[0] < ansr[0] ? megold(m2, r, ans2, ansr) : -1));
}
int find_best(int n) {
int s = 470;
vector<int> ans;
for(int i = 0; i < min(470, n); i++){
ans = ask(i);
if(ans[0] + ans[1] == 0) return i;
if(ans[0] + ans[1] > ert)
ert = ans[0] + ans[1];
}
ans = ask(s);
while(s < n){
if(ans[0]+ans[1] == 0)
return s;
while(ans[0]+ans[1] != ert){
s++;
ans = ask(s);
if(ans[0]+ans[1] == 0)
return s;
}
int e = min(s+bont, n-1);
int s2 = e+1;
vector<int> ans2 = ask(e);
if(ans2[0]+ans2[1] == 0)
return e;
while(s < e && ans2[0]+ans2[1] != ert){
e--;
ans2 = ask(e);
if(ans2[0]+ans2[1] == 0)
return e;
}
if(ans[0] < ans2[0]){
int temp = megold(s, e, ans, ans2);
if(temp != -1)
return temp;
}
s = s2;
if(e == s-1){
ans = ans2;
s--;
} else
ans = ask(s);
}
return -1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |