QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#252553 | #7679. Master of Both IV | Cu_OH_2 | WA | 41ms | 3632kb | C++14 | 2.1kb | 2023-11-15 21:04:44 | 2023-11-15 21:04:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;
template<int bit>
struct LinearBasis
{
vector<ll> v;
LinearBasis() { v.resize(bit); }
void insert(ll x)
{
for (int i = bit - 1; i >= 0; --i)
{
if (x >> i & 1ll)
{
if (v[i]) x ^= v[i];
else
{
v[i] = x;
break;
}
}
}
return;
}
int rank()
{
int cnt = 0;
for (auto e : v)
{
if (e) cnt++;
}
return cnt;
}
};
ll qpow(ll a, ll p)
{
ll res = 1;
while (p)
{
if (p & 1) res = res * a % MOD;
a = a * a % MOD;
p >>= 1;
}
return res;
}
int n, a[200005];
void solve()
{
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
// xorsum = max_element
vector<ll> cnt(n + 1);
for (int i = 1; i <= n; ++i) cnt[a[i]]++;
vector<vector<int>> f(n + 1);
for (int i = 1; i <= n; ++i)
{
for (int j = 2; i * j <= n; ++j)
{
f[i * j].push_back(i);
}
}
ll ans = 0;
vector<LinearBasis<20>> lb(n + 1);
sort(a + 1, a + 1 + n);
int cur = 0;
for (int i = 1; i <= n; ++i)
{
if (a[i] == a[i - 1]) cur++;
else cur = 1;
ll tot = 0;
LinearBasis<20> lb;
for (auto e : f[a[i]])
{
tot += cnt[e];
if (cnt[e]) lb.insert(e);
}
tot += cur - 1;
if (cur > 1) lb.insert(i);
// cerr << tot << ' ' << lb.rank() << endl;
ans = (ans + qpow(2, tot - lb.rank())) % MOD;
}
LinearBasis<20> lbb;
for (int i = 1; i <= n; ++i) lbb.insert(a[i]);
ans += qpow(2, n - lbb.rank());
ans %= MOD;
cout << (ans + MOD - 1) % MOD << '\n';
return;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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: 0
Accepted
time: 32ms
memory: 3624kb
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 17 13 8 11 8 8 8 13 15 9 9 8 8 8 11 9 11 13 15 9 17 9 8 8 8 13 11 8 9 11 8 8 11 15 9 8 9 8 8 15 11 8 17 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 17 13 15 8 8 8 9 8 9 13 15 17 9 9 17 9 11 9 9 11 9 9 11 8 9 9 13 15 11...
result:
ok 40000 numbers
Test #3:
score: -100
Wrong Answer
time: 41ms
memory: 3632kb
input:
20000 10 1 3 6 8 3 1 10 7 2 3 10 8 2 8 9 10 5 8 4 8 3 10 2 2 10 1 6 4 4 3 4 7 10 6 5 10 7 8 7 3 1 6 6 10 3 2 3 7 8 4 9 8 8 7 10 9 9 6 4 9 3 9 10 5 9 10 10 8 9 10 10 4 5 1 4 3 10 2 10 4 5 8 10 2 2 7 2 10 2 6 4 10 1 1 1 1 2 3 10 1 10 2 8 1 5 9 4 3 1 10 8 1 8 1 9 5 6 7 2 9 10 1 6 7 4 8 8 7 3 5 7 10 10 ...
output:
97 78 82 74 75 84 75 105 159 95 81 74 78 75 74 73 83 93 90 84 79 77 73 89 77 74 81 79 80 207 83 78 83 78 87 85 84 97 75 80 117 75 113 74 75 95 77 83 86 77 99 73 77 83 91 96 77 80 77 76 84 81 73 95 83 74 75 81 77 79 75 78 78 81 97 77 85 73 92 83 73 80 73 81 74 73 142 83 99 78 91 77 76 81 77 74 78 76 ...
result:
wrong answer 2nd numbers differ - expected: '77', found: '78'