#include<bits/stdc++.h>
using namespace std;
//#include "prize.h"
#include <vector>
int find_best(int n);
std::vector<int> ask(int i);
namespace solver{
map<int,pair<int,int> > mp;
int fin;
pair<int,int> query(int box){
if(box==-1){
return make_pair(0,-111);
}
if(mp.count(box))return mp[box];
cout<<"<script></script>"<<box<<endl;
auto z=ask(box);
if(z[0]==0&&z[1]==0){
fin=box;
}
return mp[box]=make_pair(z[0],z[1]);
}
inline void dfs(int l,int r){
int ex=query(r-1).first-query(l-1).first;
int r_cn=query(r-1).first+query(r-1).second;
int l_cn=query(l-1).first+query(l-1).second;
if(r_cn==l_cn&&query(l-1).first+1==query(r).first)return;
if(l+1==r)return;
if(fin!=-1)return;
dfs(l,(l+r)>>1);
if(fin!=-1)return;
dfs((l+r)>>1,r);
}
int find_best(int n) {
fin=-1;
dfs(0,n);
return fin;
}
}
int find_best(int n) {
return solver::find_best(n);
}
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;
}
Compilation message
prize.cpp: In function 'void solver::dfs(int, int)':
prize.cpp:27:7: warning: unused variable 'ex' [-Wunused-variable]
int ex=query(r-1).first-query(l-1).first;
^~
/tmp/cceyUUq1.o: In function `ask(int)':
grader.cpp:(.text+0x0): multiple definition of `ask(int)'
/tmp/ccyQaPpK.o:prize.cpp:(.text+0x0): first defined here
/tmp/cceyUUq1.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccyQaPpK.o:prize.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status