#include <bits/stdc++.h>
#ifndef DEBUG
#include "prize.h"
#endif
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using ld = long double;
template<typename T1, typename T2> bool chkmin(T1 &x, T2 y) {
return y < x ? (x = y, true) : false;
}
template<typename T1, typename T2> bool chkmax(T1 &x, T2 y) {
return y > x ? (x = y, true) : false;
}
void debug_out() {
cerr << endl;
}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) {
cerr << ' ' << A;
debug_out(B...);
}
template<typename T> void mdebug_out(T* a, int n) {
for (int i = 0; i < n; ++i) {
cerr << a[i] << ' ';
}
cerr << endl;
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n)
#else
#define debug(...) 1337
#define mdebug(a, n) 1337
#endif
template<typename T> ostream& operator << (ostream& stream, const vector<T> &v) {
for (auto& x : v) {
stream << x << ' ';
}
return stream;
}
template<typename T1, typename T2> ostream& operator << (ostream& stream, const pair<T1, T2>& p) {
return stream << p.first << ' ' << p.second;
}
const int maxN = 200005;
#ifdef DEBUG
int a[maxN];
int cnt[maxN];
pii f[maxN];
vector<int> ask(int i) {
return {f[i].fi, f[i].se};
}
#endif
pii res[maxN];
int val[maxN];
set<int> vals;
pii Ask(int i) {
if (res[i].fi != -1) {
return res[i];
}
auto a = ask(i);
val[i] = a[0] + a[1];
vals.insert(val[i]);
return res[i] = {a[0], a[1]};
}
int find_best(int n) {
memset(res, 255, sizeof res);
memset(val, 255, sizeof val);
vals.clear();
#define ASK(i) Ask(i); if (!val[i]) return i
int i = 0;
while (i < n) {
ASK(i);
bool i_not_max = val[i] != *vals.rbegin();
int vl = i;
int vr = n;
while (vr - vl > 1 && !i_not_max) {
int vm = (vl + vr) >> 1;
ASK(vm);
if (val[vm] == val[i]) {
if (res[i].fi == res[vm].fi) {
vl = vm;
} else {
vr = vm;
}
} else if (val[vm] > val[i]) {
i_not_max = true;
break;
} else {
vr = vm;
}
}
if (i_not_max) {
++i;
continue;
}
ASK(vr);
i = vr + 1;
}
throw;
}
#ifdef DEBUG
int32_t main() {
#ifdef DEBUG
freopen("in", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
mt19937 rng(228);
int n = 5;
int C = 3;
for (int itr = 1; ; ++itr) {
int M = -1e9;
int one_i = rng() % n;
a[one_i] = 1;
fill(cnt, cnt + C + 1, 0);
for (int i = 0; i < n; ++i) {
if (i != one_i) {
a[i] = rng() % (C - 1) + 2;
}
chkmax(M, a[i]);
++cnt[a[i]];
f[i].fi = accumulate(cnt, cnt + a[i], 0);
}
bool bad = false;
for (int k = 2; k <= M; ++k) {
if (cnt[k] <= cnt[k - 1] * (ll)cnt[k - 1]) {
bad = true;
break;
}
}
if (bad) continue;
fill(cnt, cnt + C + 1, 0);
for (int i = n - 1; i >= 0; --i) {
++cnt[a[i]];
f[i].se = accumulate(cnt, cnt + a[i], 0);
}
int i = find_best(n);
assert(0 <= i && i < n && a[i] == 1);
debug(itr);
}
/*int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
++cnt[a[i]];
f[i].fi = accumulate(cnt, cnt + a[i], 0);
}
fill(cnt, cnt + n + 1, 0);
for (int i = n - 1; i >= 0; --i) {
++cnt[a[i]];
f[i].se = accumulate(cnt, cnt + a[i], 0);
}
mdebug(f, n);
int i = find_best(n);
debug(i);
assert(0 <= i && i < n && a[i] == 1);*/
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2632 KB |
Output is correct |
2 |
Correct |
2 ms |
2632 KB |
Output is correct |
3 |
Correct |
2 ms |
2632 KB |
Output is correct |
4 |
Correct |
2 ms |
2580 KB |
Output is correct |
5 |
Correct |
2 ms |
2604 KB |
Output is correct |
6 |
Correct |
2 ms |
2632 KB |
Output is correct |
7 |
Correct |
2 ms |
2632 KB |
Output is correct |
8 |
Correct |
2 ms |
2596 KB |
Output is correct |
9 |
Correct |
2 ms |
2592 KB |
Output is correct |
10 |
Correct |
2 ms |
2632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2624 KB |
Output is correct |
2 |
Correct |
2 ms |
2600 KB |
Output is correct |
3 |
Correct |
2 ms |
2508 KB |
Output is correct |
4 |
Correct |
2 ms |
2588 KB |
Output is correct |
5 |
Correct |
3 ms |
2632 KB |
Output is correct |
6 |
Correct |
2 ms |
2580 KB |
Output is correct |
7 |
Correct |
2 ms |
2600 KB |
Output is correct |
8 |
Correct |
2 ms |
2596 KB |
Output is correct |
9 |
Correct |
2 ms |
2632 KB |
Output is correct |
10 |
Correct |
2 ms |
2632 KB |
Output is correct |
11 |
Correct |
3 ms |
2624 KB |
Output is correct |
12 |
Correct |
2 ms |
2592 KB |
Output is correct |
13 |
Correct |
12 ms |
2632 KB |
Output is correct |
14 |
Correct |
4 ms |
2632 KB |
Output is correct |
15 |
Correct |
17 ms |
2592 KB |
Output is correct |
16 |
Partially correct |
82 ms |
2632 KB |
Partially correct - number of queries: 6747 |
17 |
Correct |
2 ms |
2596 KB |
Output is correct |
18 |
Partially correct |
66 ms |
2632 KB |
Partially correct - number of queries: 7887 |
19 |
Correct |
2 ms |
2588 KB |
Output is correct |
20 |
Correct |
25 ms |
2632 KB |
Output is correct |
21 |
Correct |
20 ms |
2600 KB |
Output is correct |
22 |
Correct |
5 ms |
2632 KB |
Output is correct |
23 |
Correct |
2 ms |
2616 KB |
Output is correct |
24 |
Correct |
2 ms |
2632 KB |
Output is correct |
25 |
Correct |
56 ms |
2588 KB |
Output is correct |
26 |
Correct |
51 ms |
2496 KB |
Output is correct |
27 |
Correct |
2 ms |
2600 KB |
Output is correct |
28 |
Partially correct |
93 ms |
2500 KB |
Partially correct - number of queries: 7428 |
29 |
Partially correct |
74 ms |
2632 KB |
Partially correct - number of queries: 5636 |
30 |
Partially correct |
50 ms |
2632 KB |
Partially correct - number of queries: 7844 |
31 |
Correct |
2 ms |
2576 KB |
Output is correct |
32 |
Correct |
8 ms |
2636 KB |
Output is correct |
33 |
Correct |
2 ms |
2632 KB |
Output is correct |
34 |
Correct |
39 ms |
2572 KB |
Output is correct |
35 |
Correct |
4 ms |
2632 KB |
Output is correct |
36 |
Correct |
10 ms |
2580 KB |
Output is correct |
37 |
Correct |
3 ms |
2624 KB |
Output is correct |
38 |
Correct |
3 ms |
2576 KB |
Output is correct |
39 |
Correct |
46 ms |
2632 KB |
Output is correct |
40 |
Partially correct |
33 ms |
2632 KB |
Partially correct - number of queries: 6730 |
41 |
Correct |
58 ms |
2580 KB |
Output is correct |
42 |
Correct |
56 ms |
2632 KB |
Output is correct |
43 |
Correct |
58 ms |
2632 KB |
Output is correct |
44 |
Correct |
20 ms |
2596 KB |
Output is correct |
45 |
Correct |
25 ms |
2576 KB |
Output is correct |
46 |
Correct |
2 ms |
2496 KB |
Output is correct |
47 |
Correct |
19 ms |
2632 KB |
Output is correct |
48 |
Partially correct |
58 ms |
2496 KB |
Partially correct - number of queries: 5851 |
49 |
Correct |
5 ms |
2592 KB |
Output is correct |
50 |
Partially correct |
37 ms |
2624 KB |
Partially correct - number of queries: 7890 |
51 |
Correct |
19 ms |
2588 KB |
Output is correct |
52 |
Correct |
2 ms |
2588 KB |
Output is correct |
53 |
Correct |
2 ms |
2632 KB |
Output is correct |
54 |
Correct |
18 ms |
2580 KB |
Output is correct |
55 |
Correct |
2 ms |
2604 KB |
Output is correct |
56 |
Partially correct |
73 ms |
2588 KB |
Partially correct - number of queries: 7890 |
57 |
Partially correct |
28 ms |
2588 KB |
Partially correct - number of queries: 5767 |
58 |
Partially correct |
66 ms |
2624 KB |
Partially correct - number of queries: 5839 |
59 |
Correct |
60 ms |
2584 KB |
Output is correct |
60 |
Correct |
59 ms |
2600 KB |
Output is correct |
61 |
Correct |
2 ms |
2600 KB |
Output is correct |
62 |
Correct |
2 ms |
2576 KB |
Output is correct |
63 |
Correct |
3 ms |
2592 KB |
Output is correct |
64 |
Correct |
2 ms |
2624 KB |
Output is correct |
65 |
Correct |
2 ms |
2624 KB |
Output is correct |
66 |
Correct |
7 ms |
2624 KB |
Output is correct |
67 |
Correct |
2 ms |
2592 KB |
Output is correct |
68 |
Correct |
8 ms |
2592 KB |
Output is correct |
69 |
Correct |
7 ms |
2624 KB |
Output is correct |
70 |
Correct |
2 ms |
2624 KB |
Output is correct |
71 |
Partially correct |
108 ms |
2632 KB |
Partially correct - number of queries: 7757 |
72 |
Correct |
9 ms |
2596 KB |
Output is correct |
73 |
Partially correct |
95 ms |
2600 KB |
Partially correct - number of queries: 7648 |
74 |
Partially correct |
83 ms |
2632 KB |
Partially correct - number of queries: 7690 |
75 |
Correct |
4 ms |
2632 KB |
Output is correct |
76 |
Partially correct |
76 ms |
2632 KB |
Partially correct - number of queries: 6628 |
77 |
Partially correct |
78 ms |
2600 KB |
Partially correct - number of queries: 7919 |
78 |
Correct |
8 ms |
2632 KB |
Output is correct |
79 |
Correct |
53 ms |
2608 KB |
Output is correct |
80 |
Partially correct |
89 ms |
2632 KB |
Partially correct - number of queries: 7911 |
81 |
Partially correct |
109 ms |
2596 KB |
Partially correct - number of queries: 7936 |
82 |
Partially correct |
74 ms |
2632 KB |
Partially correct - number of queries: 7882 |
83 |
Correct |
3 ms |
2632 KB |
Output is correct |
84 |
Partially correct |
52 ms |
2632 KB |
Partially correct - number of queries: 6461 |
85 |
Partially correct |
90 ms |
2632 KB |
Partially correct - number of queries: 7913 |
86 |
Partially correct |
58 ms |
2632 KB |
Partially correct - number of queries: 6348 |
87 |
Correct |
7 ms |
2632 KB |
Output is correct |
88 |
Partially correct |
83 ms |
2632 KB |
Partially correct - number of queries: 5979 |
89 |
Partially correct |
87 ms |
2600 KB |
Partially correct - number of queries: 6305 |
90 |
Correct |
2 ms |
2632 KB |
Output is correct |
91 |
Correct |
41 ms |
2632 KB |
Output is correct |
92 |
Correct |
38 ms |
2632 KB |
Output is correct |
93 |
Correct |
8 ms |
2632 KB |
Output is correct |
94 |
Correct |
8 ms |
2636 KB |
Output is correct |
95 |
Correct |
8 ms |
2632 KB |
Output is correct |
96 |
Correct |
6 ms |
2628 KB |
Output is correct |
97 |
Correct |
2 ms |
2632 KB |
Output is correct |