#include "minerals.h"
#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
using namespace std;
typedef pair<int, int> pii;
mt19937 mtrd(time(0));
const int MAXN = 100055;
bitset<MAXN> chk;
int ask(int c) {
chk[c] = !chk[c];
return Query(c);
}
vector<pii> AnsV;
int Delta;
void solve(vector<int> A, vector<int> B) {
int N = sz(A), M = N >> 1, K = N-M;
if(N < 1) return;
if(1 == N) {
AnsV.eb(A[0], B[0]);
if(chk[A[0]] || chk[B[0]]) Delta++;
return;
}
shuffle(allv(A), mtrd);
shuffle(allv(B), mtrd);
vector<int> AL, AR, BL, BR;
if(!chk[A[0]] && !chk[B[0]]) { // off off
if(2 == N) {
ask(A[0]);
int ret = ask(B[0]) - Delta;
if(1 == ret) {
AnsV.eb(A[0], B[0]);
AnsV.eb(A[1], B[1]);
Delta += 1;
} else {
AnsV.eb(A[0], B[1]);
AnsV.eb(A[1], B[0]);
Delta += 2;
}
return;
}
for(int i = 0; i < M; i++) {
ask(A[i]);
AL.eb(A[i]);
}
for(int i = M; i < N; i++) AR.eb(A[i]);
{
int i = 0, h = M;
for(int v, ret; sz(BL) < M && sz(BR) < K; i++) {
v = B[i];
ret = ask(v) - Delta;
if(h == ret) {
BL.eb(v);
} else {
BR.eb(v);
}
h = ret;
}
if(sz(BL) == M) {
if(sz(BR) < K - sz(BR)) {
for(int v : BR) ask(v);
} else {
for(int j = i; j < N; j++) ask(B[j]);
}
for(int j = i; j < N; j++) BR.eb(B[j]);
} else {
if(sz(BL) < M - sz(BL)) {
for(int v : BL) ask(v);
} else {
for(int j = i; j < N; j++) ask(B[j]);
}
for(int j = i; j < N; j++) BL.eb(B[j]);
}
}
if(chk[BR[0]]) Delta += K;
solve(AL, BL);
if(chk[BR[0]]) Delta -= K;
solve(AR, BR);
} else if(!chk[A[0]] && chk[B[0]]) { // off on
solve(B, A);
return;
} else if(!chk[B[0]]) { // on off
if(2 == N) {
ask(A[0]);
int ret = ask(B[0]) - Delta;
if(2 == ret) {
AnsV.eb(A[0], B[0]);
AnsV.eb(A[1], B[1]);
Delta += 2;
} else {
AnsV.eb(A[0], B[1]);
AnsV.eb(A[1], B[0]);
Delta += 1;
}
return;
}
for(int i = 0; i < M; i++) AL.eb(A[i]);
for(int i = M; i < N; i++) {
ask(A[i]);
AR.eb(A[i]);
}
{
int i = 0, h = M;
for(int v, ret; sz(BL) < M && sz(BR) < K; i++) {
v = B[i];
ret = ask(v) - Delta;
if(h == ret) {
BL.eb(v);
} else {
BR.eb(v);
}
h = ret;
}
if(sz(BL) == M) {
if(sz(BR) < K - sz(BR)) {
for(int v : BR) ask(v);
} else {
for(int j = i; j < N; j++) ask(B[j]);
}
for(int j = i; j < N; j++) BR.eb(B[j]);
} else {
if(sz(BL) < M - sz(BL)) {
for(int v : BL) ask(v);
} else {
for(int j = i; j < N; j++) ask(B[j]);
}
for(int j = i; j < N; j++) BL.eb(B[j]);
}
}
if(chk[BR[0]]) Delta += K;
solve(AL, BL);
if(chk[BR[0]]) Delta -= K;
solve(AR, BR);
} else { // on on
if(2 == N) {
ask(A[0]);
int ret = ask(B[0]) - Delta;
if(1 == ret) {
AnsV.eb(A[0], B[0]);
AnsV.eb(A[1], B[1]);
Delta += 1;
} else {
AnsV.eb(A[0], B[1]);
AnsV.eb(A[1], B[0]);
Delta += 2;
}
return;
}
for(int i = 0; i < M; i++) AL.eb(A[i]);
for(int i = M; i < N; i++) {
ask(A[i]);
AR.eb(A[i]);
}
{
int i = 0, h = N;
for(int v, ret; sz(BL) < M && sz(BR) < K; i++) {
v = B[i];
ret = ask(v) - Delta;
if(ret == h) {
BL.eb(v);
} else {
BR.eb(v);
}
h = ret;
}
if(sz(BL) == M) {
if(sz(BR) < K - sz(BR)) {
for(int v : BR) ask(v);
} else {
for(int j = i; j < N; j++) ask(B[j]);
}
for(int j = i; j < N; j++) BR.eb(B[j]);
} else {
if(sz(BL) < M - sz(BL)) {
for(int v : BL) ask(v);
} else {
for(int j = i; j < N; j++) ask(B[j]);
}
for(int j = i; j < N; j++) BL.eb(B[j]);
}
}
if(chk[BR[0]]) Delta += K;
solve(AL, BL);
if(chk[BR[0]]) Delta -= K;
solve(AR, BR);
}
}
void Solve(int N) {
{
vector<int> O, A, B;
for(int i = 1; i <= N*2; i++) O.eb(i);
shuffle(allv(O), mtrd);
int oi = 0, h = 0;
for(int i, ret; h < N && oi < N*2; oi++) {
i = O[oi];
ret = ask(i);
if(ret == h) {
B.eb(i);
} else {
A.eb(i);
}
h = ret;
}
if(N+N - oi < oi - N) {
for(int i = oi; i < N*2; i++) ask(O[i]);
} else {
for(int v : B) ask(v);
}
for(int i = oi; i < N*2; i++) B.eb(O[i]);
solve(A, B);
}
for(auto &v : AnsV) Answer(v.first, v.second);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
9 ms |
640 KB |
Output is correct |
4 |
Correct |
16 ms |
1152 KB |
Output is correct |
5 |
Correct |
31 ms |
1664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
9 ms |
640 KB |
Output is correct |
8 |
Correct |
16 ms |
1152 KB |
Output is correct |
9 |
Correct |
31 ms |
1664 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
22 ms |
1424 KB |
Output is correct |
12 |
Correct |
32 ms |
1712 KB |
Output is correct |
13 |
Correct |
31 ms |
1664 KB |
Output is correct |
14 |
Correct |
31 ms |
1540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
9 ms |
640 KB |
Output is correct |
8 |
Correct |
16 ms |
1152 KB |
Output is correct |
9 |
Correct |
31 ms |
1664 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
22 ms |
1424 KB |
Output is correct |
12 |
Correct |
32 ms |
1712 KB |
Output is correct |
13 |
Correct |
31 ms |
1664 KB |
Output is correct |
14 |
Correct |
31 ms |
1540 KB |
Output is correct |
15 |
Correct |
93 ms |
3888 KB |
Output is correct |
16 |
Correct |
91 ms |
3948 KB |
Output is correct |
17 |
Correct |
90 ms |
3964 KB |
Output is correct |
18 |
Correct |
88 ms |
3744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
9 ms |
640 KB |
Output is correct |
8 |
Correct |
16 ms |
1152 KB |
Output is correct |
9 |
Correct |
31 ms |
1664 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
22 ms |
1424 KB |
Output is correct |
12 |
Correct |
32 ms |
1712 KB |
Output is correct |
13 |
Correct |
31 ms |
1664 KB |
Output is correct |
14 |
Correct |
31 ms |
1540 KB |
Output is correct |
15 |
Correct |
93 ms |
3888 KB |
Output is correct |
16 |
Correct |
91 ms |
3948 KB |
Output is correct |
17 |
Correct |
90 ms |
3964 KB |
Output is correct |
18 |
Correct |
88 ms |
3744 KB |
Output is correct |
19 |
Correct |
93 ms |
4012 KB |
Output is correct |
20 |
Correct |
100 ms |
3984 KB |
Output is correct |
21 |
Correct |
90 ms |
4136 KB |
Output is correct |
22 |
Correct |
94 ms |
3956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
9 ms |
640 KB |
Output is correct |
8 |
Correct |
16 ms |
1152 KB |
Output is correct |
9 |
Correct |
31 ms |
1664 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
22 ms |
1424 KB |
Output is correct |
12 |
Correct |
32 ms |
1712 KB |
Output is correct |
13 |
Correct |
31 ms |
1664 KB |
Output is correct |
14 |
Correct |
31 ms |
1540 KB |
Output is correct |
15 |
Correct |
93 ms |
3888 KB |
Output is correct |
16 |
Correct |
91 ms |
3948 KB |
Output is correct |
17 |
Correct |
90 ms |
3964 KB |
Output is correct |
18 |
Correct |
88 ms |
3744 KB |
Output is correct |
19 |
Correct |
93 ms |
4012 KB |
Output is correct |
20 |
Correct |
100 ms |
3984 KB |
Output is correct |
21 |
Correct |
90 ms |
4136 KB |
Output is correct |
22 |
Correct |
94 ms |
3956 KB |
Output is correct |
23 |
Correct |
110 ms |
4128 KB |
Output is correct |
24 |
Correct |
103 ms |
4132 KB |
Output is correct |
25 |
Correct |
99 ms |
4252 KB |
Output is correct |
26 |
Correct |
94 ms |
3880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
9 ms |
640 KB |
Output is correct |
8 |
Correct |
16 ms |
1152 KB |
Output is correct |
9 |
Correct |
31 ms |
1664 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
22 ms |
1424 KB |
Output is correct |
12 |
Correct |
32 ms |
1712 KB |
Output is correct |
13 |
Correct |
31 ms |
1664 KB |
Output is correct |
14 |
Correct |
31 ms |
1540 KB |
Output is correct |
15 |
Correct |
93 ms |
3888 KB |
Output is correct |
16 |
Correct |
91 ms |
3948 KB |
Output is correct |
17 |
Correct |
90 ms |
3964 KB |
Output is correct |
18 |
Correct |
88 ms |
3744 KB |
Output is correct |
19 |
Correct |
93 ms |
4012 KB |
Output is correct |
20 |
Correct |
100 ms |
3984 KB |
Output is correct |
21 |
Correct |
90 ms |
4136 KB |
Output is correct |
22 |
Correct |
94 ms |
3956 KB |
Output is correct |
23 |
Correct |
110 ms |
4128 KB |
Output is correct |
24 |
Correct |
103 ms |
4132 KB |
Output is correct |
25 |
Correct |
99 ms |
4252 KB |
Output is correct |
26 |
Correct |
94 ms |
3880 KB |
Output is correct |
27 |
Incorrect |
98 ms |
4100 KB |
Wrong Answer [2] |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
9 ms |
640 KB |
Output is correct |
8 |
Correct |
16 ms |
1152 KB |
Output is correct |
9 |
Correct |
31 ms |
1664 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
22 ms |
1424 KB |
Output is correct |
12 |
Correct |
32 ms |
1712 KB |
Output is correct |
13 |
Correct |
31 ms |
1664 KB |
Output is correct |
14 |
Correct |
31 ms |
1540 KB |
Output is correct |
15 |
Correct |
93 ms |
3888 KB |
Output is correct |
16 |
Correct |
91 ms |
3948 KB |
Output is correct |
17 |
Correct |
90 ms |
3964 KB |
Output is correct |
18 |
Correct |
88 ms |
3744 KB |
Output is correct |
19 |
Correct |
93 ms |
4012 KB |
Output is correct |
20 |
Correct |
100 ms |
3984 KB |
Output is correct |
21 |
Correct |
90 ms |
4136 KB |
Output is correct |
22 |
Correct |
94 ms |
3956 KB |
Output is correct |
23 |
Correct |
110 ms |
4128 KB |
Output is correct |
24 |
Correct |
103 ms |
4132 KB |
Output is correct |
25 |
Correct |
99 ms |
4252 KB |
Output is correct |
26 |
Correct |
94 ms |
3880 KB |
Output is correct |
27 |
Incorrect |
98 ms |
4100 KB |
Wrong Answer [2] |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
9 ms |
640 KB |
Output is correct |
8 |
Correct |
16 ms |
1152 KB |
Output is correct |
9 |
Correct |
31 ms |
1664 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
22 ms |
1424 KB |
Output is correct |
12 |
Correct |
32 ms |
1712 KB |
Output is correct |
13 |
Correct |
31 ms |
1664 KB |
Output is correct |
14 |
Correct |
31 ms |
1540 KB |
Output is correct |
15 |
Correct |
93 ms |
3888 KB |
Output is correct |
16 |
Correct |
91 ms |
3948 KB |
Output is correct |
17 |
Correct |
90 ms |
3964 KB |
Output is correct |
18 |
Correct |
88 ms |
3744 KB |
Output is correct |
19 |
Correct |
93 ms |
4012 KB |
Output is correct |
20 |
Correct |
100 ms |
3984 KB |
Output is correct |
21 |
Correct |
90 ms |
4136 KB |
Output is correct |
22 |
Correct |
94 ms |
3956 KB |
Output is correct |
23 |
Correct |
110 ms |
4128 KB |
Output is correct |
24 |
Correct |
103 ms |
4132 KB |
Output is correct |
25 |
Correct |
99 ms |
4252 KB |
Output is correct |
26 |
Correct |
94 ms |
3880 KB |
Output is correct |
27 |
Incorrect |
98 ms |
4100 KB |
Wrong Answer [2] |
28 |
Halted |
0 ms |
0 KB |
- |