#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ln '\n'
#define MAX 101010
ll rnd[MAX];
vector<ll> A, B; //A is old
ll chk[MAX];
ll rem[MAX];
ll pv = 0;
ll pvv = 0;
ll query(ll x) {
rem[x] = !rem[x];
pv = pvv;
pvv = Query(rnd[x]);
return pvv;
}
void answer(ll x, ll y) {
Answer(rnd[x], rnd[y]);
}
void rnd_gen(ll N) {
ll i;
for (i = 1; i <= 2 * N; i++) rnd[i] = i;
for (i = 2 * N; i > 1; i--) {
ll a = rand() % i + 1;
swap(rnd[i], rnd[a]);
}
}
ll ans[MAX];
ll anschk[MAX];
void Solve(int N) {
srand(77777); //lucky seven
ll i;
rnd_gen(N);
for (i = 1; i <= 2 * N; i++) {
ll res = query(i);
if (res != pv) {
B.push_back(i);
chk[i] = 1;
}
else {
A.push_back(i);
chk[i] = 0;
}
}
for (i = 1; i <= 2 * N; i++) rem[i] = 1;
ll b;
for (b = 15; b >= 1; b--) {
for (i = 0; i < N; i++) {
if (!((1LL << b) & i)) {
if (!rem[B[i]]) query(B[i]);
}
else {
if (rem[B[i]]) query(B[i]);
}
}
for (i = 0; i < N; i++) if (query(A[i]) != pv) ans[i] += (1LL << b);
}
b = 0;
for (i = 0; i < N; i++) {
for (i = 0; i < N; i++) {
if (!((1LL << b) & i)) {
if (!rem[B[i]]) query(B[i]);
}
else {
if (rem[B[i]]) query(B[i]);
}
}
for (i = 0; i < N; i++) {
if (anschk[ans[i]] || anschk[ans[i + 1]]) {
if (anschk[ans[i]]) ans[i]++;
}
else {
if (query(A[i]) != pv) ans[i] += (1LL << b);
anschk[ans[i]] = 1;
}
}
}
for (i = 0; i < N; i++) answer(A[i], B[ans[i]]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
328 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
328 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
328 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
328 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
328 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
328 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
328 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
328 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
328 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |