#include "Anna.h"
#include <vector>
namespace {
const int B = 20
, N = 10000;
int n, l, r, bel[N], ans, count, pre[N], suf[N]
, lb, rb, num, at;
}
void InitA(int n, int l, int r) {
::n = n;
::l = l;
::r = r;
for (int i = 0; i < n; ++i)
bel[i] = i / B;
lb = bel[l] + 1 , rb = bel[r];
for (int i = 8; i >= 0; --i)
SendA((lb >> i) & 1);
for (int i = 8; i >= 0; --i)
SendA((rb >> i) & 1);
count = 0;
ans = 0;
num = 0;
at = lb * B + B - 1;
}
void ReceiveA(bool x) {
if (count < 20) {
ans |= (x ? 1 : 0) << (20 - count - 1);
} else {
int y = (count - 20) % 20;
num |= (x ? 1 : 0) << y;
if (y == 19) {
if (at == lb * B) {
pre[at] = num;
at = rb * B;
if (at >= l && ans > num)
ans = num;
} else if (at <= lb * B + B - 1) {
pre[at] = num;
--at;
if (at >= l && ans > num)
ans = num;
} else {
suf[at] = num;
++at;
if (at <= r && ans > num)
ans = num;
}
pre[at] = num;
num = 0;
}
}
++count;
}
int Answer() {
return ans;
}
#include "Bruno.h"
#include <cstdio>
#include <vector>
namespace {
const int B = 20, N = 10000;
std::vector<int> P;
int n, bel[N], low[N]
, tot, count;
}
void InitB(int n, std::vector<int> P) {
::P = P;
::n = n;
for (int i = 0; i < n; ++i)
bel[i] = i / B, low[i / B] = P[i];
for (int i = 0; i < n; ++i)
if (low[i / B] > P[i])
low[i / B] = P[i];
count = 0;
}
void ReceiveB(bool y) {
tot |= (y? 1 : 0) << (18 - count - 1);
++count;
if (count == 18) {
printf(" COUNT 18 \n");
int lb = tot >> 9, rb = tot & 511;
int x = (1 << 20) - 1;
for (int i = lb; i < rb; ++i)
if (low[i] < x)
x = low[i];
for (int j = 19; j >= 0; --j)
SendB((x >> j) & 1);
int at;
at = lb * B + B - 1;
for (; at >= lb * B; --at) {
for (int j = 19; j >= 0; --j)
SendB((P[at] >> j) & 1);
}
at = rb * B;
for (; at < rb * B + B; ++at) {
for (int j = 19; j >= 0; --j)
SendB((P[at] >> j) & 1);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |