#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int K = 475;
const int N = 2e5;
const int L = 5000;
const int mod = 998244353;
set <int> s;
int l2[N],r2[N];
int cnt = 0;
int mx = 0;
int qcount = 0;
int ans = -1;
int seed = 17;
int f(){
return rng()%mod;
seed = 1ll*seed*seed%mod;
return seed;
}
void solve(int l,int r,int dl,int dr){
if(dl + dr >= mx)return;
if(l > r)return;
//cout<<l<<' '<<r<<' '<<dl<<' '<<dr<<'\n';
int mij = (l + r)/2;
for(int i = mij;i <= r;i++){
auto x = ask(i);
if(x[0] + x[1] == mx){
x[0]-=dl;
x[1]-=dr;
solve(i + 1,r,x[0] + dl,dr);
if(ans != -1)return;
solve(l,mij - 1,dl,dr + x[1] + i - mij);
return;
}else{
if(x[0] + x[1] == 0){
ans = i;
return;
}
}
}
solve(l,mij - 1,dl,dr);
return;
}
int find_best(int n) {
int last = 0;
for(int i = 0;i < K;i++){
int id = f()%n;
//cout<<id<<'\n';
auto x = ask(id);
int nr = x[0] + x[1];
if(nr == 0)return id;
if(nr > mx){
mx = nr;
cnt = 1;
}else if(nr == mx){
cnt++;
}
last = i;
if(mx > (int)sqrt(n))break;
}
solve(last + 1,n - 1,last - cnt + 1,0);
return ans;
}
/**
8
3 3 3 3 2 2 2 1
**/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
344 KB |
Output is correct |
4 |
Correct |
3 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Incorrect |
2 ms |
596 KB |
Integer -1 violates the range [0, 199999] |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
600 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Incorrect |
2 ms |
344 KB |
Integer -1 violates the range [0, 199999] |
7 |
Halted |
0 ms |
0 KB |
- |