QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#617340 | #7679. Master of Both IV | ShwStone | WA | 19ms | 9408kb | C++14 | 1.3kb | 2024-10-06 15:00:54 | 2024-10-06 15:00:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MAXN(2e5 + 5);
const int MOD(998244353);
int n, ans;
vector<pair<int, int>> vec[MAXN];
int book[MAXN];
int c[20];
int quickPow(int x, int p) {
int res = 1;
for (; p; x = 1ll * x * x % MOD, p >>= 1) {
if (p & 1) res = 1ll * res * x % MOD;
}
return res;
}
int insert(int x) {
for (int i = 19; i >= 0; i--) {
if ((x >> i) & 1) {
if (c[i]) x ^= c[i];
else {
c[i] = x;
return -1;
}
}
}
return 0;
}
int calc(int x) {
int cnt = 0;
memset(c, 0, sizeof c);
for (auto p : vec[x]) {
cnt += p.second + insert(p.first);
}
return quickPow(2, cnt);
}
void solve() {
scanf("%d", &n);
for (int i = 0; i <= n; i++) {
vec[i].clear();
book[i] = 0;
}
for (int i = 1; i <= n; i++) {
int x; scanf("%d", &x);
book[x]++;
}
for (int i = 1; i <= n; i++) {
if (book[i]) {
vec[0].emplace_back(i, book[i]);
for (int j = i * 2; j <= n; j += i) {
vec[j].emplace_back(i, book[i]);
}
}
}
ans = (calc(0) + MOD - 1) % MOD;
for (int i = 1; i <= n; i++) {
if (book[i]) {
ans = (ans + 1ll * book[i] * calc(i)) % MOD;
}
}
printf("%d\n", ans);
}
int main() {
int _;
scanf("%d", &_);
while (_--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 8444kb
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: 19ms
memory: 9408kb
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:
8 12 8 9 8 8 8 8 8 9 12 8 8 8 8 9 12 9 11 14 8 8 15 12 8 11 8 8 8 12 15 9 9 8 8 8 11 9 11 12 15 8 15 8 8 8 8 12 11 8 8 11 8 8 11 15 9 8 9 8 8 14 11 8 15 9 15 8 8 8 12 9 8 11 8 13 9 8 14 8 8 8 8 8 8 15 8 11 12 8 9 11 8 18 11 13 18 15 12 14 8 8 8 9 8 8 12 15 15 8 9 15 9 11 8 8 11 8 9 11 8 9 8 12 15 11...
result:
wrong answer 1st numbers differ - expected: '9', found: '8'