比赛 NOIP模拟赛1 评测结果 AAAWWWWWWW
题目名称 异或 最终得分 30
用户昵称 Kyru Yann 运行时间 0.323 s
代码语言 C++ 内存使用 0.56 MiB
提交时间 2018-02-08 21:19:01
显示代码纯文本
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <cctype>
#include <iomanip>
#define inf 0x7f7f7f7f
using namespace std;
int n,k,a[100005],nums=0,ret,blk,block_upper[50]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432};
struct data
{
	int val;
	friend bool operator < (data a,data b)
	{
		return a.val>b.val;
	}
};
priority_queue<data>pq;
int find_block(int x)
{
	ret=block_upper[(int)ceil((double)log(x)/log(2))];
	if(ret==x) return ret*2;
	return ret;
}
int main()
{
	freopen("xorxor.in","r+",stdin);
	freopen("xorxor.out","w+",stdout);
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	if(n<=500)
	{
		for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++) pq.push((data){a[i]^a[j]});
		for(int i=1;i<k;i++) pq.pop();
		cout<<pq.top().val<<endl;
	}
	else
	{
		for(int i=1;i<=n && nums<=500005;i++)
		{
			int j;
			blk=find_block(a[i]);
			for(j=i+1;j<=n && a[j]<blk && nums<=500005;j++)
			{
				pq.push((data){a[i]^a[j]});
				nums++;
			}
			pq.push((data){a[i]^a[j++]});
			pq.push((data){a[i]^a[j++]});
			pq.push((data){a[i]^a[j++]});
			pq.push((data){a[i]^a[j++]});
			pq.push((data){a[i]^a[j++]});
			nums+=5;
		}
		for(int i=1;i<k;i++) pq.pop();
		cout<<pq.top().val<<endl;
	}
	return 0;
}