Claris and XOR
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.
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≤1018). Between each two adjacent integers there is a white space separated.
For each test case, the only line contains a integer that is the maximum value of x~XOR~yx XOR y.
2
1 2 3 4
5 7 13 15
6
11
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.
#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的更多相关文章
- BC之Claris and XOR
http://acm.hdu.edu.cn/showproblem.php?pid=5661 Claris and XOR Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 5661 Claris and XOR
Claris and XOR Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- Claris and XOR(模拟)
Claris and XOR Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- HDU5661 Claris and XOR
我们求二进制是怎么求的呢:先看看二进制的每一位代表多大:.......32 16 8 4 2 1 假如n=10, ..... 32>n ,不要. 16>n,不要. 8<=n,要,然后 ...
- HDU 5661 Claris and XOR 贪心
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5661 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- 【整理】XOR:从陌生到头晕
一:解决XOR常用的方法: 在vjudge上面输入关键词xor,然后按照顺序刷了一些题. 然后大概悟出了一些的的套路: 常用的有贪心,主要是利用二进制的一些性质,即贪心最大值的尽量高位取1. 然后有前 ...
- bzoj4589 FWT xor版本
4589: Hard Nim Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 865 Solved: 484[Submit][Status][Disc ...
- [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 ...
- 二分+DP+Trie HDOJ 5715 XOR 游戏
题目链接 XOR 游戏 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
随机推荐
- 同TextView在不同的显示内容
首先,请原谅我不能命名文章.. . 我们不能准确地表达你说说什么什么,真正急着赶智商. 直接在地图上 如图所看到的显示的是两个textview 第一个实现的是,在同一个textview中给不同内容赋予 ...
- 使用 WPF 创建单实例应用程序
一个简单的例子就是大家在使用很多应用程序,例如在使用Microsoft Word 时会遇到一种情况,不管你打开多少个文档,系统一次只能加载一个winword.exe 实例.当打开新文档时,文档在新窗口 ...
- android_定义多个Activity及跳转
说明:在Android应用程序其中创建多个activity,而且启动一个activity的方法,以及activity之间的跳转. 样例:在MainActivity里面加入一个button,触动butt ...
- iOS_数据库3_sqlite3基本操作
终于效果图: Sqlite3函数总结 1.打开数据库 int sqlite3_open( const char *filename, // 数据库的文件路径 sqlite3 **ppDb // 数据 ...
- 【Android进阶】判断网络连接状态并自动界面跳转
用于判断软件打开时的网络连接状态,若无网络连接,提醒用户跳转到设置界面 /** * 设置在onStart()方法里面,可以在界面每次获得焦点的时候都进行检测 */ @Override protecte ...
- CodeForces 69D Dot (游戏+记忆)
Description Anton and Dasha like to play different games during breaks on checkered paper. By the 11 ...
- innerHTML使用方法
使用方法: 比方在<body>中写了例如以下的代码:<div id=top></div> 如今用top.innerHTML="..........&quo ...
- 使用cocoapods install友盟时报错Error installing UMengAnalytics
报错: [!] /usr/bin/unzip /Users/soindy/Documents/SmartThermo/ios/SmartThermo/Pods/UMengAnalytics/file. ...
- mysql数据库的安装以及常见优化设置
原文请详见:http://www.ucai.cn/blogdetail/7036?mid=1&f=5 能够在线执行查看效果哦! 本文依据优才网课程整理,面向web开发人员,内容以有用为主,专业 ...
- RestServer 1.1发布
具体配置方法参照第一版:http://www.cnblogs.com/devgis/p/4947191.html BUG反馈 QQ:80163278 邮箱:devgis@qq.com 淘宝:http: ...