题目链接

题目大意:给你两个序列,第二个序列可以任意进行排列变换,然后由这两个序列一一异或得到答案序列,要求答案序列的字典序最小。

可持续字典树与第K大可持续线段树的区别主要在于每个节点上 ,它多了一个记录值。

因为线段树肯定是对区间处理,要+1的,但是字典树是对点处理,这两个值都要记录。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=3e5+;
int sum[N*][],son[N*][],x,n,tot,a[N];
void update(int last,int cur,int num,int pos){
int temp=!!(num&(<<pos));
sum[cur][temp]=sum[last][temp]+;
sum[cur][temp^]=sum[last][temp^];
son[cur][temp^]=son[last][temp^];
if(!pos) return;
update(son[last][temp],son[cur][temp]=++tot,num,pos-);
}
void query(int last,int cur,int num,int pos,int ans){
if(pos<) {printf("%d ",ans);return;}
int temp=!!(num&(<<pos));
if(sum[cur][temp]-sum[last][temp]>) --sum[cur][temp],query(son[last][temp],son[cur][temp],num,pos-,ans);
else --sum[cur][temp^],query(son[last][temp^],son[cur][temp^],num,pos-,ans|(<<pos));
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;++i) scanf("%d",a+i);
scanf("%d",&x);
update(,++tot,x,);
for(int i=;i<=n;++i) {
scanf("%d",&x);
update((i-)*+,++tot,x,);
}
for(int i=;i<=n;++i) query(,(n-)*+,a[i],,);
puts("");
}

可持续字典树 Perfect Security的更多相关文章

  1. hdu4757 可持续字典树

    Tree Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total Sub ...

  2. Codeforces 948D Perfect Security(字典树)

    题目链接:Perfect Security 题意:给出N个数代表密码,再给出N个数代表key.现在要将key组排序,使key组和密码组的亦或所形成的组字典序最小. 题解:要使密码组里面每个数都找到能使 ...

  3. Codeforces 948D Perfect Security 【01字典树】

    <题目链接> 题目大意: 给定两个长度为n的序列,可以改变第二个序列中数的顺序,使得两个序列相同位置的数异或之后得到的新序列的字典序最小. 解题分析: 用01字典树来解决异或最值问题.因为 ...

  4. [CodeForces948D]Perfect Security(01字典树)

    Description 题目链接 Solution 01字典树模板题,删除操作用个数组记录下就行了 Code #include <cstdio> #include <algorith ...

  5. 01Trie树 CF923C Perfect Security

    CF923C Perfect Security 上下各n个数,求一种排列p,使上面的数i异或pi成为新的数i,求方案另字典序最小,输出该结果 01Trie树. 记录每个节点经过多少次. 每一次查询的时 ...

  6. 算法笔记--字典树(trie 树)&& ac自动机 && 可持久化trie

    字典树 简介:字典树,又称单词查找树,Trie树,是一种树形结构,是哈希树的变种. 优点:利用字符串的公共前缀来减少查询时间,最大限度地减少无谓的字符串比较. 性质:根节点不包含字符,除根节点外每一个 ...

  7. Codeforces 948D Perfect Security

    Perfect Security 题意:给你一个A[i]数组, 再给你一个B[i]数组, 现在用选取 B[i] 数组中的一个 去和 A[i] 数组里的一个元素去进行异或操作, B[i]数组的元素只能用 ...

  8. [LeetCode] Implement Trie (Prefix Tree) 实现字典树(前缀树)

    Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...

  9. Good Firewall(字典树 HDU4760)

    Good Firewall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...

随机推荐

  1. 《SQL初学者指南》——第1章 关系型数据库和SQL

    第1章 关系型数据库和SQL SQL初学者指南在本章中,我们将介绍一些背景知识,以便于你能够很快地上手,能在后续的章节中编写SQL语句.本章有两个主题.首先是对本书所涉及到的数据库做一个概述,并且介绍 ...

  2. 美国在线CEO:雅虎被Verizon收购或导致裁员

    北京时间9月13日消息,据外媒报道,AOL首席执行官蒂姆·阿姆斯特朗(Tim Armstrong)称,雅虎.AOL和Verizon整合业务,将导致"部分工作岗位的变化". 阿姆斯特 ...

  3. du命令、df命令、磁盘分区

    df:汇报文件系统的磁盘使用空间[root@localhost ~]# df文件系统 1K-块 已用 可用 已用% 挂载点/dev/sda3 29140072 1022920 28117152 4% ...

  4. JSbridge 在Vue的封装与交互

    原文转自: 点我 写在 JSbridge.js let isAndroid = navigator.userAgent.indexOf('Android') > -1 || navigator. ...

  5. Jaba_Web--JDBC 删除记录操作模板

    import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import ...

  6. String(字符串) 比较大小 如果有A+B>B+A 则A>B

    题目引入: 给定N个整数,那任意顺序排列连成一个数,得到的最大的数是多少? 分析:贪心,字典序排序,都不对大小比较也不对,今天我跟别人想了很久绞尽脑汁,各种模拟都失败了.最后才发现对于俩个数a=313 ...

  7. Codeforce 322E Ciel the Commander (点分治)

    E. Ciel the Commander Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, ...

  8. 跟哥一起学python(4)- 数据类型之Number

    本节我们开始学习python的数据类型. 什么是数据类型呢?前面我们提过,所谓的编程,就是控制一系列的数据去完成我们预设的逻辑或者功能.所以,编程语言首先要定义一系列对“数据”的处理规则.这些处理规则 ...

  9. JAVA基础篇 之 类的初始化

    类中属性的隐式初始化,代码如下,我们看下不同类型默认的初始值是什么 创建一个Demo类如下: class Demo { int a; byte b; short c; long d; boolean ...

  10. 002_python的in,while else,格式化输出,逻辑运算符,int与bool转换,编码

    数据 1.什么是数据? x=10,10是我们要存储的数据 2.为何数据要分不同的类型 数据是用来表示状态的,不同的状态就应该用不同的类型的数据去表示 3.数据类型 数字 字符串 列表 元组 字典 集合 ...