QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#592759 | #9305. Steins;Game | real_sigma_team# | WA | 7ms | 11612kb | C++17 | 2.9kb | 2024-09-27 02:54:32 | 2024-09-27 02:54:32 |
Judging History
answer
#include <bits/stdc++.h>
#include <immintrin.h>
using namespace std;
using ll = long long;
using ld = long double;
# define x first
# define y second
# define all(x) x.begin(), x.end()
# define rall(x) x.rbegin(), x.rend()
mt19937 mt(123);
void solve();
void init();
int32_t main() {
#ifndef LOCAL
cin.tie(nullptr)->sync_with_stdio(false);
#endif
init();
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
constexpr int mod = 1'000'000'007, MAXN = 1'000'000;
int add(int a, int b) {
return a + b >= mod ? a + b - mod : a + b;
}
int sub(int a, int b) {
return a >= b ? a - b : a - b + mod;
}
int mul(int a, int b) {
return 1ll * a * b % mod;
}
int bin_pow(int a, int x) {
int res = 1;
while (x) {
if (x & 1) {
res = mul(res, a);
}
a = mul(a, a);
x >>= 1;
}
return res;
}
struct popka {
vector<ll> basis;
size_t sz;
popka() {
sz = 0;
basis.clear();
}
void insert(ll x) {
int ind = 0;
sz++;
for (ll i : basis) {
int bti = 63 - __builtin_clzll(i);
int btx = 63 - __builtin_clzll(x);
if (bti < btx) {
break;
}
ind++;
if (bti == btx) {
x ^= i;
}
}
if (x) {
basis.emplace(basis.begin() + ind, x);
}
}
int check(ll x) {
for (ll i : basis) {
int bti = 63 - __builtin_clzll(i);
int btx = 63 - __builtin_clzll(x);
if (bti < btx) {
break;
}
if (bti == btx) {
x ^= i;
}
}
if (x) {
return 0;
}
return bin_pow(2, sz - basis.size());
}
};
int inv(int x) {
return bin_pow(x, mod - 2);
}
int f[MAXN], invf[MAXN];
void init() {
f[0] = 1;
for (int i = 1; i < MAXN; i++) {
f[i] = mul(f[i - 1], i);
}
invf[MAXN - 1] = inv(f[MAXN - 1]);
for (int i = MAXN - 1; i > 0; i--) {
invf[i - 1] = mul(invf[i], i);
}
}
int C(int n, int k) {
return mul(f[n], mul(invf[k], invf[n - k]));
}
void solve() {
popka p;
ll n;
cin >> n;
vector<ll> arr(n);
for (ll i = 0; i < n; i++) {
cin >> arr[i];
}
ll nx = 0;
sort(arr.begin(), arr.end());
for (auto i : arr) {
nx ^= i;
}
ll ans = 0;
if (nx == 0) {
ans++;
}
ll px = 0;
while (!arr.empty()) {
ll x = arr.back();
ll c = 0;
while (!arr.empty() && arr.back() == x) {
c++;
arr.pop_back();
}
for (ll nc = 1; nc <= c; nc++) {
nx ^= x;
ll now = x;
if (nc % 2 == 1) {
now--;
}
ll nans = p.check(now ^ nx);
{
if (px == (now ^ nx)) {
nans = sub(nans, 1);
}
if (nc % 2 == 1) {
now++;
} else {
now--;
}
if (px == (now ^ nx)) {
nans = add(nans, 1);
}
}
ans = add(ans, mul(nans, C(c, nc)));
}
for (ll nc = 0; nc < c; nc++) {
px ^= x;
p.insert(x);
}
}
cout << ans << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 7ms
memory: 11412kb
input:
2 1 1
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 11612kb
input:
2 1 2
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'