#include "prize.h"
#include "bits/stdc++.h"
using namespace std;
#ifdef duc_debug
#include "bits/debug.h"
#else
#define debug(...)
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) {
assert(l <= r);
return uniform_int_distribution<int> (l, r)(rng);
}
const int maxn = 2e5 + 5;
const int B = 480;
vector<int> que[maxn];
int cnt_asks;
vector<int> abc(int i) {
++cnt_asks;
if(!que[i].empty()) {
return que[i];
} else {
return que[i] = ask(i);
}
}
int find_best(int n) {
int mx = 0;
int x = min(n - 1, B);
for (int i = 0; i <= x; ++i) {
vector<int> cur = abc(i);
if (cur[0] + cur[1] == 0) return i;
mx = max(mx, cur[0] + cur[1]);
}
while (x >= 0) {
if (que[x][0] + que[x][1] == mx) break;
--x;
}
int spec = 0;
for(int i = x; i < n; ++i) {
// debug(cnt_asks, i, spec);
vector<int> cur_ask = abc(i);
if(cur_ask[0] + cur_ask[1] != mx) {
++spec;
if(cur_ask[0] + cur_ask[1] == 0) {
return i;
}
continue;
}
int l = i + 1, r = n - 1, nxt = i;
while(l <= r) {
int mid = (l + r) >> 1;
vector<int> he = abc(mid);
if(he == cur_ask) {
nxt = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
i = nxt;
}
}
컴파일 시 표준 에러 (stderr) 메시지
prize.cpp: In function 'int find_best(int)':
prize.cpp:65:1: warning: control reaches end of non-void function [-Wreturn-type]
65 | }
| ^| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |