# bzoj4103【THUSC2015】异或运算

## 4103: [Thu Summer Camp 2015]异或运算

Time Limit: 20 Sec  Memory Limit: 512 MB
Submit: 359  Solved: 188
[Submit][Status][Discuss]

3 3
1 2 4
7 6 5
3
1 2 1 2 2
1 2 1 3 4
2 3 2 3 4

6
5
1

## HINT

对于100%的数据，0<=Xi,Yj<2^31,

1<=u<=d<=n<=1000,

1<=l<=r<=m<=300000,

1<=k<=(d-u+1)*(r-l+1),

1<=p<=500

## Source

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define F(i,j,n) for(int i=j;i<=n;i++)
#define D(i,j,n) for(int i=j;i>=n;i--)
#define ll long long
#define N 1005
#define M 300005
using namespace std;
int n,m,q,cnt,x_1,x_2,y_1,y_2,k;
int a[N],b[M];
int sz[M*35],c[M*35][2],rt[M];
struct data{int x,y;}p[N];
inline int read()
{
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void insert(int x,int &y,int val,int tmp)
{
y=++cnt;sz[y]=sz[x]+1;
c[y][0]=c[x][0];c[y][1]=c[x][1];
if (tmp==-1) return;
int t=(val>>tmp)&1;
insert(c[x][t],c[y][t],val,tmp-1);
}
int solve(int k,int tmp)
{
if (tmp==-1) return 0;
int sum=0;
F(i,x_1,x_2)
{
int t=(a[i]>>tmp)&1;
sum+=sz[c[p[i].y][t^1]]-sz[c[p[i].x][t^1]];
}
if (sum>=k)
{
F(i,x_1,x_2)
{
int t=(a[i]>>tmp)&1;
p[i].x=c[p[i].x][t^1];
p[i].y=c[p[i].y][t^1];
}
return solve(k,tmp-1)+(1<<tmp);
}
else
{
F(i,x_1,x_2)
{
int t=(a[i]>>tmp)&1;
p[i].x=c[p[i].x][t];
p[i].y=c[p[i].y][t];
}
return solve(k-sum,tmp-1);
}
}
int main()
{
n=read();m=read();
F(i,1,n) a[i]=read();
F(i,1,m) b[i]=read();
F(i,1,m) insert(rt[i-1],rt[i],b[i],30);
q=read();
while (q--)
{
x_1=read();x_2=read();y_1=read();y_2=read();k=read();
F(i,x_1,x_2) p[i].x=rt[y_1-1],p[i].y=rt[y_2];
printf("%d\n",solve(k,30));
}
}


#### BZOJ 4103~4105 THUSC2015 题解

2015-06-03 17:55:51

#### bzoj-4103 异或运算

2015-08-25 21:58:07

#### 【BZOJ4103】异或运算（THUSC2015）-可持久化trie树+位运算

2017-05-18 19:34:59

#### 【BZOJ4103】【Thusc2015】异或运算 可持久Trie

2016-06-01 11:08:08

#### THUSC2015

2015-06-15 16:18:05

#### 【BZOJ4104】解密运算（THUSC2015）-排序和循环串性质应用

2017-05-19 13:39:47

#### bzoj4104【THUSC2015】解密运算

2016-06-01 23:23:12

#### 【BZOJ4104】【Thusc2015】解密运算

2016-06-01 15:56:28

#### bzoj4103[Thu Summer Camp 2015]异或运算

2015-12-05 14:41:45

#### JZOJ4121. 【THUSC2015】异或问题（可持久化trie）

2018-05-21 18:13:28