#include <bits/stdc++.h>
#define pb push_back
#include "prize.h"
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;
//cout<<query_count<<" babag "<<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;
}
*/
const int MAXN = 2e5 + 5;
vector<vector<int> > check(MAXN, vector<int>(2, -1));
vector<int> small(MAXN);
void f(int n, int smallcnt, int l, int r, int cnt){
if(l == r){
small[l] = 1;
return;
}
int mid = (l + r)/2;
int m = -1;
for(int delt = 0; delt <= (r - l + 1)/2 + 1; delt++){
if(mid + delt <= r){
if(check[mid + delt][0] == -1) check[mid + delt] = ask(mid + delt);
if(check[mid + delt][0] + check[mid + delt][1] == smallcnt){
m = mid + delt;
break;
}
else{
small[mid + delt] = 1;
}
}
if(mid - delt >= l){
if(check[mid - delt][0] == -1) check[mid - delt] = ask(mid - delt);
if(check[mid - delt][0] + check[mid - delt][1] == smallcnt){
m = mid - delt;
break;
}
else{
small[mid - delt] = 1;
}
}
}
if(m == -1) return; // aralıktaki herkes small ve tagledik
if(l > 0 && check[l-1][0] == -1) check[l-1] = ask(l-1);
if(r < n-1 && check[r+1][0] == -1) check[r+1] = ask(r+1);
int solcnt = check[m][0] - (l > 0 ? check[l-1][0] : 0);
int sagcnt = check[m][1] - (r < n-1 ? check[r+1][1] : 0);
if(l <= m-1 && solcnt > 0){
f(n, smallcnt, l, m-1, solcnt);
}
if(m+1 <= r && sagcnt > 0){
f(n, smallcnt, m+1, r, sagcnt);
}
}
int find_best(int n) {
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int smallcnt = 0;
int kok = min(475, n);
for(int i = 0; i < kok; i++){
check[i] = ask(i);
smallcnt = max(smallcnt, check[i][0] + check[i][1]);
if(smallcnt > 30) break;
}
f(n, smallcnt, 0, n-1, smallcnt);
int ans = -1;
for(int i = 0; i < n; i++){
if(small[i] == 1){
if(check[i][0] == -1) check[i] = ask(i);
if(check[i][0] + check[i][1] == 0){
ans = i;
break;
}
}
}
return ans;
}
/*
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;
}
*/
/*
int main() {
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mx = 0;
int t;
cin>>t;
while(t--){
//cin>>n;
//n = rng() % 55 + 7;
n = 2e5 - rng() % 5000;
g.resize(n);
vector<int> cnts(3);
cnts[0] = 1;
cnts[1] = 3;
cnts[2] = rng()%10 + 10;
cnts[3] = rng()%20 + 400;
cnts[4] = n - cnts[3] - cnts[2] - cnts[1] - cnts[0];
for(int i = 0; i < n; i++){
small[i] = 0;
check[i][0] = check[i][1] = -1;
}
int ind = 0;
for(int i = 0; i < n; i++){
if(cnts[ind] == 0) ind++;
g[i] = ind + 1;
cnts[ind]--;
}
shuffle(g.begin(), g.end(), rng);
for(int i = 0; i < n; 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.clear();
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);
if(res == -1 || query_count > max_q){
cout << res << endl << "Query count: " << query_count << endl;
}
mx = max(mx, query_count);
query_count = 0;
}
cout<<mx<<endl;
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
12112 KB |
Output is correct |
2 |
Correct |
17 ms |
12112 KB |
Output is correct |
3 |
Correct |
18 ms |
12112 KB |
Output is correct |
4 |
Correct |
17 ms |
12112 KB |
Output is correct |
5 |
Correct |
20 ms |
12052 KB |
Output is correct |
6 |
Correct |
19 ms |
12112 KB |
Output is correct |
7 |
Correct |
21 ms |
12112 KB |
Output is correct |
8 |
Correct |
19 ms |
12112 KB |
Output is correct |
9 |
Correct |
22 ms |
12072 KB |
Output is correct |
10 |
Correct |
18 ms |
12112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
12112 KB |
Output is correct |
2 |
Correct |
18 ms |
12112 KB |
Output is correct |
3 |
Correct |
18 ms |
12368 KB |
Output is correct |
4 |
Correct |
21 ms |
12188 KB |
Output is correct |
5 |
Correct |
16 ms |
12112 KB |
Output is correct |
6 |
Correct |
17 ms |
12112 KB |
Output is correct |
7 |
Correct |
16 ms |
12112 KB |
Output is correct |
8 |
Correct |
17 ms |
12112 KB |
Output is correct |
9 |
Correct |
21 ms |
12112 KB |
Output is correct |
10 |
Correct |
17 ms |
12112 KB |
Output is correct |
11 |
Correct |
17 ms |
12112 KB |
Output is correct |
12 |
Correct |
17 ms |
12112 KB |
Output is correct |
13 |
Correct |
17 ms |
12112 KB |
Output is correct |
14 |
Correct |
26 ms |
12112 KB |
Output is correct |
15 |
Correct |
78 ms |
12176 KB |
Output is correct |
16 |
Correct |
91 ms |
12112 KB |
Output is correct |
17 |
Correct |
102 ms |
12176 KB |
Output is correct |
18 |
Correct |
91 ms |
12112 KB |
Output is correct |
19 |
Correct |
82 ms |
12172 KB |
Output is correct |
20 |
Correct |
53 ms |
12284 KB |
Output is correct |
21 |
Correct |
83 ms |
12112 KB |
Output is correct |
22 |
Correct |
75 ms |
12112 KB |
Output is correct |
23 |
Correct |
21 ms |
12112 KB |
Output is correct |
24 |
Correct |
20 ms |
12112 KB |
Output is correct |
25 |
Correct |
90 ms |
12176 KB |
Output is correct |
26 |
Correct |
94 ms |
12112 KB |
Output is correct |
27 |
Correct |
25 ms |
12104 KB |
Output is correct |
28 |
Correct |
84 ms |
12112 KB |
Output is correct |
29 |
Correct |
84 ms |
12112 KB |
Output is correct |
30 |
Correct |
104 ms |
12112 KB |
Output is correct |
31 |
Correct |
89 ms |
12172 KB |
Output is correct |
32 |
Correct |
18 ms |
12124 KB |
Output is correct |
33 |
Correct |
12 ms |
12112 KB |
Output is correct |
34 |
Correct |
108 ms |
12176 KB |
Output is correct |
35 |
Correct |
20 ms |
12112 KB |
Output is correct |
36 |
Correct |
92 ms |
12180 KB |
Output is correct |
37 |
Correct |
16 ms |
12112 KB |
Output is correct |
38 |
Correct |
20 ms |
12112 KB |
Output is correct |
39 |
Correct |
92 ms |
12172 KB |
Output is correct |
40 |
Correct |
85 ms |
12112 KB |
Output is correct |
41 |
Correct |
90 ms |
12112 KB |
Output is correct |
42 |
Correct |
90 ms |
12176 KB |
Output is correct |
43 |
Correct |
99 ms |
12112 KB |
Output is correct |
44 |
Correct |
100 ms |
12112 KB |
Output is correct |
45 |
Correct |
89 ms |
12364 KB |
Output is correct |
46 |
Correct |
99 ms |
12112 KB |
Output is correct |
47 |
Correct |
89 ms |
12112 KB |
Output is correct |
48 |
Correct |
90 ms |
12112 KB |
Output is correct |
49 |
Correct |
90 ms |
12112 KB |
Output is correct |
50 |
Correct |
92 ms |
12112 KB |
Output is correct |
51 |
Correct |
98 ms |
12180 KB |
Output is correct |
52 |
Correct |
92 ms |
12112 KB |
Output is correct |
53 |
Correct |
22 ms |
11972 KB |
Output is correct |
54 |
Correct |
102 ms |
12180 KB |
Output is correct |
55 |
Correct |
101 ms |
12196 KB |
Output is correct |
56 |
Correct |
89 ms |
12112 KB |
Output is correct |
57 |
Correct |
101 ms |
12112 KB |
Output is correct |
58 |
Correct |
99 ms |
12176 KB |
Output is correct |
59 |
Correct |
108 ms |
12028 KB |
Output is correct |
60 |
Correct |
102 ms |
12112 KB |
Output is correct |
61 |
Correct |
22 ms |
12112 KB |
Output is correct |
62 |
Correct |
21 ms |
12112 KB |
Output is correct |
63 |
Correct |
25 ms |
12136 KB |
Output is correct |
64 |
Correct |
24 ms |
12360 KB |
Output is correct |
65 |
Correct |
13 ms |
12148 KB |
Output is correct |
66 |
Correct |
18 ms |
12112 KB |
Output is correct |
67 |
Correct |
18 ms |
12112 KB |
Output is correct |
68 |
Correct |
17 ms |
12112 KB |
Output is correct |
69 |
Correct |
18 ms |
12368 KB |
Output is correct |
70 |
Correct |
16 ms |
12112 KB |
Output is correct |
71 |
Correct |
111 ms |
12172 KB |
Output is correct |
72 |
Correct |
18 ms |
12112 KB |
Output is correct |
73 |
Correct |
96 ms |
12112 KB |
Output is correct |
74 |
Correct |
109 ms |
12112 KB |
Output is correct |
75 |
Correct |
17 ms |
12112 KB |
Output is correct |
76 |
Correct |
88 ms |
12180 KB |
Output is correct |
77 |
Correct |
93 ms |
12180 KB |
Output is correct |
78 |
Correct |
18 ms |
12112 KB |
Output is correct |
79 |
Correct |
52 ms |
12076 KB |
Output is correct |
80 |
Correct |
98 ms |
12184 KB |
Output is correct |
81 |
Correct |
95 ms |
12112 KB |
Output is correct |
82 |
Correct |
98 ms |
12112 KB |
Output is correct |
83 |
Correct |
17 ms |
12176 KB |
Output is correct |
84 |
Correct |
86 ms |
12112 KB |
Output is correct |
85 |
Correct |
89 ms |
12112 KB |
Output is correct |
86 |
Correct |
21 ms |
12112 KB |
Output is correct |
87 |
Correct |
11 ms |
12136 KB |
Output is correct |
88 |
Correct |
23 ms |
12112 KB |
Output is correct |
89 |
Correct |
26 ms |
12112 KB |
Output is correct |
90 |
Correct |
20 ms |
12112 KB |
Output is correct |
91 |
Correct |
16 ms |
12112 KB |
Output is correct |
92 |
Correct |
18 ms |
12112 KB |
Output is correct |
93 |
Correct |
20 ms |
12112 KB |
Output is correct |
94 |
Correct |
25 ms |
12112 KB |
Output is correct |
95 |
Correct |
26 ms |
12128 KB |
Output is correct |
96 |
Correct |
24 ms |
12192 KB |
Output is correct |
97 |
Correct |
18 ms |
12112 KB |
Output is correct |