#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, not_lolipop = -1, counter = 0;
#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;
if (l == r) {
myask(l);
return;
}
int mid = l + r >> 1; int pref_mid = 0;
for (int i = mid; i >= l; --i) {
vector<int> tmp = myask(i);
if (tmp[0] + tmp[1] == not_lolipop) {
pref_mid += tmp[0];
break;
}
++pref_mid;
}
dnc(l, mid, prefL, pref_mid);
dnc(mid + 1, r, pref_mid, prefR);
}
void find_lolipop(int l, int r) {
if (ans != -1) return;
if (counter == 550) return;
int mid = l + r >> 1; vector<int> ask_mid = myask(mid); ++counter;
maximize(not_lolipop, ask_mid[0] + ask_mid[1]);
if (l == r) return;
find_lolipop(l, mid);
find_lolipop(mid + 1, 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(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:96:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
96 | int mid = l + r >> 1; int pref_mid = 0;
| ~~^~~
prize.cpp: In function 'void find_lolipop(int, int)':
prize.cpp:115:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
115 | int mid = l + r >> 1; vector<int> ask_mid = myask(mid); ++counter;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
432 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
3 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
4 ms |
428 KB |
Output is correct |
16 |
Correct |
18 ms |
832 KB |
Output is correct |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Correct |
21 ms |
1076 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
7 ms |
344 KB |
Output is correct |
21 |
Correct |
6 ms |
600 KB |
Output is correct |
22 |
Correct |
2 ms |
344 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
13 ms |
804 KB |
Output is correct |
26 |
Correct |
13 ms |
660 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
15 ms |
856 KB |
Output is correct |
29 |
Correct |
9 ms |
600 KB |
Output is correct |
30 |
Correct |
21 ms |
1104 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
10 ms |
432 KB |
Output is correct |
35 |
Correct |
3 ms |
344 KB |
Output is correct |
36 |
Correct |
5 ms |
444 KB |
Output is correct |
37 |
Correct |
3 ms |
344 KB |
Output is correct |
38 |
Correct |
2 ms |
344 KB |
Output is correct |
39 |
Correct |
7 ms |
600 KB |
Output is correct |
40 |
Correct |
11 ms |
844 KB |
Output is correct |
41 |
Correct |
15 ms |
600 KB |
Output is correct |
42 |
Correct |
9 ms |
564 KB |
Output is correct |
43 |
Correct |
12 ms |
632 KB |
Output is correct |
44 |
Correct |
11 ms |
1108 KB |
Output is correct |
45 |
Correct |
7 ms |
344 KB |
Output is correct |
46 |
Correct |
2 ms |
344 KB |
Output is correct |
47 |
Correct |
9 ms |
856 KB |
Output is correct |
48 |
Correct |
15 ms |
1000 KB |
Output is correct |
49 |
Correct |
3 ms |
344 KB |
Output is correct |
50 |
Correct |
25 ms |
844 KB |
Output is correct |
51 |
Correct |
12 ms |
600 KB |
Output is correct |
52 |
Correct |
1 ms |
344 KB |
Output is correct |
53 |
Correct |
2 ms |
344 KB |
Output is correct |
54 |
Correct |
8 ms |
672 KB |
Output is correct |
55 |
Correct |
1 ms |
344 KB |
Output is correct |
56 |
Correct |
20 ms |
944 KB |
Output is correct |
57 |
Correct |
15 ms |
660 KB |
Output is correct |
58 |
Correct |
17 ms |
664 KB |
Output is correct |
59 |
Correct |
12 ms |
900 KB |
Output is correct |
60 |
Correct |
12 ms |
600 KB |
Output is correct |
61 |
Correct |
1 ms |
344 KB |
Output is correct |
62 |
Correct |
2 ms |
344 KB |
Output is correct |
63 |
Correct |
2 ms |
344 KB |
Output is correct |
64 |
Correct |
1 ms |
344 KB |
Output is correct |
65 |
Correct |
2 ms |
600 KB |
Output is correct |
66 |
Correct |
5 ms |
1012 KB |
Output is correct |
67 |
Correct |
2 ms |
428 KB |
Output is correct |
68 |
Correct |
2 ms |
344 KB |
Output is correct |
69 |
Correct |
3 ms |
344 KB |
Output is correct |
70 |
Correct |
2 ms |
344 KB |
Output is correct |
71 |
Partially correct |
18 ms |
1104 KB |
Partially correct - number of queries: 5021 |
72 |
Correct |
3 ms |
344 KB |
Output is correct |
73 |
Correct |
20 ms |
1104 KB |
Output is correct |
74 |
Correct |
20 ms |
848 KB |
Output is correct |
75 |
Correct |
2 ms |
344 KB |
Output is correct |
76 |
Correct |
21 ms |
796 KB |
Output is correct |
77 |
Correct |
22 ms |
976 KB |
Output is correct |
78 |
Correct |
3 ms |
344 KB |
Output is correct |
79 |
Correct |
10 ms |
600 KB |
Output is correct |
80 |
Correct |
20 ms |
800 KB |
Output is correct |
81 |
Correct |
30 ms |
784 KB |
Output is correct |
82 |
Correct |
18 ms |
812 KB |
Output is correct |
83 |
Correct |
2 ms |
344 KB |
Output is correct |
84 |
Correct |
17 ms |
856 KB |
Output is correct |
85 |
Correct |
18 ms |
972 KB |
Output is correct |
86 |
Correct |
4 ms |
344 KB |
Output is correct |
87 |
Correct |
3 ms |
344 KB |
Output is correct |
88 |
Correct |
4 ms |
344 KB |
Output is correct |
89 |
Correct |
3 ms |
344 KB |
Output is correct |
90 |
Correct |
2 ms |
344 KB |
Output is correct |
91 |
Correct |
3 ms |
344 KB |
Output is correct |
92 |
Correct |
4 ms |
344 KB |
Output is correct |
93 |
Incorrect |
47 ms |
1840 KB |
Incorrect |
94 |
Halted |
0 ms |
0 KB |
- |