QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#252486 | #7679. Master of Both IV | Cu_OH_2 | TL | 0ms | 3748kb | C++14 | 1.9kb | 2023-11-15 20:06:18 | 2023-11-15 20:06:18 |
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 = 1; i * j <= n; ++j)
{
f[i * j].push_back(i);
}
}
ll ans = 0;
for (int i = 1; i <= n; ++i)
{
if (!cnt[i]) continue;
ll res = 1, tot = 0;
LinearBasis<32> lb;
for (auto e : f[i])
{
tot += cnt[e];
lb.insert(e);
}
ans += qpow(2, tot - lb.rank());
ans %= MOD;
}
LinearBasis<32> lb;
for (int i = 1; i <= n; ++i) lb.insert(a[i]);
ans += qpow(2, n - lb.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: 3748kb
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
Time Limit Exceeded
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 ...