이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 = 500;
int ans, 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 check(int i) {
if (ans != -1) return;
auto [l, r] = que(i);
if (l + r == 0) {
ans = i;
return;
}
id.pb(i);
}
void rec(int l, int r, int lc, int rc, int tot) {
if (ans != -1 || l > r || tot == 0) return;
if (l == r) {
check(l);
return;
}
int mid = (l + r) / 2;
FOR (i, mid, r) {
if (ans != -1) return;
auto [lcnt, rcnt] = que(i);
if (lcnt + rcnt != mx) {
check(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, rc, 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();
ans = -1;
FOR (i, 0, K - 1) {
auto [l, r] = que(i);
if (l + r != mx) check(i);
}
rec(K, n - 1, id.size(), 0, mx - id.size());
for (int i : id) check(i);
return ans;
}
/*
in1
8
3 2 3 1 3 3 2 3
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |