大意: 给两个数组$a,b$, 要求重排使得$c_i=a_i\oplus b_i$字典序最小.

字典树上贪心取$n$次, 然后排序, 还不知道怎么证.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
using namespace std;
const int N = 1e5+50, S = 29;
int n, T[2], tot;
struct {int ch[2];} tr[N*60];
int cnt[N*60][2];
vector<int> ans;
void add(int &o, int d, int x, int tp, int v) {
if (!o) o=++tot;
cnt[o][tp]+=v;
if (d>=0) add(tr[o].ch[x>>d&1],d-1,x,tp,v);
}
void solve(int u, int v, int d, int x, int y) {
--cnt[u][0],--cnt[v][1];
if (d<0) return ans.pb(x^y);
int A=cnt[tr[u].ch[0]][0],B=cnt[tr[u].ch[1]][0];
int C=cnt[tr[v].ch[0]][1],D=cnt[tr[v].ch[1]][1];
if (A&&C) return solve(tr[u].ch[0],tr[v].ch[0],d-1,x,y);
if (B&&D) return solve(tr[u].ch[1],tr[v].ch[1],d-1,x^1<<d,y^1<<d);
if (A&&D) return solve(tr[u].ch[0],tr[v].ch[1],d-1,x,y^1<<d);
if (B&&C) return solve(tr[u].ch[1],tr[v].ch[0],d-1,x^1<<d,y);
} void work() {
scanf("%d", &n);
REP(z,0,1) REP(i,1,n) {
int t;
scanf("%d", &t);
add(T[z],S,t,z,1);
}
ans.clear();
REP(i,1,n) solve(T[0],T[1],S,0,0);
sort(begin(ans),end(ans));
REP(i,0,n-1) printf("%d%c",ans[i]," \n"[i==n-1]);
T[0]=T[1]=0;
while (tot) cnt[tot][0]=cnt[tot][1]=tr[tot].ch[0]=tr[tot].ch[1]=0,--tot;
} int main() {
int t;
scanf("%d", &t);
while (t--) work();
}

hdu 6625 three array (01-trie)的更多相关文章

  1. hdu 5536 Chip Factory (01 Trie)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题面; Chip Factory Time Limit: 18000/9000 MS (Java/O ...

  2. hdu 4825 Xor Sum (01 Trie)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 题面: Xor Sum Time Limit: 2000/1000 MS (Java/Others) ...

  3. [一本通学习笔记] 字典树与 0-1 Trie

    字典树中根到每个结点对应原串集合的一个前缀,这个前缀由路径上所有转移边对应的字母构成.我们可以对每个结点维护一些需要的信息,这样即可以去做很多事情. #10049. 「一本通 2.3 例 1」Phon ...

  4. 可持久化0-1 Trie 简介

    Trie树是字符串问题中应用极为广泛的一种数据结构,可以拓展出AC自动机.后缀字典树等实用数据结构. 然而在此我们考虑0-1 Trie的应用,即在序列最大异或问题中的应用. 这里的异或是指按位异或.按 ...

  5. Hash Array Mapped Trie

    Hash Array Mapped Trie   Python\hamt.c

  6. HDU 6625 (01字典树)

    题意:给定两个长为n的数组a和b:重新排列a和b,生成数组c,c[i]=a[i] xor b[i]:输出字典序最小的c数组. 分析:将a中的数插入一颗01字典树a中:将b中的数插入一颗01字典树b中: ...

  7. HDU 1671 Phone List(Trie的应用与内存释放)

    Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. HDU 1251 统计难题(Trie模版题)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Subm ...

  9. HDU 2846:Repository(Trie)

    http://acm.hdu.edu.cn/showproblem.php?pid=2846 题意:给出N个模式串,再给出M个文本串,问每一个文本串在多少个模式串中出现. 思路:平时都是找前缀的,这里 ...

随机推荐

  1. iftop -i eth0 -B -F

    iftop -i eth0 -B -F 108.51.5.220 1 https://www.cnblogs.com/kobexffx/p/11000337.html

  2. golang配置镜像站点

    In Linux or macOS, you can execute the below commands. Bash / # Enable the go modules feature export ...

  3. C# mvc后台传过来的list 怎么在js使用

    var arr= JSON.parse('@Html.Raw(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize( ...

  4. C++11智能指针之std::unique_ptr

    C++11智能指针之std::unique_ptr   uniqut_ptr是一种对资源具有排他性拥有权的智能指针,即一个对象资源只能同时被一个unique_ptr指向. 一.初始化方式 通过new云 ...

  5. shared_ptr的使用和陷阱

    shared_ptr的使用和陷阱 shared_ptr的使用 分配内存 make_shared //make_shared<int>分配一块int类型大小的内存,并值初始化为100 //返 ...

  6. OpenBLAS编译 Debug x64 Win10 vs2015

    OpenBLAS编译  Debug x64  Win10  vs2015 >------ 已启动生成: 项目: ZERO_CHECK, 配置: Debug x64 ------ > Che ...

  7. VMware 快速克隆出多个 Linux centos7 环境

    这样一台系统就已经克隆好了,但是,现在还没有完,因为是克隆的,里面的ip地址和创建的主机名都是一样,需要进行修改 登录服务器,然后使用 [ifcfg-ens33需根据实际情况而定] vi /etc/s ...

  8. 【441】JSON format

      Ref: json -- JSON encoder and decoder JSON(JavaScript Object Notation) can help us to see data mor ...

  9. Python - Django - 命名 URL 和反向解析 URL

    命名 URL: test.html: <!DOCTYPE html> <html lang="en"> <head> <meta char ...

  10. 数据标记系列——图像分割 & Curve-GCN

    在之前的文章中(参考:),我们提到了Polygon-RNN++在数据标注中的应用.今天不得不提到多伦多大学与英伟达联合公布的一项最新研究:Curve-GCN的应用结果显示图像标注速度提升10倍. Cu ...