XMAX - XOR Maximization

Given a set of integers S = { a1, a2, a3, ... a|S| }, we define a function X on S as follows:
X( S ) = a1 ^ a2 ^ a3 ^ ... ^ a|S|.
(^ stands for bitwise 'XOR' or 'exclusive or')

Given a set of N integers, compute the maximum of the X-function over all the subsets of the given starting set.

Input

The first line of input contains a single integer N, 1 <= N <= 105.
Each of the next N lines contain an integer ai, 1 <= ai <= 1018.

Output

To the first line of output print the solution.

Example

Input:

3
1
2
4
Output: 7

高斯消元类似。尽量变幻成上三角矩阵。每一位尽量留一个1

如矩阵:

010000

001000

000100

000010

就是一个理想的矩阵。

/* ***********************************************
Author :guanjun
Created Time :2016/9/8 15:30:01
File Name :spoj_XMAX.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 100010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(ll a,ll b){
return a>b;
}
ll a[maxn];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int n;
while(cin>>n){
for(int i=;i<=n;i++)cin>>a[i];
sort(a+,a++n,cmp);
int row=;
for(int i=;i>=;i--){
for(int j=row;j<=n;j++){
if(a[j]&(1LL<<i)){
swap(a[row],a[j]);
for(int k=;k<=n;k++){
if((a[k]&(1LL<<i))&&(k!=row)){
a[k]=a[k]^a[row];
}
//puts("YES");
}
row++;
}
}
}
ll ans=0LL;
for(int i=;i<=n;i++){
// cout<<a[i]<<endl;
ans^=a[i];
}
cout<<ans<<endl;
}
return ;
}

SPOJ XMAX - XOR Maximization的更多相关文章

  1. SPOJ Find the max XOR value(二进制,贪心即可)

    You have two integers L and R, and you are required to find the max xor value of a and b where L < ...

  2. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  3. SPOJ COT3 Combat on a tree(Trie树、线段树的合并)

    题目链接:http://www.spoj.com/problems/COT3/ Alice and Bob are playing a game on a tree of n nodes.Each n ...

  4. BZOJ 2588: Spoj 10628. Count on a tree 树上跑主席树

    2588: Spoj 10628. Count on a tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/J ...

  5. Bzoj 2588: Spoj 10628. Count on a tree 主席树,离散化,可持久,倍增LCA

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2588 2588: Spoj 10628. Count on a tree Time Limit ...

  6. 图论(网络流):SPOJ OPTM - Optimal Marks

    OPTM - Optimal Marks You are given an undirected graph G(V, E). Each vertex has a mark which is an i ...

  7. BZOJ 2588: Spoj 10628. Count on a tree( LCA + 主席树 )

    Orz..跑得还挺快的#10 自从会树链剖分后LCA就没写过倍增了... 这道题用可持久化线段树..点x的线段树表示ROOT到x的这条路径上的权值线段树 ----------------------- ...

  8. 【BZOJ2588】Spoj 10628. Count on a tree 主席树+LCA

    [BZOJ2588]Spoj 10628. Count on a tree Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lasta ...

  9. SPOJ SUBXOR

    SPOJ SUBXOR 题意 给定一个由正整数构成的数组, 求 异或和小于k 的子序列的个数. 题解 假设答案区间为 [L, R], XOR[L, R] 等价于 XOR[1, L - 1] ^ XOR ...

随机推荐

  1. python 3 Urllib 数据抓取

    1.0 Urllib简介 Urllib是python自带的标准库,无需安装,直接引用即可.urllib通常用于爬虫开发,API(应用程序编程接口)数据获取和测试.在python2和python3中,u ...

  2. CAD指定区域绘制一个jpg文件

    主要用到函数说明: _DMxDrawX::DrawToJpg 把指定区域的内容绘制一个jpg文件中.详细说明如下: 参数 说明 BSTR sJpgFilePath Jpg文件名 DOUBLE dLbx ...

  3. ThinkPHP---thinkphp拓展之空操作

    [一]概论 (1)定义 空操作指系统在找不到指定操作方法的时候.会定位到空操作方法 / 控制器来执行,利用这个机制,我们可以实现错误页面的自定义和URL的优化 (2)场景 常用于错误页面的自定义 (3 ...

  4. 【转】Go语言入门教程(一)Linux下安装Go

    说明 系统是Ubuntu. 关于安装 下载安装包 当前官方下载地址是https://golang.org/dl/,如果不能访问,请自行FQ,FQ是技术工作者的必备技能. 安装 tar -xzvf go ...

  5. 后台中的sql注入

    aa.getSqlMap().put("order"," and a.id not in(\'"+po.getId()+"\')"); \' ...

  6. java计算两地距离(公里)

    //目标经度,目标纬度,自己经度,自己纬度 public static double getDistance(double lon1, double lat1, double lon2, double ...

  7. [luogu4571 JSOI2009] 瓶子和燃料 (数论)

    传送门 Solution 题目说的很迷,但可以发现两个瓶子互相倒最少是容积的gcd 那么题目就转化为求其中选k个瓶子gcd的最大值,这个可以分解因数,枚举因数得到 Code //By Menteur_ ...

  8. mysql function 查询子级机构

    DROP FUNCTION IF EXISTS queryChildOrgList;CREATE FUNCTION queryChildOrgList(id VARCHAR(20))RETURNS V ...

  9. BZOJ 2095 [POI2010]Bridges (最大流、欧拉回路)

    洛谷上有这题,但是输出方案缺SPJ..(而且我也懒得输出方案了) 题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2095 题解: 首先判 ...

  10. 【Codeforces 522B】Photo to Remember

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 模拟题.用set模拟下就好 [代码] import java.io.*; import java.util.*; public class M ...