QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#704#456139#8823. Game: Battle of MenjisyemuzheyemuzheSuccess!2024-06-27 11:29:042024-06-27 11:29:06

详细

Extra Test:

Wrong Answer
time: 0ms
memory: 1540kb

input:

1
2 1
1000000000 1

output:

1000000000

result:

wrong answer 1st numbers differ - expected: '1000000001', found: '1000000000'

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#456139#8823. Game: Battle of MenjisyemuzheWA 47ms2024kbC++14840b2024-06-27 11:27:492024-06-27 11:29:47

answer

#include <cstdio>
#include <algorithm>
#define N 100005
#define LGA 35
#define ctz __builtin_ctz
using namespace std;

const int lga = 29;

int T, n, s, ans, a[N], cnt[LGA];

int main ()
{
	scanf ("%d", &T);
	while (T --)
	{
		scanf ("%d%*d", &n), s = ans = 0;
		for (int i = 0; i <= lga; i ++) cnt[i] = 0;
		for (int i = 1; i <= n; i ++)
		{
			scanf ("%d", &a[i]), s ^= a[i];
			if (a[i]) cnt[ctz (a[i])] ++;
			if (a[i] == 1e9) break;
		}
		for (int i = 1, res; res = s, i <= n; i ++)
		{
			if (a[i]) cnt[ctz (a[i])] --;
			for (int j = 0; j <= lga; j ++) if (cnt[j])
			{
				int now = s ^ a[i] ^ a[i] + 1;
				now ^= 1 << j ^ (1 << j) - 1;
				res = min (res, now);
			}
			ans = max (ans, res);
			if (a[i]) cnt[ctz (a[i])] ++;
		}
		printf ("%d\n", ans);
	}
	return 0;
}

/*
1
2 1
1 1
*/