/// In The Name Of God
#include <bits/stdc++.h>
#ifndef IOI2018
#include "prize.h"
#endif
#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define nl '\n'
#define ioi exit(0);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
using namespace std;
namespace com {
static const int max_q = 10000;
static int n;
static int query_count = 0;
static vector<int> g;
static vector<vector<int> > rank_count;
}
namespace grader {
using namespace com;
vector<int> ask(int i) {
query_count++;
if(query_count > max_q) {
cerr << "Query limit exceeded" << endl;
exit(0);
}
if(i < 0 || i >= n) {
cerr << "Bad index: " << i << endl;
exit(0);
}
vector<int> res(2);
res[0] = rank_count[g[i] - 1][i + 1];
res[1] = rank_count[g[i] - 1][n] - res[0];
return res;
}
}
#ifdef IOI2018
using namespace grader;
#endif
int solve(int p, int n) {
while (p < n) {
int l = p + 1, r = n - 1, res = p;
vector <int> cur = ask(p);
while (l <= r) {
int mid = l + r >> 1;
vector <int> now = ask(mid);
if ((now[0] + now[1] == cur[0] + cur[1]) && now[0] == cur[0]) {
res = mid, l = mid + 1;
}
else r = mid - 1;
}
++res;
while (res < n) {
vector <int> now = ask(res);
if (!max(now[0], now[1])) return res;
if (now[0] + now[1] == cur[0] + cur[1]) break;
++res;
}
p = res;
}
assert(0);
}
int find_best(int n) {
int mx = -1, p = -1;
rep(i, 0, min(500, n)) {
#ifndef IOI2018
vector <int> a = ask(i);
#endif
#ifdef IOI2018
vector <int> a = grader :: ask(i);
#endif
if (a[0] + a[1] == 0) return i;
if (a[0] + a[1] > mx) {
mx = a[0] + a[1];
p = i;
}
if (mx >= 52) break;
}
return solve(p, n);
}
namespace read {
using namespace com;
void read() {
cin >> n;
g.resize(n);
for(int i = 0; i < n; i++) {
cin >> g[i];
if(g[i] < 1) {
cerr << "Invalid rank " << g[i] << " at index " << i << endl;
exit(0);
}
}
int max_rank = *max_element(g.begin(), g.end());
rank_count.resize(max_rank + 1, vector<int>(n + 1, 0));
for(int r = 0; r <= max_rank; r++) {
for(int i = 1; i <= n; i++) {
rank_count[r][i] = rank_count[r][i - 1];
if(g[i - 1] == r)
rank_count[r][i]++;
}
}
for(int i = 0; i <= n; i++)
for(int r = 1; r <= max_rank; r++)
rank_count[r][i] += rank_count[r - 1][i];
int res = find_best(n);
cout << res;
ioi
cout << res << endl << "Query count: " << query_count << endl;
ioi
}
}
#ifdef IOI2018
int main() {
#ifdef IOI2018
freopen ("in.txt", "r", stdin);
freopen ("D.out", "w", stdout);
#endif
read :: read();
}
#endif
Compilation message
prize.cpp: In function 'int solve(int, int)':
prize.cpp:79:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
256 KB |
Output is correct |
2 |
Correct |
8 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
256 KB |
Output is correct |
4 |
Correct |
6 ms |
256 KB |
Output is correct |
5 |
Correct |
7 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
404 KB |
Output is correct |
7 |
Correct |
6 ms |
304 KB |
Output is correct |
8 |
Correct |
5 ms |
504 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
8 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
396 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
8 ms |
256 KB |
Output is correct |
8 |
Correct |
7 ms |
304 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
4 ms |
392 KB |
Output is correct |
13 |
Correct |
11 ms |
256 KB |
Output is correct |
14 |
Correct |
6 ms |
256 KB |
Output is correct |
15 |
Correct |
6 ms |
396 KB |
Output is correct |
16 |
Partially correct |
57 ms |
256 KB |
Partially correct - number of queries: 7724 |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Partially correct |
70 ms |
384 KB |
Partially correct - number of queries: 9081 |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
24 ms |
256 KB |
Output is correct |
21 |
Correct |
33 ms |
384 KB |
Output is correct |
22 |
Correct |
7 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
512 KB |
Output is correct |
24 |
Correct |
4 ms |
312 KB |
Output is correct |
25 |
Partially correct |
37 ms |
396 KB |
Partially correct - number of queries: 5126 |
26 |
Partially correct |
38 ms |
256 KB |
Partially correct - number of queries: 5040 |
27 |
Correct |
5 ms |
304 KB |
Output is correct |
28 |
Partially correct |
64 ms |
256 KB |
Partially correct - number of queries: 8611 |
29 |
Partially correct |
26 ms |
376 KB |
Partially correct - number of queries: 6539 |
30 |
Partially correct |
31 ms |
396 KB |
Partially correct - number of queries: 9020 |
31 |
Correct |
3 ms |
376 KB |
Output is correct |
32 |
Correct |
11 ms |
256 KB |
Output is correct |
33 |
Correct |
2 ms |
256 KB |
Output is correct |
34 |
Correct |
11 ms |
304 KB |
Output is correct |
35 |
Correct |
8 ms |
256 KB |
Output is correct |
36 |
Correct |
20 ms |
384 KB |
Output is correct |
37 |
Correct |
9 ms |
384 KB |
Output is correct |
38 |
Correct |
6 ms |
312 KB |
Output is correct |
39 |
Correct |
27 ms |
256 KB |
Output is correct |
40 |
Partially correct |
50 ms |
256 KB |
Partially correct - number of queries: 7706 |
41 |
Partially correct |
36 ms |
256 KB |
Partially correct - number of queries: 5418 |
42 |
Partially correct |
23 ms |
376 KB |
Partially correct - number of queries: 5418 |
43 |
Correct |
26 ms |
284 KB |
Output is correct |
44 |
Correct |
34 ms |
312 KB |
Output is correct |
45 |
Correct |
35 ms |
256 KB |
Output is correct |
46 |
Correct |
3 ms |
256 KB |
Output is correct |
47 |
Correct |
25 ms |
384 KB |
Output is correct |
48 |
Partially correct |
42 ms |
428 KB |
Partially correct - number of queries: 6701 |
49 |
Correct |
8 ms |
308 KB |
Output is correct |
50 |
Partially correct |
36 ms |
256 KB |
Partially correct - number of queries: 9078 |
51 |
Correct |
29 ms |
384 KB |
Output is correct |
52 |
Correct |
2 ms |
308 KB |
Output is correct |
53 |
Correct |
8 ms |
256 KB |
Output is correct |
54 |
Correct |
31 ms |
304 KB |
Output is correct |
55 |
Correct |
3 ms |
308 KB |
Output is correct |
56 |
Partially correct |
47 ms |
308 KB |
Partially correct - number of queries: 9080 |
57 |
Partially correct |
23 ms |
308 KB |
Partially correct - number of queries: 6619 |
58 |
Partially correct |
29 ms |
256 KB |
Partially correct - number of queries: 6732 |
59 |
Partially correct |
44 ms |
256 KB |
Partially correct - number of queries: 5418 |
60 |
Partially correct |
36 ms |
264 KB |
Partially correct - number of queries: 5029 |
61 |
Correct |
4 ms |
384 KB |
Output is correct |
62 |
Correct |
6 ms |
256 KB |
Output is correct |
63 |
Correct |
5 ms |
256 KB |
Output is correct |
64 |
Correct |
7 ms |
384 KB |
Output is correct |
65 |
Correct |
4 ms |
376 KB |
Output is correct |
66 |
Correct |
7 ms |
384 KB |
Output is correct |
67 |
Correct |
2 ms |
512 KB |
Output is correct |
68 |
Correct |
4 ms |
384 KB |
Output is correct |
69 |
Correct |
3 ms |
384 KB |
Output is correct |
70 |
Correct |
2 ms |
256 KB |
Output is correct |
71 |
Partially correct |
62 ms |
256 KB |
Partially correct - number of queries: 9205 |
72 |
Correct |
11 ms |
256 KB |
Output is correct |
73 |
Partially correct |
58 ms |
384 KB |
Partially correct - number of queries: 9084 |
74 |
Partially correct |
58 ms |
284 KB |
Partially correct - number of queries: 9131 |
75 |
Correct |
5 ms |
256 KB |
Output is correct |
76 |
Partially correct |
60 ms |
384 KB |
Partially correct - number of queries: 7859 |
77 |
Partially correct |
59 ms |
256 KB |
Partially correct - number of queries: 9098 |
78 |
Correct |
6 ms |
396 KB |
Output is correct |
79 |
Correct |
15 ms |
512 KB |
Output is correct |
80 |
Partially correct |
64 ms |
384 KB |
Partially correct - number of queries: 9086 |
81 |
Partially correct |
58 ms |
256 KB |
Partially correct - number of queries: 9082 |
82 |
Partially correct |
67 ms |
384 KB |
Partially correct - number of queries: 9043 |
83 |
Correct |
8 ms |
256 KB |
Output is correct |
84 |
Partially correct |
61 ms |
256 KB |
Partially correct - number of queries: 7405 |
85 |
Partially correct |
83 ms |
256 KB |
Partially correct - number of queries: 9081 |
86 |
Correct |
4 ms |
384 KB |
Output is correct |
87 |
Correct |
8 ms |
428 KB |
Output is correct |
88 |
Correct |
6 ms |
384 KB |
Output is correct |
89 |
Correct |
6 ms |
384 KB |
Output is correct |
90 |
Correct |
5 ms |
412 KB |
Output is correct |
91 |
Correct |
6 ms |
256 KB |
Output is correct |
92 |
Correct |
5 ms |
256 KB |
Output is correct |
93 |
Correct |
10 ms |
304 KB |
Output is correct |
94 |
Correct |
10 ms |
256 KB |
Output is correct |
95 |
Correct |
9 ms |
384 KB |
Output is correct |
96 |
Correct |
8 ms |
256 KB |
Output is correct |
97 |
Correct |
5 ms |
384 KB |
Output is correct |