QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#612504 | #7679. Master of Both IV | zhangboju | WA | 25ms | 12392kb | C++17 | 2.4kb | 2024-10-05 11:38:07 | 2024-10-05 11:38:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 2e5 + 5, mod = 1e9 + 7;
struct Base{
int a[20];
void init() {
for (int i = 0; i < 20; i++)
a[i] = 0;
}
void insert(int x) {
for (int i = 19; i >= 0; i--) {
if (!((x >> i) & 1)) {
continue;
}
if (!a[i]) {
a[i] = x;
break;
}
x ^= a[i];
}
}
int count() {
int cnt = 0;
for (int i = 0; i < 20; i++)
if (a[i])
cnt++;
return cnt;
}
};
int n;
int pw[N];
int a[N];
int cnt[N];
vector<int> d[N];
int fac[N], inv[N];
int qpow(int a, int k) {
int res = 1;
while (k) {
if (k & 1) res = 1ll * res * a % mod;
a = 1ll * a * a % mod;
k >>= 1;
}
return res;
}
void init(int n) {
pw[0] = 1;
for (int i = 1; i <= n; i++)
pw[i] = 2ll * pw[i - 1] % mod;
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = 1ll * fac[i - 1] * i % mod;
inv[n] = qpow(fac[n], mod - 2);
for (int i = n - 1; i >= 0; i--)
inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
}
int C(int n, int m) {
if (m < 0 || n < m) return 0;
return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
void solve() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
cnt[a[i]]++;
}
for (int i = 1; i <= n; i++)
for (int j = 2 * i; j <= n; j += i)
d[j].push_back(i);
Base alls;
alls.init();
for (int i = 1; i <= n; i++)
alls.insert(a[i]);
int ans = pw[n - alls.count()] - 1;
for (int i = 1; i <= n; i++) {
if (!cnt[i]) continue;
Base B;
B.init();
int sum = 0;
for (int x : d[i]) {
if (cnt[x]) {
B.insert(x);
sum += cnt[x];
}
}
ans = (ans + 1ll * cnt[i] * pw[sum - B.count()]) % mod;
for (int t = 3; t <= cnt[i]; t += 2)
ans = (ans + C(cnt[i], t)) % mod;
}
printf("%d\n", ans);
}
void clear() {
for (int i = 0; i <= n; i++)
cnt[i] = 0, d[i].clear();
}
int main() {
init(N - 1);
int T;
scanf("%d", &T);
while (T--) {
solve();
clear();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 11716kb
input:
2 3 1 2 3 5 3 3 5 1 1
output:
4 11
result:
ok 2 number(s): "4 11"
Test #2:
score: -100
Wrong Answer
time: 25ms
memory: 12392kb
input:
40000 5 4 2 5 5 5 5 5 5 5 5 4 5 1 4 4 4 2 5 2 5 2 4 1 5 3 2 4 5 3 5 1 5 5 3 4 5 5 5 5 4 3 5 4 3 3 5 1 5 4 5 5 2 1 5 2 5 4 2 5 5 3 4 3 4 3 5 5 3 5 1 3 5 5 1 2 4 4 5 4 2 5 1 5 5 5 4 2 5 4 5 5 2 5 2 4 5 1 4 5 4 5 5 4 2 3 2 3 5 1 4 1 3 5 5 1 1 2 1 5 5 5 2 5 1 3 5 3 1 2 5 3 5 5 5 1 1 5 5 2 2 2 1 3 5 3 1 ...
output:
9 16 9 9 8 8 9 8 8 9 13 8 8 8 8 9 12 9 11 15 8 8 16 13 8 11 8 8 8 13 15 9 9 8 8 8 11 9 11 13 15 9 16 9 8 8 8 13 11 8 9 11 8 8 11 15 9 8 9 8 8 15 11 8 16 9 15 8 8 8 12 9 9 11 8 13 9 8 15 8 8 9 8 8 8 15 8 11 13 8 9 11 8 19 11 13 19 16 13 15 8 8 8 9 8 9 13 15 16 9 9 16 9 11 9 9 11 9 9 11 8 9 9 13 15 11...
result:
wrong answer 23rd numbers differ - expected: '17', found: '16'