#include <bits/stdc++.h>
using namespace std;
int a[200005], cc = 0, hh = 200000, dd[200005], c[200005][10], da[200005];
void build(int n) {
for (int j = 0; j <= 9; j++) {
c[0][j] = (a[0] <= j);
for (int i = 1; i < n; i++) {
c[i][j] = c[i - 1][j] + (a[i] <= j);
}
}
}
mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
vector<int> ask(int i);
int find_best(int n) {
vector<pair<int, pair<int, int>>> v;
vector<int> t;
if (n <= 170000) {
for (int i = 0; i < 480; i++) {
t = ask(i);
if (t[0] + t[1] == 0) return i;
mi = max(mi, t[0] + t[1]);
}
}
else {
for (int i = 0; i < n; i++) da[i] = 0;
for (int i = 0; i < 430; i++) {
int h;
while (1) {
h = 1ll * (mt() % n) % n;
if (da[h] == 1) continue;
break;
}
da[h] = 1;
t = ask(h);
if (t[0] + t[1] == 0) return h;
mi = max(mi, t[0] + t[1]);
}
}
int mi = 0;
for (int i = 0; i < 475; i++) {
t = ask(i);
if (t[0] + t[1] == 0) return i;
mi = max(mi, t[0] + t[1]);
}
for (int i = 0; i < n; i++) dd[i] = da[i] = 0;
int c = 0;
for (int i = 0; i < n; i += 500) {
while (1) {
if (i >= n) break;
t = ask(i);
if (t[0] + t[1] == 0) return i;
if (t[0] + t[1] == mi) {
break;
}
c++;
i++;
}
if (i < n) {
v.push_back({i, {t[1], c}});
c = 0;
}
}
v.push_back({n, {0, c}});
vector<int> vb, vvb;
for (int i = 0; i < v.size() - 1; i++) vb.push_back(i);
for (int i = 0; i < vb.size(); i++) {
int h = mt() % (vb.size() - i) + 1;
for (int j = 0; j < vb.size(); j++) {
if (da[j] == 0) {
h--;
if (h == 0) {
vvb.push_back(vb[j]);
da[j] = 1;
break;
}
}
}
}
for (int i : vvb) {
int h = v[i].second.first - v[i + 1].second.first;
h -= v[i + 1].second.second;
vector<int> va, vc, vv;
for (int j = v[i].first; j < min(v[i].first + 500, n + 1); j++) {
va.push_back(j);
}
for (int j = 0; j < h; j++) {
int l = 0, r = va.size() - 1, res;
while (1) {
int mid = (l + r) / 2;
res = va[mid];
dd[va[mid]] = 1;
t = ask(va[mid]);
if (t[0] + t[1] == 0) return va[mid];
if (t[0] + t[1] != mi) break;
for (int w : vc) {
if (w <= va[mid]) t[1]++;
}
if (t[1] == v[i].second.first) {
l = mid + 1;
}
else r = mid - 1;
}
vc.push_back(res);
vv.clear();
for (int w : va) {
if (dd[w] == 0) vv.push_back(w);
}
va = vv;
}
}
return -1;
}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:21:13: error: 'mi' was not declared in this scope; did you mean 'i'?
21 | mi = max(mi, t[0] + t[1]);
| ^~
| i
prize.cpp:36:13: error: 'mi' was not declared in this scope; did you mean 'i'?
36 | mi = max(mi, t[0] + t[1]);
| ^~
| i
prize.cpp:65:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (int i = 0; i < v.size() - 1; i++) vb.push_back(i);
| ~~^~~~~~~~~~~~~~
prize.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int i = 0; i < vb.size(); i++) {
| ~~^~~~~~~~~~~
prize.cpp:68:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for (int j = 0; j < vb.size(); j++) {
| ~~^~~~~~~~~~~