题目链接: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. restful架构风格设计准则(二)以资源为中心,一个url

    读书笔记,原文链接:http://www.cnblogs.com/loveis715/p/4669091.html,感谢作者! 1.REST是一种架构风格,其核心是面向资源,简化设计,降低开发的复杂性 ...

  2. 新概念英语(1-35)Our village

    新概念英语(1-35)Our village Are the children coming out of the park or going into it ? This is a photogra ...

  3. golang-在gin中cookie跨域设置(配合ajax)

    1.当我在golang中,在前后端分离的情况下使用cookies时发现,跨域没有被允许.代码如下: func AccessJsMiddleware() gin.HandlerFunc { return ...

  4. [Debug]测试环境Giraffe无法正确登录

    BUG描述: 在测试环境192.168.2.72上的giraffe无法正确登录,输入正确的用户名.密码,点击登录无反应,输入错误的用户名密码会报错 原因: 2.72安装giraffe的磁盘空间已满,导 ...

  5. [LeetCode] Diameter of Binary Tree 二叉树的直径

    Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a b ...

  6. [LeetCode] Relative Ranks 相对排名

    Given scores of N athletes, find their relative ranks and the people with the top three highest scor ...

  7. [JLOI 2015]装备购买

    Description 脸哥最近在玩一款神奇的游戏,这个游戏里有 n 件装备,每件装备有 m 个属性,用向量zi(aj ,.....,am) 表示  (1 <= i <= n; 1 < ...

  8. [HNOI 2010]Bus 公交线路

    Description 题库链接 有 \(N\) 个车站, \(K\) 条公交线路.第 \(1\) 到 \(K\) 站是这 \(K\) 线路的起点站.第 \(N-K+1\) 到 \(N\) 是终点站. ...

  9. [POJ 1006]生理周期

    Description 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这天,人会在相应的方面表现出色.例如,智力周期的高峰 ...

  10. [AH/HNOI2017]影魔

    题目背景 影魔,奈文摩尔,据说有着一个诗人的灵魂. 事实上,他吞噬的诗人灵魂早已成千上万. 千百年来,他收集了各式各样的灵魂,包括诗人. 牧师. 帝王. 乞丐. 奴隶. 罪人,当然,还有英雄. 题目描 ...