#ifndef hwe
#include "prize.h"
#endif
#include <bits/stdc++.h>
using namespace std;
#define popcount(n) (__builtin_popcountll((n)))
#define clz(n) (__builtin_clzll((n)))
#define ctz(n) (__builtin_ctzll((n)))
#define lg(n) (63 - __builtin_clzll((n)))
#define BIT(n, i) (((n) >> (i)) & 1ll)
#define MASK(i) (1ll << (i))
#define FLIP(n, i) ((n) ^ (1ll << (i)))
#define ON(n, i) ((n) | MASK(i))
#define OFF(n, i) ((n) & ~MASK(i))
#define Int __int128
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long, long long>> vll;
typedef vector<pair<long long, int>> vli;
typedef vector<pair<int, long long>> vil;
template <class T1, class T2>
bool maximize(T1 &x, T2 y) {
if (x < y) {
x = y;
return true;
}
return false;
}
template <class T1, class T2>
bool minimize(T1 &x, T2 y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <class T>
void remove_duplicate(vector<T> &ve) {
sort (ve.begin(), ve.end());
ve.resize(unique(ve.begin(), ve.end()) - ve.begin());
}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
template <class T> T random(T l, T r) {
return uniform_int_distribution<T>(l, r)(rng);
}
template <class T> T random(T r) {
return rng() % r;
}
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
map<int, vector<int>> mem;
int ans = -1, counter = 0, not_lolipop = -1;
#ifdef hwe
vector<int> ask(int id) {
return {0, 1};
}
#endif
vector<int> myask(int id) {
auto it = mem.find(id);
if (it != mem.end()) return mem[id];
vector<int> tmp = ask(id); mem[id] = tmp;
if (tmp[0] + tmp[1] == 0) ans = id;
return tmp;
}
void dnc(int l, int r, int prefL, int prefR) {
if (ans != -1) return;
if (prefR - prefL == 0) return;
int mid = l + r + 1 >> 1; vector<int> ask_mid = myask(mid);
if (l == r) return;
dnc(l, mid - 1, prefL, ask_mid[0]);
dnc(mid, r, ask_mid[0], prefR);
}
void find_lolipop(int l, int r) {
if (ans != -1) return;
if (++counter == 500) return;
int mid = l + r + 1 >> 1; vector<int> ask_mid = myask(mid);
maximize(not_lolipop, ask_mid[0] + ask_mid[1]);
if (l == r) return;
find_lolipop(l, mid - 1);
find_lolipop(mid, r);
}
int find_best(int n) {
ans = not_lolipop = -1; counter = 0;
find_lolipop(0, n - 1);
dnc(0, n - 1, 0, not_lolipop);
assert(not_lolipop != -1);
assert(0 <= ans && ans < n);
return ans;
}
#ifdef hwe
signed main() {
cerr << '\n'; return 0;
}
#endif
Compilation message
prize.cpp: In function 'void dnc(int, int, int, int)':
prize.cpp:91:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
91 | int mid = l + r + 1 >> 1; vector<int> ask_mid = myask(mid);
| ~~~~~~^~~
prize.cpp: In function 'void find_lolipop(int, int)':
prize.cpp:104:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
104 | int mid = l + r + 1 >> 1; vector<int> ask_mid = myask(mid);
| ~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
50 ms |
1428 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
49 ms |
1292 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |