首页 技术 正文
技术 2022年11月19日
0 收藏 504 点赞 4,115 浏览 2468 个字

传送门

搬题解QwQ

首先最大值一定为 \(1\),直接扫一遍两两比较 \(O(2N)\) 求出最大值

设最大值位置为 \(a\),对于任意两个没有确定的位置 \(x,y\)

询问 \([a,x+y]\),如果 \(a\le x+y\) 那么 \(x,y\) 的最大值为 \(1\),否则 \(x,y\) 最小值为 \(0\)

再询问 \([x,y]\) 即可

复杂度 \(O(7N)\)

考虑 \(Task3\),首先花费 \(2\) 的代价找到端点的 \(1\)

假设序列为 \(00000….11111\),只需要找到最靠前的位置 \(x\),使得 \(x+(x+1)\ge 1\),二分即可

然后 \(\ge x+1\) 的位置都是 \(1\),\(< x\) 的位置都是 \(0\),利用奇偶性判断 \(x\) 是否为 \(1\)

再考虑 \(Task6\),猜想复杂度为 \(5N+3logN\) 左右

任取三个没有确定的位置 \(x,y,a\),询问 \([x+y,a]\),再花费 \(2\) 的代价确定 \(x\le y\) 或者 \(y\ge x\)

假设 \(x\le y\)

如果 \(x+y\le a\),那么 \(x=0\)

否则 \(y\ge a\),把 \(y\) 当成新的 \(a\) 继续做

最后可以得到一个不确定的位置 \(z\) 和一条递增的链 \(x_1…x_k\),其它的都是 \(0\)

\(max(z,x_k)\) 一定为 \(1\),那么可以直接用 \(Task3\) 的方法二分

最后利用常数的代价 \(+\) 奇偶性求出 \(z\) 和二分中不确定的位置

# include "shop.h"
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;const int maxn(1e5 + 5);int tmp1[2], tmp2[2], que[maxn], cnt, st[maxn], tp;inline int Query1(int x, int y) {
tmp1[0] = x, tmp2[0] = y;
return query(tmp1, 1, tmp2, 1);
}inline int Query2(int x, int y, int z) {
tmp1[0] = x, tmp1[1] = y, tmp2[0] = z;
return query(tmp1, 2, tmp2, 1);
}inline int Binary(int n, int k, int *ans) {
int i, l, r, mid, ret, v;
l = 0, ret = n - 1, r = n - 2;
while (l <= r) {
mid = (l + r) >> 1;
if (!Query2(que[mid], que[mid + 1], que[n - 1])) ret = mid, r = mid - 1;
else l = mid + 1;
}
v = ret;
if (((n - ret) & 1) ^ k) ++ret;
for (i = 0; i < ret; ++i) ans[que[i]] = 0;
for (i = ret; i < n; ++i) ans[que[i]] = 1;
return v;
}void find_price(int task_id, int n, int k, int ans[]) {
int i, mx = 0, ret;
for (i = 0; i < n; ++i) ans[i] = 0;
if (task_id == 3) {
for (i = 0; i < n; ++i) que[i] = i;
if (!Query1(0, n - 1)) reverse(que, que + n);
Binary(n, k, ans);
}
/* times = 7N
else {
for (i = 1; i < n; ++i) if (Query1(mx, i)) mx = i;
ans[mx] = 1, cnt = 0, k ^= 1;
for (i = 0; i < n; ++i) if (i ^ mx) que[++cnt] = i;
while (cnt > 1) {
if (Query2(que[cnt], que[cnt - 1], mx)) {
if (!Query1(que[cnt], que[cnt - 1])) swap(que[cnt], que[cnt - 1]);
ans[que[cnt]] = 0;
}
else {
if (Query1(que[cnt], que[cnt - 1])) swap(que[cnt], que[cnt - 1]);
ans[que[cnt]] = 1, k ^= 1;
}
--cnt;
}
if (k && cnt) ans[que[1]] = 1;
}
*/
else {
if (n == 1) {
ans[0] = 1;
return;
}
if (n == 2) {
mx = Query1(0, 1) ? 1 : 0;
ans[mx] = 1;
if (!k) ans[mx ^ 1] = 1;
return;
}
st[0] = cnt = 0, tp = 1;
for (i = 1; i < n; ++i) que[++cnt] = i;
while (cnt > 1) {
if (Query2(que[cnt], que[cnt - 1], st[tp - 1])) {
if (!Query1(que[cnt], que[cnt - 1])) swap(que[cnt], que[cnt - 1]);
ans[que[cnt]] = 0;
}
else {
if (Query1(que[cnt], que[cnt - 1])) swap(que[cnt], que[cnt - 1]);
st[tp++] = que[cnt];
}
--cnt;
}
if (Query1(que[cnt], st[tp - 1])) {
ans[st[tp - 1]] = 1, mx = que[cnt], cnt = 0;
for (i = 0; i < tp; ++i) que[cnt++] = st[i];
ret = Binary(cnt, k, ans);
k ^= (cnt - ret - 1) & 1, ret = que[ret];
if (Query2(ret, mx, st[tp - 1])) {
if (!Query1(ret, mx)) swap(ret, mx);
ans[ret] = 0;
}
else {
if (Query1(ret, mx)) swap(ret, mx);
ans[ret] = 1, k ^= 1;
}
ans[mx] = k;
}
else {
ans[que[cnt]] = 1, st[tp++] = que[cnt], cnt = 0;
for (i = 0; i < tp; ++i) que[cnt++] = st[i];
Binary(cnt, k, ans);
}
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,953
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,478
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,290
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,107
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,739
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,773