이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* https://www.ioi-jp.org/camp/2019/2019-sp-tasks/day4/minerals-review.pdf */
#include "minerals.h"
#include <cstring>
const int N = 43000, L = 19;
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], kk[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(kk, 0, (1 << L) * sizeof *kk);
for (int i = 0; i < n; i++)
kk[aa[i] & (1 << l + 1) - 1]++;
for (int i = 0; i < n; i++) {
if (kk[bb[i]] == 0 || kk[bb[i] | 1 << l] != 0 && Query_(ii[1][i]))
bb[i] |= 1 << l;
kk[bb[i]]--;
}
}
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);
}
컴파일 시 표준 에러 (stderr) 메시지
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:28:46: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
28 | if ((a >> l & 1) != (l == 0 ? 0 : (a >> l - 1 & 1)))
| ~~^~~
minerals.cpp:40:54: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
40 | if ((aa[i] >> l & 1) != (l == 0 ? 0 : (aa[i] >> l - 1 & 1)))
| ~~^~~
minerals.cpp:44:23: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
44 | kk[aa[i] & (1 << l + 1) - 1]++;
| ~~^~~
minerals.cpp:44:28: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
44 | kk[aa[i] & (1 << l + 1) - 1]++;
| ~~~~~~~~~~~~~^~~
minerals.cpp:46:50: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
46 | if (kk[bb[i]] == 0 || kk[bb[i] | 1 << l] != 0 && 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... |