CF1081F Tricky Interactor
Description
这是一道交互题。
有一个长度为 的 序列,初始时 的个数为 。定义一次操作为给定 ,交互库会等概率地从区间 和 中选择一个,然后翻转下标在该区间内的数(翻转即 ),并告诉你翻转完的序列中有多少个 。操作之间不是独立的,即对序列的修改是永久的。
你需要在 次操作内得出原始的序列。
。
Solution
设这个序列为 。注意到连续操作 两次所形成的序列要么是 ,要么是除了 都翻转的序列。我们可以多随几次,总能碰到第二种情况,然后就能知道第 个数是 还是 了,然后再还原回去。当然有一个问题就是除开 以外剩下的 数量相等,这里我们可以把 改为 ,这样每次能得到 ,最后再统计一下就可以了。这样我们就得到了一个期望 次询问的做法。
其实放 没有必要,完全可以开到 ,总不至于有人这么非吧。
#include <bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define rep(i, s, e) for (re int i = s; i <= e; ++i)
#define drep(i, s, e) for (re int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
const int N = 300 + 10;
il int read() {
int x = 0; bool f = true; char c = getchar();
while (!isdigit(c)) {if (c == '-') f = false; c = getchar();}
while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return f ? x : -x;
}
int n, t, ans[N];
il int ask(int l, int r) {
cout << "? " << l << ' ' << r << endl;
fflush(stdout);
int res; cin >> res;
return res;
}
il int get(int l, int r) {
int res;
do { res = ask(l, r); res = ask(l, r); } while (res == t);
int dis = res - (n - t);
do { res = ask(l, r); res = ask(l, r); } while (res != t);
return (r - l + 1 + dis) / 2;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> t;
if (n == 2 * t + 1 || n == 2 * t - 1) {
static int a[N];
rep(i, 1, n - 1) a[i] = get(i, i + 1);
a[n] = 2 * t;
rep(i, 1, n - 1) a[n] -= a[i];
rep(i, 1, n - 1) {
if (i & 1) ans[n] -= a[i];
else ans[n] += a[i];
}
ans[n] = (ans[n] + a[n]) / 2;
drep(i, n - 1, 1) ans[i] = a[i] - ans[i + 1];
}
else rep(i, 1, n) ans[i] = get(i, i);
cout << "! ";
rep(i, 1, n) cout << ans[i];
cout << endl;
return 0;
}