#include "prize.h"
#include <bits/stdc++.h>
#define MIN -1
#define MAX 1000000000
#define all(a) a.begin (), a.end ()
#define mp make_pair
#define pb push_back
using namespace std;
typedef vector <int> vi;
typedef long long int ll;
typedef pair <int, int> ii;
pair<int, int> v[201000];
bool aux[200100];
pair<int, int> visitado(int pos){
if (aux[pos]){
return v[pos];
}
aux[pos] = 1;
vector <int> v1 = ask(pos);
return v[pos] = {v1[0], v1[1]};
}
int find_best(int n) {
int mx = MIN;
int mxpos = 0;
for (int i = 0; i < min(474, n); i++){
pair<int, int> v = visitado(i);
if (v.first+v.second == 0)
return i;
if (v.first + v.second > mx){
mx = v.first + v.second;
mxpos = i;
}
}
int aux1 = mxpos;
while(1){
int l = aux1+1, r = n;
while(l < r){
int mid = (l+r)/2;
pair<int, int> v = visitado(mid);
if (v.first+v.second == 0)return mid;
if (v != visitado(aux1))
r = mid; else
l = mid+1;
}
aux1 = l;
while(aux1 < n){
if (visitado(aux1).first + visitado(aux1).second == visitado(mxpos).first+visitado(mxpos).second)
break;
if (visitado(aux1).first + visitado(aux1).second == 0)
return aux1;
aux1++;
}
}
}
/*
using namespace std;
static const int max_q = 10000;
static int n;
static int query_count = 0;
static vector<int> g;
static vector<vector<int> > rank_count;
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;
}
int main() {
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 << endl << "Query count: " << query_count << endl;
return 0;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
392 KB |
Output is correct |
2 |
Correct |
4 ms |
392 KB |
Output is correct |
3 |
Correct |
7 ms |
376 KB |
Output is correct |
4 |
Correct |
8 ms |
376 KB |
Output is correct |
5 |
Correct |
7 ms |
308 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
7 ms |
248 KB |
Output is correct |
8 |
Correct |
7 ms |
248 KB |
Output is correct |
9 |
Correct |
4 ms |
396 KB |
Output is correct |
10 |
Correct |
9 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
460 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
392 KB |
Output is correct |
4 |
Correct |
7 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
392 KB |
Output is correct |
6 |
Correct |
2 ms |
320 KB |
Output is correct |
7 |
Correct |
4 ms |
392 KB |
Output is correct |
8 |
Correct |
4 ms |
328 KB |
Output is correct |
9 |
Correct |
7 ms |
332 KB |
Output is correct |
10 |
Correct |
7 ms |
248 KB |
Output is correct |
11 |
Correct |
6 ms |
832 KB |
Output is correct |
12 |
Correct |
5 ms |
520 KB |
Output is correct |
13 |
Correct |
11 ms |
1272 KB |
Output is correct |
14 |
Correct |
10 ms |
376 KB |
Output is correct |
15 |
Correct |
18 ms |
1092 KB |
Output is correct |
16 |
Partially correct |
87 ms |
1840 KB |
Partially correct - number of queries: 7129 |
17 |
Correct |
6 ms |
248 KB |
Output is correct |
18 |
Partially correct |
90 ms |
1972 KB |
Partially correct - number of queries: 8288 |
19 |
Correct |
9 ms |
276 KB |
Output is correct |
20 |
Correct |
26 ms |
888 KB |
Output is correct |
21 |
Correct |
37 ms |
1408 KB |
Output is correct |
22 |
Correct |
13 ms |
908 KB |
Output is correct |
23 |
Correct |
5 ms |
412 KB |
Output is correct |
24 |
Correct |
8 ms |
376 KB |
Output is correct |
25 |
Correct |
50 ms |
1576 KB |
Output is correct |
26 |
Correct |
49 ms |
1656 KB |
Output is correct |
27 |
Correct |
5 ms |
524 KB |
Output is correct |
28 |
Partially correct |
77 ms |
2160 KB |
Partially correct - number of queries: 7836 |
29 |
Partially correct |
47 ms |
2024 KB |
Partially correct - number of queries: 6048 |
30 |
Partially correct |
79 ms |
2016 KB |
Partially correct - number of queries: 8218 |
31 |
Correct |
6 ms |
512 KB |
Output is correct |
32 |
Correct |
12 ms |
1212 KB |
Output is correct |
33 |
Correct |
2 ms |
404 KB |
Output is correct |
34 |
Correct |
18 ms |
1380 KB |
Output is correct |
35 |
Correct |
8 ms |
632 KB |
Output is correct |
36 |
Correct |
23 ms |
1272 KB |
Output is correct |
37 |
Correct |
10 ms |
504 KB |
Output is correct |
38 |
Correct |
7 ms |
376 KB |
Output is correct |
39 |
Correct |
44 ms |
1516 KB |
Output is correct |
40 |
Partially correct |
66 ms |
2048 KB |
Partially correct - number of queries: 7104 |
41 |
Partially correct |
42 ms |
1656 KB |
Partially correct - number of queries: 5155 |
42 |
Partially correct |
46 ms |
1624 KB |
Partially correct - number of queries: 5155 |
43 |
Correct |
39 ms |
1648 KB |
Output is correct |
44 |
Correct |
56 ms |
1528 KB |
Output is correct |
45 |
Correct |
29 ms |
1336 KB |
Output is correct |
46 |
Correct |
6 ms |
396 KB |
Output is correct |
47 |
Correct |
34 ms |
1540 KB |
Output is correct |
48 |
Partially correct |
66 ms |
1704 KB |
Partially correct - number of queries: 6274 |
49 |
Correct |
13 ms |
696 KB |
Output is correct |
50 |
Partially correct |
86 ms |
2100 KB |
Partially correct - number of queries: 8272 |
51 |
Correct |
22 ms |
1596 KB |
Output is correct |
52 |
Correct |
7 ms |
504 KB |
Output is correct |
53 |
Correct |
8 ms |
632 KB |
Output is correct |
54 |
Correct |
45 ms |
1528 KB |
Output is correct |
55 |
Correct |
5 ms |
404 KB |
Output is correct |
56 |
Partially correct |
100 ms |
1980 KB |
Partially correct - number of queries: 8262 |
57 |
Partially correct |
63 ms |
1724 KB |
Partially correct - number of queries: 6161 |
58 |
Partially correct |
35 ms |
1784 KB |
Partially correct - number of queries: 6226 |
59 |
Partially correct |
41 ms |
1588 KB |
Partially correct - number of queries: 5154 |
60 |
Correct |
49 ms |
1624 KB |
Output is correct |
61 |
Correct |
9 ms |
652 KB |
Output is correct |
62 |
Correct |
7 ms |
300 KB |
Output is correct |
63 |
Correct |
5 ms |
652 KB |
Output is correct |
64 |
Correct |
4 ms |
520 KB |
Output is correct |
65 |
Correct |
8 ms |
376 KB |
Output is correct |
66 |
Correct |
13 ms |
404 KB |
Output is correct |
67 |
Correct |
6 ms |
312 KB |
Output is correct |
68 |
Correct |
4 ms |
456 KB |
Output is correct |
69 |
Correct |
14 ms |
376 KB |
Output is correct |
70 |
Correct |
5 ms |
408 KB |
Output is correct |
71 |
Partially correct |
87 ms |
1960 KB |
Partially correct - number of queries: 8285 |
72 |
Correct |
15 ms |
1272 KB |
Output is correct |
73 |
Partially correct |
56 ms |
2040 KB |
Partially correct - number of queries: 8171 |
74 |
Partially correct |
46 ms |
2188 KB |
Partially correct - number of queries: 8205 |
75 |
Correct |
9 ms |
632 KB |
Output is correct |
76 |
Partially correct |
70 ms |
2060 KB |
Partially correct - number of queries: 7105 |
77 |
Partially correct |
65 ms |
2184 KB |
Partially correct - number of queries: 8327 |
78 |
Correct |
14 ms |
1272 KB |
Output is correct |
79 |
Correct |
44 ms |
1960 KB |
Output is correct |
80 |
Partially correct |
83 ms |
2136 KB |
Partially correct - number of queries: 8335 |
81 |
Partially correct |
95 ms |
2040 KB |
Partially correct - number of queries: 8345 |
82 |
Partially correct |
94 ms |
2020 KB |
Partially correct - number of queries: 8247 |
83 |
Correct |
9 ms |
632 KB |
Output is correct |
84 |
Partially correct |
83 ms |
2040 KB |
Partially correct - number of queries: 6870 |
85 |
Partially correct |
46 ms |
2048 KB |
Partially correct - number of queries: 8325 |
86 |
Correct |
6 ms |
376 KB |
Output is correct |
87 |
Correct |
5 ms |
384 KB |
Output is correct |
88 |
Correct |
8 ms |
376 KB |
Output is correct |
89 |
Correct |
6 ms |
376 KB |
Output is correct |
90 |
Correct |
6 ms |
376 KB |
Output is correct |
91 |
Correct |
7 ms |
376 KB |
Output is correct |
92 |
Correct |
7 ms |
376 KB |
Output is correct |
93 |
Correct |
10 ms |
1064 KB |
Output is correct |
94 |
Correct |
14 ms |
1144 KB |
Output is correct |
95 |
Correct |
11 ms |
1020 KB |
Output is correct |
96 |
Correct |
13 ms |
1020 KB |
Output is correct |
97 |
Correct |
8 ms |
376 KB |
Output is correct |