#include <bits/stdc++.h>
#include "prize.h"
using namespace std;
using ll = long long;
//vector<int> ask(int i);
vector<int> a[200006];
int summ = 0;
int solve(int l, int r){
if(l+1>=r)return 0;
int cnt = a[l][1]-a[r][1];
if(cnt==0)return 0;
int s = l+r>>1;
if(a[s][0]==-1)a[s]=ask(s);
if(a[s][0]+a[s][1]==summ)return max(solve(l, s), solve(s, r));
if(a[s][0]+a[s][1]==0)return s;
int R = s-1, L = s+1;
for(int i=s-1; i>=l; i--){
if(a[i][0]==-1)a[i]=ask(i);
if(a[i][0]+a[i][1]==0)return i;
if(a[i][0]+a[i][1]==summ){
R=i;
break;
}
}
for(int i=s+1; i<=r; i++){
if(a[i][0]==-1)a[i]=ask(i);
if(a[i][0]+a[i][1]==0)return i;
if(a[i][0]+a[i][1]==summ){
L=i;
break;
}
}
return max(solve(l, R), solve(L, r));
}
int find_best(int n){
if(n<=5000){
for(int i=0; i<n; i++){
vector<int> ans = ask(i);
if(ans[0]==0 && ans[1]==0)return i;
}
}
/*
for(int i=0; i< n; i++){
a[i].push_back(-1);
}
for(int i=0; i<20; i++){
ll ind = rand() * 12ll * rand() + 1000000009ll*rand();
ind%=n;
if(a[ind][0]!=-1){
i--;
continue;
}
vector<int> ans = ask(ind);
a[ind]=ans;
summ=max(summ, ans[0]+ans[1]);
if(ans[0]+ans[1]==0)return ind;
}
int L = 0, R = n-1;
for(int i=0; i<n; i++){
if(a[i][0]==-1)a[i] = ask(i);
if(a[i][0]+a[i][1]==summ){
L=i;
break;
}
if(a[i][0]+a[i][1]==0)return i;
}
for(int i=n-1; i>=0; i--){
if(a[i][0]==-1)a[i]=ask(i);
if(a[i][0]+a[i][1]==summ){
R=i;
break;
}
if(a[i][0]+a[i][1]==0)return i;
}
return solve(L, R);*/
}
Compilation message
prize.cpp: In function 'int solve(int, int)':
prize.cpp:17:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
17 | int s = l+r>>1;
| ~^~
prize.cpp: In function 'int find_best(int)':
prize.cpp:82:1: warning: control reaches end of non-void function [-Wreturn-type]
82 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
51 ms |
4952 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
59 ms |
4952 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |