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. Js AJAX Event

    ;(function () { if ( typeof window.CustomEvent === "function" ) return false; function Cus ...

  2. Java 5种单例模式

    /*单例模式: 指某个类中只能存在一个对象实例,并且该类中只提供一个取得其对象实例的方法 优点:减少系统性能开销 应用场景:网站的计数器,任务管理器,回收站等*/   //单例模式1 -- 静态内部类 ...

  3. SI 和 MDK 添加Astyle功能

    一. 什么是Astyle 1. Astyle是一个用来对C/C++代码进行格式化的插件,可在多个环境中使用.该插件基于 Artistic Style 开发 二. 软件获取地址 1.下载地址:https ...

  4. Comet OJ C1076 [Contest #4]求和

    题目 首先我们可以通过经典容斥转化为计算\([1,x]\)的答案. 现在我们考虑一个数的个位对答案的贡献. 每做一次操作都会让个位加上十位然后取模,直到只有个位为止. 我们发现这个过程中,个位数前的系 ...

  5. mysqldump: [Warning] Using a password on the command line interface can be insecure.

    MySQL 5.6 警告信息 command line interface can be insecure 修复 在命令行输入密码,就会提示这些安全警告信息. Warning: Using a pas ...

  6. 关于“如何只用2GB内存从20亿,40亿,80亿个整数中找到出现次数最多的数?”的一种思路

    小弟不才,只懂一些c#的皮毛,有一些想法, int32值范围大概在-20亿——20亿,按hashtable一个keyvalue占8B的设定来说,最大可以存储大约2.5亿个 数字-次数对. 那么,可以将 ...

  7. Listview使用

    ListView控件比前面几种控件要复杂一些,通过此控件,可将项目组成带有或不带有列标头的列,并显示伴随的图标和文本.ListView控件是由ColumnHeader和ListItem对象所组成的,其 ...

  8. Andronov-Hopf bifurcation

    地址:http://www.scholarpedia.org/article/Andronov-Hopf_bifurcation Andronov-Hopf bifurcation is the bi ...

  9. pandas的settingwithWaring报警

    # 0 读取数据 import pandas as pd df = pd.read_csv("beijing_tianqi_2018.csv") # 换掉温度后面的后缀 df.lo ...

  10. macos升级Nodejs和Npm到最新版

    第一步,先查看本机node.js版本: node -v 第二步,清除node.js的cache: sudo npm cache clean -f 第三步,安装 n 工具,这个工具是专门用来管理node ...