Luogu P13685 【MX-X16-T3】「DLESS-3」XOR and Impossible Problem 题解 [ 黄 ] [ Ad-hoc ] [ 值域分治 ]
XOR and Impossible Problem:你怎么知道我被诈骗了/ll/ll/ll
拆位显然是不好做的,注意到模数为 \(2^{64}\),而式子又是一串乘积,因此只要有 \(64\) 个 \(2\) 在乘积里面答案就一定是 \(0\)。对于 \(n\le 200\) 的数据显然直接暴力计算即可;而对于 \(n> 200\) 的数据,分三种情况:
- 至少有两个数相同,此时存在两个数的异或和为 \(0\),答案就是 \(0\)。
- 所有数都不同,则根据异或奇偶性的性质,如果相同奇偶性且不同的数达到了 \(64\) 个,那么答案一定是 \(0\)。又因为 \(n\) 取了 \(200\),所以此情况答案也一定是 \(0\)。
对于 \(n\le 200\),时间复杂度 \(O(tn^2)\)。对于 \(n>200\),时间复杂度 \(O(n)\),瓶颈在于读入。
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb(x) emplace_back(x)
#define pb(x) push_back(x)
#define lc(x) (tr[x].ls)
#define rc(x) (tr[x].rs)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
using pi = pair<int, int>;
const int N = 1000005;
ull n, a[N], ans;
void solve()
{
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
if(n <= 200)
{
ans = 1;
for(int i = 1; i <= n; i++)
for(int j = i + 1; j <= n; j++)
ans *= (a[i] ^ a[j]);
cout << ans << '\n';
}
else
cout << 0 << '\n';
}
int main()
{
//freopen("sample.in", "r", stdin);
//freopen("sample.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--) solve();
return 0;
}

浙公网安备 33010602011771号