three arrays

字典树上贪心

#include<bits/stdc++.h>
using namespace std;
int trie[][][];
int siz[][];
int A[];
int tot[];
bool ed[][];
int val[][];
int N;
void init()
{
tot[]=tot[]=;
for(int i=; i<=*N; i++)
{
val[i][]=val[i][]=;
ed[i][]=ed[i][]=;
trie[i][][]=trie[i][][]=trie[i][][]=trie[i][][]=;
siz[i][]=siz[i][]=;
} }
void insert(int x,bool f)
{
int k=;
int y=x;
while(x)
{
A[k++]=x%;
x/=;
}
while(k<)A[k++]=;
int t=;
int j=;
int len=;
while(j>=)
{
++siz[t][f];
if(trie[t][A[j]][f]==)
{
trie[t][A[j]][f]=++tot[f];
}
t=trie[t][A[j]][f]; j--;
// cout<<t<<"t"<<endl;
len++;
}
//cout<<len<<" leN\n";
++siz[t][f];
ed[t][f]=;
val[t][f]=y;
//cout<<t<<'\n'; }
int query()
{
int t0=,t1=;
int len=;
while(!ed[t0][]&&!ed[t1][])
{
--siz[t0][];
--siz[t1][];
// cout<<t0<<t1<<endl;//siz[t0][0]<<siz[t1][1]<<endl;
if(siz[trie[t0][][]][]&&siz[trie[t1][][]][])
{
t0=trie[t0][][];
t1=trie[t1][][];
}
else if(siz[trie[t0][][]][]&&siz[trie[t1][][]][])
{
t0=trie[t0][][];
t1=trie[t1][][];
}
else
{
if(siz[trie[t0][][]][])
t0=trie[t0][][];
else t0=trie[t0][][];
if(siz[trie[t1][][]][])
t1=trie[t1][][];
else t1=trie[t1][][]; }
// ++len;
}
//cout<<len<<"LEN"<<'\n';
siz[t0][]--;
siz[t1][]--;
//cout<<t0<<t1<<'\n';
//cout<<ed[t0][0]<<' '<<ed[t1][1]<<'\n';
return val[t0][]^val[t1][];
}
int T;
int a,b;
int C[];
int main()
{
//freopen("1.in","r",stdin);
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
init();
for(int i=; i<N; i++)
{
scanf("%d",&a);
insert(a,);
}
for(int i=; i<N; i++)
{
scanf("%d",&b);
insert(b,);
}
for(int i=;i<N;i++){
C[i]=query();
}
sort(C,C+N);
for(int i=; i<N; i++)
{
cout<<C[i]<<((i!=N-1)?' ':'\n');
}
} }

three arrays的更多相关文章

  1. Java程序员的日常—— Arrays工具类的使用

    这个类在日常的开发中,还是非常常用的.今天就总结一下Arrays工具类的常用方法.最常用的就是asList,sort,toStream,equals,copyOf了.另外可以深入学习下Arrays的排 ...

  2. 使用 Arrays 类操作 Java 中的数组

    Arrays 类是 Java 中提供的一个工具类,在 java.util 包中.该类中包含了一些方法用来直接操作数组,比如可直接实现数组的排序.搜索等(关于类和方法的相关内容在后面的章节中会详细讲解滴 ...

  3. 【转】java.util.Arrays.asList 的用法

    DK 1.4对java.util.Arrays.asList的定义,函数参数是Object[].所以,在1.4中asList()并不支持基本类型的数组作参数. JDK 1.5中,java.util.A ...

  4. System.arraycopy()和Arrays.copyOf()的区别

    先看看System.arraycopy()的声明: public static native void arraycopy(Object src,int srcPos, Object dest, in ...

  5. 计算机程序的思维逻辑 (31) - 剖析Arrays

    数组是存储多个同类型元素的基本数据结构,数组中的元素在内存连续存放,可以通过数组下标直接定位任意元素,相比我们在后续章节介绍的其他容器,效率非常高. 数组操作是计算机程序中的常见基本操作,Java中有 ...

  6. No.004:Median of Two Sorted Arrays

    问题: There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the ...

  7. [LeetCode] Intersection of Two Arrays II 两个数组相交之二

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  8. [LeetCode] Intersection of Two Arrays 两个数组相交

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  9. [LeetCode] Median of Two Sorted Arrays 两个有序数组的中位数

    There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...

  10. Merge K Sorted Arrays

    This problem can be solved by using a heap. The time is O(nlog(n)). Given m arrays, the minimum elem ...

随机推荐

  1. 根据对象属性查找对象或者数组(根据对象属性查找某数组内符合该条件的对象,数组内对象属性check为true的对象,存放到数组内) 滚动轴样式

      1.根据对象属性查找某数组内符合该条件的对象. optionComwords:[ {optionName:"名称1", optionCode: '1'}, {optionNam ...

  2. xmake入门,构建项目原来可以如此简单

    前言 在开发xmake之前,我一直在使用gnumake/makefile来维护个人C/C++项目,一开始还好,然而等项目越来越庞大后,维护起来就非常吃力了,后续也用过一阵子automake系列工具,并 ...

  3. 【Python基础】_2 Python基本语法与常识(迭代优化中...)

    2 Python的基本语法 为了保证Python解释器能顺利编译所编写的代码,也为了程序员对自己和别人所编写的程序易于阅读.维护,对编程语言的语法做一些基本约定是非常必要的. 2.1 编程方式 2.1 ...

  4. Selenium1.0与2.0介绍

    Selenium的实现原理 首先,你要明确刚才建立的测试用例是基于Selenium 2.0,也就是Selenium + WebDriver的方案.其次,你需要知道,对Selenium而言,V1.0和V ...

  5. CSP2019

    $CSP\space S$ 格雷码 $solution:$ 直接模拟即可. 时间复杂度 $O(n)$ . #include<iostream> #include<cstring> ...

  6. node搭建个人博客promise警告解除

    警告 (node:8500) UnhandledPromiseRejectionWarning: undefined (node:8500) UnhandledPromiseRejectionWarn ...

  7. 看CLRS 对B树的浅显理解

    定义及特点: 每个结点有n个关键字和n+1个指向子结点的指针,即有n+1个孩子结点. n个关键字按非递减的顺序存储. 最小度数t>=2,除了根结点的所有内部结点(非叶结点)的孩子数>=t且 ...

  8. ubuntu下docker安装

    首先来一个官网安装教程链接:https://docs.docker.com/install/linux/docker-ce/ubuntu/ 目前docker主要有docker-CE 与 docker- ...

  9. GIT 开发流程

    1.git clone 使用 git clone 将一个项目下载到本地 2.git checkout -b branchName 新建一个branchName的本地分支 3.git add file/ ...

  10. P4315 月下“毛景树” (树链剖分+边剖分+区间覆盖+区间加+区间最大值)

    题目链接:https://www.luogu.org/problem/P4315 题目大意: 有N个节点和N-1条树枝,但节点上是没有毛毛果的,毛毛果都是长在树枝上的.但是这棵“毛景树”有着神奇的魔力 ...