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 ...
随机推荐
- iOS Crash获取闪回日志和上传server
首先我们整理常常会闪退的异常哪些:数组越界.空引用.引用没有定义方法.内存空间不足等等. 怎样获取crash闪退日志 -- 工具查看 先看第一个问题怎样查看,我搜索的方法有下面几个: 第一个方法:XC ...
- DiskFileUpload类别
1.2.2 DiskFileUpload类 DiskFileUpload类是Apache文件上传组件的核心类,应用程序开发者通过这个类来与Apache文件上传组件进行交互.以下介绍DiskFileUp ...
- js你真的了解offsetWidth吗
offsetWidth是什么? 答:它可以获取物体宽度的数值 那么就只是这样吗! html部分 <div id="div1"></div> <styl ...
- Android 学习历程摘要(二)
1.资源文件命名仅仅能小写,否则会报错生成不了R.java文件 2.R文件导包时应该导入自己project的包,而不是android.R 3.数据库操作使用SqliteOpenHelper 4.val ...
- JTable demo
简单讲就是在没有使用layout manager的时候用setSize,在使用了layout manager 的时候用setPreferredSize 并且setPreferredSize通常和set ...
- Hibernate学习笔记(1)Hibernate构造
一 准备工作 首先,我们将创建一个简单的基于控制台(console-based)Hibernate应用. 我们所做的第一件事就是创建我们的开发文件夹.并把所有需要用到的Java件放进去.解压缩从Hib ...
- PowerDesigner有几个需要设置
安装后PDM后.一些易于使用的设计人才需求. 一. 建立name与code做自己的主动关联,我们输入name当你不希望个别及连带code已经改变. 打开Tools->General Option ...
- 为了解决这个问题:07文本WORD文档超链接、页码成{HYPERLINK"网站"}、{PAGE}/{NUMPAGES}
版权声明:本文博主原创文章.博客,未经同意不得转载.
- 【SSH进阶之路】一步步重构容器实现Spring框架——彻底封装,实现简单灵活的Spring框架(十一)
文件夹 [SSH进阶之路]一步步重构容器实现Spring框架--从一个简单的容器開始(八) [SSH进阶之路]一步步重构容器实现Spring框架--解决容器对组件的"侵入 ...
- 姿势体系结构的详细解释 -- C
我基本上总结出以下4部分: 1.问题的足迹大小. 2.字节对齐问题. 3.特别保留位0. 4.这种结构被存储在存储器中的位置. #include <stdio.h> #include &l ...