This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "minerals.h"
#include <iostream>
#include <cstring>
using namespace std;
const int N = 41000, L = 18;
int k;
int Query_(int i) {
int k_ = Query(i + 1);
if (k_ == k)
return 0;
k = k_;
return 1;
}
int tt[N * 2], ii[2][N], ii_[1 << L], nn[2], aa[N], bb[N];
int aaa[L * 2 + 2][1 << L], nn_[L * 2 + 2]; char used[1 << L];
void Solve(int n) {
for (int i = 0; i < n * 2; i++) {
tt[i] = !Query_(i);
ii[tt[i]][nn[tt[i]]++] = i;
}
for (int a = 0; a < 1 << L; a++) {
int k = 0, l_ = -1;
for (int l = 0; l < L; l++)
if ((a >> l & 1) != (l == 0 ? 0 : (a >> l - 1 & 1)))
k++, l_ = l;
int w = a == 0 ? 0 : k + l_ + 2;
aaa[w][nn_[w]++] = a;
}
for (int i = 0, w = 0; i < n; i++) {
while (nn_[w] == 0)
w++;
aa[i] = aaa[w][--nn_[w]];
}
for (int l = 0; l < L; l++) {
for (int i = 0; i < n; i++)
if ((aa[i] >> l & 1) != (l == 0 ? 0 : (aa[i] >> l - 1 & 1)))
Query_(ii[0][i]);
memset(used, 0, (1 << L) * sizeof *used);
for (int i = 0; i < n; i++)
used[aa[i] & (1 << l + 1) - 1] = 1;
for (int i = 0; i < n; i++)
if (!used[bb[i]] || used[bb[i] | 1 << l] && Query_(ii[1][i]))
bb[i] |= 1 << l;
}
for (int i = 0; i < n; i++)
ii_[aa[i]] = ii[0][i];
for (int i = 0; i < n; i++)
Answer(ii_[bb[i]] + 1, ii[1][i] + 1);
}
Compilation message (stderr)
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:29:46: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
29 | if ((a >> l & 1) != (l == 0 ? 0 : (a >> l - 1 & 1)))
| ~~^~~
minerals.cpp:41:54: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
41 | if ((aa[i] >> l & 1) != (l == 0 ? 0 : (aa[i] >> l - 1 & 1)))
| ~~^~~
minerals.cpp:45:25: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
45 | used[aa[i] & (1 << l + 1) - 1] = 1;
| ~~^~~
minerals.cpp:45:30: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
45 | used[aa[i] & (1 << l + 1) - 1] = 1;
| ~~~~~~~~~~~~~^~~
minerals.cpp:47:45: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
47 | if (!used[bb[i]] || used[bb[i] | 1 << l] && Query_(ii[1][i]))
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |