题目链接:http://uoj.ac/problem/239


题目大意:

这是一道交互题,交互库维护了一个数据结构,可以存储n为二进制串,一开始你可以向空的数据结构中插入若干二进制串,

接下来这个数据结构会将其中存储的二进制串进行改变。

改变的方法是生成一个0到n-1的排列pi,将原来的二进制串a0a1a2..an-1变成ap0ap1..apn-1。

接着你可以进行询问,每次询问一个串是否在这个数据结构当中,要求你在不超过w次插入和r次询问中求出排列p

分析:读完题后看看数据范围,w=r=896=128*7=nlog^2(n),提示我们用分治算法


加数:

我们需要在开始一次性把所有数加完。

考虑加哪些数?结合分治,我们把l,r分为(l,mid)(mid+1,r)如果我们把左边的数加入库中,分治时如果我们找到一个数在出现

就说明他是在(l,mid)范围内,否则在(mid+1,r)中,可以完成分治。

对于这个操作我们具体讲讲:根据上面所说,我们只对(l,mid)进行操作,枚举i(l<=i<=mid)我们使(l,i-1)(i+1,mid)为0,其他位置

都为1,把他们都加入库中,这样我们每一层1的个数都不同,所以所有数加入过后不会影响最后分治。


查找 :

我们对(0,n-1)进行分治,每次可以判断一个位置上的数在哪个区间,一直递归到底层可得最后答案。


附上交互代码 :

#include<bits/stdc++.h>
#include "messy.h"
using namespace std;
const int N=;
int ans[N],used[N],len;
inline void add(int l,int r)
{
if(l>=r) return ;
string str="";
for(int i=;i<len;i++) str+='';
for(int i=;i<l;i++) str[i]='';
for(int i=r+;i<len;i++) str[i]=''; int mid=(l+r)>>;
for(int i=l;i<=mid;i++)
{
str[i]='';
add_element(str);
str[i]='';
}
add(l,mid);add(mid+,r);
} int temp[N]; inline void solve(int l,int r)
{
if(l>=r) return ;
string str="";
for(int i=;i<len;i++) str+='';
for(int i=;i<l;i++) str[ans[i]]='';
for(int i=r+;i<len;i++) str[ans[i]]='';
int cnt1=,cnt2=,mid=(l+r)>>;
for(int i=l;i<=r;i++)
{
int o=ans[i];
str[o]='';
if(check_element(str))
{
cnt1++;
temp[l+cnt1-]=ans[i];
}
else
{
cnt2++;
temp[mid+cnt2]=ans[i];
}
str[o]='';
}
for(int i=l;i<=r;i++) ans[i]=temp[i];
solve(l,mid);solve(mid+,r);
} vector<int> cnt;
vector<int> restore_permutation(int n, int w, int r)
{
len=n; memset(used,,sizeof(used));
add(,len-);
compile_set();
for(int i=;i<len;i++) ans[i]=i; solve(,len-);
for(int i=;i<len;i++) temp[ans[i]]=i;
for(int i=;i<len;i++) cnt.push_back(temp[i]);
return cnt;
}

转载请声明!!!


IOI2016Day2. Messy的更多相关文章

  1. Messy Code in Windows Server 2008 R2 English Edition

          We always use Windows Server 2008 R2 English operation system. And it doesn't have any problem ...

  2. the solution about &quot;messy code&quot; in elicpse

    I use the Elicpse IDE to develope the ansdroid app.Sometime encounter the messy code in the Elicpse ...

  3. Chinese Messy Code of String

    It's very strange that I found the messy code.I 've never seen this before. this is the java code: / ...

  4. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C. Messy 构造

    C. Messy You are fed up with your messy room, so you decided to clean it up. Your room is a bracket ...

  5. .net 中文显示乱码问题(Chinese display with messy code)

    Case:同样的代码,本地开发环境(local is Chinese Simplify)可以成功运行,但是放到Windows Server 2008 R2(Local is United State) ...

  6. BNU OJ 50998 BQG's Messy Code

    #include <cstdio> #define _(l) int l #define ___(l,L) for (_(o)=0,x=l o*2;o<x;o++)O= L o; # ...

  7. IOI2016Day2. paint

    题目链接:http://uoj.ac/problem/238 题目大意: 有一个长度为n的黑白序列,告诉你所以k个极长连续黑段长度和顺序.有一些位置的颜色已知,需要判断剩下未知的位置哪些颜色 一定是白 ...

  8. IS Kali: installed chiess messy code problem

    apt-get install ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy init 6

  9. CF1227C Messy

    思路: 构造题.首先把字符串变成“(((((...)))))”的样子,再根据k的取值变成“()()()...((...))”的样子即可. 实现: #include <bits/stdc++.h& ...

随机推荐

  1. CTF中常见密码题解密网站总结

    0x00.综合 网站中包含大多编码的解码. http://web2hack.org/xssee/ https://www.sojson.com/ http://web.chacuo.net/ 0x01 ...

  2. netty学习--handler传递

    在netty中的处理链pipeline中,事件是按顺序传递的,把自己拟人为netty程序,针对进来(inbound)的请求,会从head开始,依次往tail传递. pipeline采用了链表结构,he ...

  3. Apache设置用户权限(2个域名。一个能访问全部文件,一个只能访问指定文件)

    可以利用apache的虚拟主机的配置设置: 2个域名一个是xxxxx.com ,一个是aaaaa.com xxxxx.com配置只访问jpg文件,aaaaa.com可以访问所有文件 <Virtu ...

  4. [翻译] TensorFlow Programmer's Guide之Frequently Asked Questions(问得频率最多的几个问题)

    目录: 特点和兼容性(Features and Compatibility) 建立一个TensorFlow图(Building a TensorFlow graph) 运行一个TensorFlow计算 ...

  5. Python系列之 - 装饰器

    装饰器主要是用来对函数的操作,我们把定义的函数比作一个蛋糕的话,那么装饰器就是盒子,如果要吃蛋糕就先打开盒子.具体到程序中就是在函数外层又套了一层,套的那一层就是一个装饰器.这么说可能有点抽象,那么我 ...

  6. CSS3中不常用但很有用的属性-1

    内容来源于W3Cschool和<图解CSS3核心技术与案例实战> 1.:target选择器 URL 带有后面跟有锚名称 #,指向文档内某个具体的元素.这个被链接的元素就是目标元素(targ ...

  7. MySQL获取XML格式数据

    通过再调用mysql工具时使用--xml选项: C:\Users\wang>mysql -uroot -p --xml mydb Enter password: ******** Welcome ...

  8. a标签点击页面刷新但还保存当前点击的class是激活的状态

    $(".shop-list1").find("li").each(function(){            var href=$(this).attr(&q ...

  9. mvc4.0 @Styles.Render(转)

    1.@Styles.Render 在页面上可以用@Styles.Render("~/Content/css") 来加载css 首先要在App_Start 里面BundleConfi ...

  10. 0417 jsBom操作+Dom再次整理

    BOM 1.Windows对象 window.open("打开的地址","打开的位置")window.opener:打开此页面的上一个页面对象window.cl ...