Problem Description

Claris loves bitwise operations very much, especially XOR, because it has many beautiful features. He gets four positive integers a,b,c,da,b,c,d that satisfies a\leq ba≤b and c\leq dc≤d. He wants to choose two integers x,yx,y that satisfies a\leq x\leq ba≤x≤b and c\leq y\leq dc≤y≤d, and maximize the value of x~XOR~yx XOR y. But he doesn't know how to do it, so please tell him the maximum value of x~XOR~yx XOR y.

Input

The first line contains an integer T\left(1\leq T\leq10,000\right)T(1≤T≤10,000)——The number of the test cases. For each test case, the only line contains four integers a,b,c,d\left(1\leq a,b,c,d\leq10^{18}\right)a,b,c,d(1≤a,b,c,d≤10​18​​). Between each two adjacent integers there is a white space separated.

Output

For each test case, the only line contains a integer that is the maximum value of x~XOR~yx XOR y.

Sample Input
2
1 2 3 4
5 7 13 15
Sample Output
Copy

6
11
Hint

In the first test case, when and only when x=2,y=4x=2,y=4, the value of x~XOR~yx XOR y is the maximum. In the second test case, when and only when x=5,y=14x=5,y=14 or x=6,y=13x=6,y=13, the value of x~XOR~yx XOR y is the maximum.

 
 
 
这游戏真难,之前写过一道类似的,就直接敲了...o(n)...超时....
 
 
TLE代码:
 #include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <queue>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long int const MAX = ;
int n; struct Trie
{
int root, tot, next[MAX][], end[MAX];
inline int node()
{
memset(next[tot], -, sizeof(next[tot]));
end[tot] = ;
return tot ++;
} inline void Init()
{
tot = ;
root = node();
} inline void insert(ll x)
{
int p = root;
for(int i = ; i >= ; i--)
{
int ID = (( << i) & x) ? : ;
if(next[p][ID] == -)
next[p][ID] = node();
p = next[p][ID];
}
end[p] = x;
} inline int search(int x)
{
int p = root;
for(int i = ; i >= ; i--)
{
int ID = (( << i) & x) ? : ;
if(ID == )
p = next[p][] != - ? next[p][] : next[p][];
else
p = next[p][] != - ? next[p][] : next[p][];
}
return x ^ end[p];
} }trie; int a[],b[];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n=;
int WTF = ,ans=, x;
trie.Init();
for(int i = ; i < ; i++)
{
scanf("%d", &a[i]);
}
for(int i = ; i < ; i++)
{
scanf("%d", &b[i]);
}
for(int i=a[]; i<=a[]; i++){
//WTF=0;
//trie.insert(1);
//WTF = WTFx(WTF, trie.search(1));
for(int j=b[]; j<=b[]; j++){
trie.Init();
trie.insert(i);
WTF = max(WTF, trie.search(i));
trie.insert(j);
WTF = max(WTF, trie.search(j));
ans=max(WTF,ans);
}
}
printf("%d\n", WTF);
}
}

Claris and XOR的更多相关文章

  1. BC之Claris and XOR

    http://acm.hdu.edu.cn/showproblem.php?pid=5661 Claris and XOR Time Limit: 2000/1000 MS (Java/Others) ...

  2. hdu 5661 Claris and XOR

    Claris and XOR Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  3. Claris and XOR(模拟)

    Claris and XOR Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  4. HDU5661 Claris and XOR

    我们求二进制是怎么求的呢:先看看二进制的每一位代表多大:.......32 16 8 4 2 1 假如n=10, ..... 32>n ,不要. 16>n,不要. 8<=n,要,然后 ...

  5. HDU 5661 Claris and XOR 贪心

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5661 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  6. 【整理】XOR:从陌生到头晕

    一:解决XOR常用的方法: 在vjudge上面输入关键词xor,然后按照顺序刷了一些题. 然后大概悟出了一些的的套路: 常用的有贪心,主要是利用二进制的一些性质,即贪心最大值的尽量高位取1. 然后有前 ...

  7. bzoj4589 FWT xor版本

    4589: Hard Nim Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 865  Solved: 484[Submit][Status][Disc ...

  8. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  9. 二分+DP+Trie HDOJ 5715 XOR 游戏

    题目链接 XOR 游戏 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

随机推荐

  1. Java中动态代理技术生成的类与原始类的区别

    用动态代理的时候,对它新生成的类长什么样子感到好奇.有幸通过一些资料消除了心里的疑惑. 平时工作使用的Spring框架里面有一个AOP(面向切面)的机制,只知道它是把类重新生成了一遍,在切面上加上了后 ...

  2. MySQL 最经常使用的一千行

    /* 启动MySQL */ net start mysql /* 连接和断开server */ mysql -h 住址 -P port -u username -p password /* 跳过许可认 ...

  3. poj 2478 Farey Sequence(欧拉函数是基于寻求筛法素数)

    http://poj.org/problem?id=2478 求欧拉函数的模板. 初涉欧拉函数,先学一学它主要的性质. 1.欧拉函数是求小于n且和n互质(包含1)的正整数的个数. 记为φ(n). 2. ...

  4. udacity android 学习笔记: lesson 4 part b

    udacity android 学习笔记: lesson 4 part b 作者:干货店打杂的 /titer1 /Archimedes 出处:https://code.csdn.net/titer1 ...

  5. Ubuntu14.04下安装ZendStudio10.6.1+SVN出现Failed to load JavaHL Library

    Subclipse不能正常工作,打开后报错: Failed to load JavaHL Library. These are the errors that were encountered: no ...

  6. HDU 1069 Monkey and Banana(DP 长方体堆放问题)

    Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...

  7. 认识node.js:express(一)

    express是node.js官方推荐的框架. 安装 npm install express -g 命令中的 “-g” 表示全局(global) 由于新版本(4.x.x)的express的命令集中到了 ...

  8. CodeForces 22D Segments 排序水问题

    主题链接:点击打开链接 升序右键点.采取正确的点 删边暴力 #include <cstdio> #include <cstring> #include <algorith ...

  9. SoC嵌入式软件架构设计II:没有MMU的CPU虚拟内存管理的设计和实现方法

    大多数的程序代码是必要的时,它可以被加载到内存中运行.手术后,可直接丢弃或覆盖其它代码. 我们PC然在同一时间大量的应用,地址空间差点儿能够整个线性地址空间(除了部分留给操作系统或者预留它用).能够觉 ...

  10. 给Activity设置Dialog属性,点击区域外消失;

    1.在AndroidManifest.xml中给Activity设置样式: <activity             android:name=".MyActivity" ...