This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
int lc[SIZE];
map<int, set<int>> mp;
int rec(int l, int r) {
if (l > r) return -1;
int mid = (l + r) / 2;
auto v = ask(mid);
if (v[0] + v[1] == 0) return mid;
lc[mid] = v[0];
mp[v[0] + v[1]].insert(mid);
auto it = mp[v[0] + v[1]].find(mid);
if (it == mp[v[0] + v[1]].begin() || lc[*prev(it)] != lc[mid]) {
int res = rec(l, mid - 1);
if (res != -1) return res;
}
if (next(it) == mp[v[0] + v[1]].end() || lc[*next(it)] != lc[mid]) {
int res = rec(mid + 1, r);
if (res != -1) return res;
}
return -1;
}
int find_best(int n) {
mp.clear();
return rec(0, n - 1);
}
/*
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... |