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. WPF/Silverlight中图形的平移,缩放,旋转,倾斜变换演示

    原文:WPF/Silverlight中图形的平移,缩放,旋转,倾斜变换演示 为方便描述, 这里仅以正方形来做演示, 其他图形从略. 运行时效果图:XAML代码:// Transform.XAML< ...

  2. 简单的反射 把datatable 转换成list对象

    /// <summary> /// 把datatable 转换成list对象 /// </summary> /// <typeparam name="T&quo ...

  3. 开展:随笔记录 OSGI的jar增加了一些小问题和注意事项

    在引用jar当包,假设引用的项目包.在需要MANIFEST.MF 它定义 一.外用jar: 实例:外部参考需要包装的Import package里面 定义一下.如:google-gson-2.2.2. ...

  4. Codeforces 484E Sign on Fence(是持久的段树+二分法)

    题目链接:Codeforces 484E Sign on Fence 题目大意:给定给一个序列,每一个位置有一个值,表示高度,如今有若干查询,每次查询l,r,w,表示在区间l,r中, 连续最长长度大于 ...

  5. 返璞归真 asp.net mvc (5) - Action Filter, UpdateModel, ModelBinder, Ajax, Unit Test

    原文:返璞归真 asp.net mvc (5) - Action Filter, UpdateModel, ModelBinder, Ajax, Unit Test [索引页] [源码下载] 返璞归真 ...

  6. freemarker错误七

    1.错误叙述性说明 五月 30, 2014 11:33:57 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template p ...

  7. HDU2516-取石子游戏

    取石子游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  8. Android Studio如何引用jar包裹(不gradle)

    这和eclipse最大的区别.与非常人的预期开始Android Studio我们很不高兴这一套. 它直接在地图上.首先通过File->Projcet structure打开project结构界面 ...

  9. Android ListView分页载入(服务端+android端)Demo

    Android ListView分页载入功能 在实际开发中经经常使用到,是每一个开发人员必须掌握的内容,本Demo给出了服务端+Android端的两者的代码,并成功通过了測试. 服务端使用MyEcli ...

  10. Windows Server 2008 R2 SP1 下载地址

    Windows Server 2008 R2 SP1 http://download.microsoft.com/download/0/A/F/0AFB5316-3062-494A-AB78-7FB0 ...