// In the name of Allah
#include <bits/stdc++.h>
#include "prize.h"
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<ld> cld;
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define F first
#define S second
#define pb push_back
#define sep ' '
#define endl '\n'
#define Mp make_pair
#define kill(x) cout << x << '\n', exit(0)
#define set_dec(x) cout << fixed << setprecision(x);
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
const int maxn = 2e5 + 7;
int n; pii A[maxn];
mt19937 rng(923232361);
void askx(int i) {
if (A[i].F != -1) return ;
vector<int> res = ask(i);
A[i] = Mp(res[0], res[1]);
return ;
}
int find_best(int n) {
fill(A, A + n, Mp(-1, -1));
if (n <= 5000) {
for (int i = 0; i < n; i++) {
askx(i);
if (A[i].F + A[i].S == 0) return i;
}
return -1;
}
int mx = 0;
while (mx <= 1000) {
int i = rng() % n; askx(i);
if (A[i].F + A[i].S == 0) return i;
mx = max(mx, A[i].F + A[i].S);
}
int i = 0;
while (i < n) {
askx(i);
if (A[i].F + A[i].S == 0) return i;
else if (A[i].F + A[i].S != mx) {
i++;
continue;
}
bool flag = 0;
int l = i, r = min(n, i + 1024);
while (r - l > 1) {
int mid = (l + r) / 2;
int j = mid; askx(j);
if (A[j].F + A[j].S == 0) return j;
if (A[j].F + A[j].S == mx && A[j].F == A[i].F) {
l = mid;
if (!flag) break;
}
else r = mid;
flag = 1;
}
i = l + 1;
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
64 ms |
1880 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
1880 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |