#include "library.h"
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
vector< vector<int> > V;
int n;
int Ask(int L, int R){
vector<int> Q(n, 0);
for(int i = L; i < R; i++)
for(int j : V[i])
Q[j] = 1;
// cerr << "#@$ ";
// for(auto x : Q) cerr << x;
// cerr << " -> " << Query(Q) << '\n';
return Query(Q);
}
bool Nei(int a, int b){
vector<int> Q(n, 0);
Q[a] = 1; Q[b] = 1;
return Query(Q) == 1;
}
int tri(int a, int b, int c){
vector<int> Q(n, 0);
Q[a] = 1; Q[b] = 1; Q[c] = 1;
return Query(Q);
}
void Insert(int i, int j){
assert(i < j);
for(auto x : V[j])
V[i].pb(x);
V[j].clear();
V.erase(V.begin() + j);
}
void Comb(int i, int j){
if(V[i].size() == 1) swap(V[i], V[j]);
if(V[j].size() == 1){
if((V[i].size() == 1) || (Nei(V[j][0], V[i].back()))){
Insert(i, j);
return ;
}
reverse(all(V[i]));
assert(Nei(V[i].back(), V[j][0]));
Insert(i, j);
return ;
}
if(tri(V[i][0], V[j][0], V[j].back()) == 2 - (V[j].size() == 2)) reverse(all(V[i]));
if(!Nei(V[i].back(), V[j][0])) reverse(all(V[j]));
Insert(i, j);
}
void Solve(int _n){
n = _n;
V.resize(n, vector<int>(0));
for(int i = 0; i < n; i++) V[i].pb(i);
int L, R, mid=0;
while((int) V.size() > 1){
// cerr << "! " << V.size() << '\n';
// cerr << "WTF : ";
// for(auto Y : V)
// cerr << Y.size() << ' ';
// cerr << '\n';
L = 1, R = V.size();
while(L + 1 < R){
mid = (L + R) >> 1;
if(Ask(0, mid) < mid) R = mid;
else L = mid;
}
int res = R - 1;
L = 0, R = res;
while(L + 1 < R){
mid = (L + R) >> 1;
if(Ask(mid, res + 1) < (res + 1 - mid)) L = mid;
else R = mid;
}
// cerr << "# " << L << ' ' << res << '\n';
Comb(L, res);
}
for(auto &x : V[0]) x++;
// cerr << "! " << n << ' ' << V[0].size() << '\n';
Answer(V[0]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
388 KB |
# of queries: 2319 |
2 |
Correct |
35 ms |
364 KB |
# of queries: 2339 |
3 |
Correct |
36 ms |
364 KB |
# of queries: 2395 |
4 |
Correct |
37 ms |
492 KB |
# of queries: 2421 |
5 |
Correct |
37 ms |
364 KB |
# of queries: 2441 |
6 |
Correct |
37 ms |
364 KB |
# of queries: 2411 |
7 |
Correct |
51 ms |
364 KB |
# of queries: 2419 |
8 |
Correct |
41 ms |
364 KB |
# of queries: 2305 |
9 |
Correct |
36 ms |
364 KB |
# of queries: 2441 |
10 |
Correct |
20 ms |
364 KB |
# of queries: 1401 |
11 |
Correct |
0 ms |
364 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
364 KB |
# of queries: 0 |
13 |
Correct |
0 ms |
364 KB |
# of queries: 2 |
14 |
Correct |
1 ms |
364 KB |
# of queries: 8 |
15 |
Correct |
2 ms |
364 KB |
# of queries: 78 |
16 |
Correct |
3 ms |
528 KB |
# of queries: 178 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
388 KB |
# of queries: 2319 |
2 |
Correct |
35 ms |
364 KB |
# of queries: 2339 |
3 |
Correct |
36 ms |
364 KB |
# of queries: 2395 |
4 |
Correct |
37 ms |
492 KB |
# of queries: 2421 |
5 |
Correct |
37 ms |
364 KB |
# of queries: 2441 |
6 |
Correct |
37 ms |
364 KB |
# of queries: 2411 |
7 |
Correct |
51 ms |
364 KB |
# of queries: 2419 |
8 |
Correct |
41 ms |
364 KB |
# of queries: 2305 |
9 |
Correct |
36 ms |
364 KB |
# of queries: 2441 |
10 |
Correct |
20 ms |
364 KB |
# of queries: 1401 |
11 |
Correct |
0 ms |
364 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
364 KB |
# of queries: 0 |
13 |
Correct |
0 ms |
364 KB |
# of queries: 2 |
14 |
Correct |
1 ms |
364 KB |
# of queries: 8 |
15 |
Correct |
2 ms |
364 KB |
# of queries: 78 |
16 |
Correct |
3 ms |
528 KB |
# of queries: 178 |
17 |
Correct |
345 ms |
364 KB |
# of queries: 16682 |
18 |
Correct |
336 ms |
364 KB |
# of queries: 16487 |
19 |
Correct |
409 ms |
364 KB |
# of queries: 16676 |
20 |
Correct |
271 ms |
432 KB |
# of queries: 15574 |
21 |
Correct |
288 ms |
364 KB |
# of queries: 14634 |
22 |
Correct |
341 ms |
364 KB |
# of queries: 16695 |
23 |
Correct |
342 ms |
492 KB |
# of queries: 16738 |
24 |
Correct |
135 ms |
492 KB |
# of queries: 7602 |
25 |
Correct |
336 ms |
492 KB |
# of queries: 16290 |
26 |
Correct |
296 ms |
492 KB |
# of queries: 15279 |
27 |
Correct |
111 ms |
364 KB |
# of queries: 7543 |
28 |
Correct |
181 ms |
364 KB |
# of queries: 8977 |
29 |
Correct |
175 ms |
492 KB |
# of queries: 8967 |
30 |
Correct |
175 ms |
364 KB |
# of queries: 8977 |