#include "prize.h"
#include <bits/stdc++.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;
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;
}*/
vector<int> ans[200001];
map<int, set<int> > v;
int L, R;
int find_best(int n) {
L = 0;
R = n - 1;
queue<pair<int, int> > q;
q.push(make_pair(L, R));
int l, r, m;
while(!q.empty()){
l = q.front().first;
r = q.front().second;
q.pop();
cout<<l<<" "<<r<<"\n";
if(L > r || l > R || l > r){
continue;
}
m = (l + r) >> 1;
ans[m] = ask(m);
if(ans[m][0] + ans[m][1] == 0){
return m;
}
v[ans[m][0] + ans[m][1]].insert(m);
auto it = v.find(ans[m][0] + ans[m][1]);
auto loc = it -> second.find(m);
bool in = 0;
auto tmp = loc;
while(tmp != it -> second.begin()){
tmp--;
if(ans[m][0] != ans[*tmp][0]){
in = 1;
tmp++;
q.push(make_pair(l, *tmp));
break;
}
}
if(in == 0){
q.push(make_pair(l, *(it->second.begin())));
} else {
in = 0;
}
tmp = loc;
while(tmp != it -> second.end()){
if(ans[m][0] != ans[*tmp][0]){
in = 1;
tmp--;
q.push(make_pair(*tmp, r));
break;
}
tmp++;
}
if(in == 0){
q.push(make_pair(*(it->second.end()--), r));
}
}
}
/*
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 'int find_best(int)':
prize.cpp:90:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
5024 KB |
Token "0" doesn't correspond to pattern "[A-B]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
5176 KB |
Token "0" doesn't correspond to pattern "[A-B]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |