#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#include "grader.cpp"
#else
#include "prize.h"
#endif
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const int SIZE = 2e5 + 5;
const int K = 450;
int mx, L[SIZE], R[SIZE];
vector<int> id;
pair<int, int> que(int i) {
if (L[i] == -1) {
auto v = ask(i);
L[i] = v[0], R[i] = v[1];
}
return {L[i], R[i]};
}
void rec(int l, int r, int lc, int rc, int tot) {
if (l > r || tot == 0) return;
if (l == r) {
id.pb(l);
return;
}
int mid = (l + r) / 2;
FOR (i, mid, r) {
auto [lcnt, rcnt] = que(i);
if (lcnt + rcnt != mx) {
id.pb(i);
continue;
}
lcnt -= lc, rcnt -= rc;
rec(l, mid - 1, lc, rc + (i - mid) + rcnt, tot - (i - mid) - rcnt);
rec(i + 1, r, lc + lcnt, rcnt, tot - lcnt);
return;
}
rec(l, mid - 1, lc, rc + (r - mid + 1), tot - (r - mid + 1));
}
int find_best(int n) {
FOR (i, 0, n - 1) L[i] = R[i] = -1;
if (n < K) {
FOR (i, 0, n - 1) {
auto [l, r] = que(i);
if (l == 0 && r == 0) return i;
}
}
mx = 0;
FOR (i, 0, K - 1) {
auto [l, r] = que(i);
mx = max(mx, l + r);
}
id.clear();
rec(0, n - 1, 0, 0, mx);
for (int i : id) {
auto [l, r] = que(i);
if (l == 0 && r == 0) return i;
}
}
/*
in1
8
3 2 3 1 3 3 2 3
*/
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:84:1: warning: control reaches end of non-void function [-Wreturn-type]
84 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
2008 KB |
Output is correct |
2 |
Incorrect |
57 ms |
2140 KB |
Incorrect |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
29 ms |
2144 KB |
Partially correct - number of queries: 6872 |
2 |
Incorrect |
46 ms |
2136 KB |
Incorrect |
3 |
Halted |
0 ms |
0 KB |
- |