QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#698650 | #7679. Master of Both IV | jiangzhihui# | WA | 49ms | 3884kb | C++14 | 3.9kb | 2024-11-01 21:02:32 | 2024-11-01 21:02:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std ;
const int mod = 998244353 ;
int norm(int x)
{
if(x < 0) x += mod ;
if(x >= mod) x -= mod ;
return x ;
}
template<class T>
T power(T a , int b)
{
T res = 1 ;
for( ; b ; b /= 2 , a *= a)
if(b % 2) res *= a ;
return res ;
}
template<class T>
T print(T a , int b)
{
T res = 1 ;
for( ; b ; b /= 2 , a *= a)
if(b % 2) res *= a ;
return res ;
}
struct mint
{
int x ;
mint(int x = 0) : x(norm(x)) {}
int val() const
{
return x ;
}
mint operator-() const
{
return mint(norm(mod - x)) ;
}
mint inv() const
{
assert(x != 0);
return power(*this, mod - 2) ;
}
mint &operator*=(const mint &rhs)
{
x = (long long)x * rhs.x % mod ;
return *this ;
}
mint &operator+=(const mint &rhs)
{
x = norm(x + rhs.x) ;
return *this ;
}
mint &operator-=(const mint &rhs)
{
x = norm(x - rhs.x) ;
return *this ;
}
mint &operator/=(const mint &rhs)
{
return *this *= rhs.inv() ;
}
friend mint operator*(const mint &lhs , const mint &rhs)
{
mint res = lhs ;
res *= rhs ;
return res ;
}
friend mint operator+(const mint &lhs , const mint &rhs)
{
mint res = lhs ;
res += rhs ;
return res ;
}
friend mint operator-(const mint &lhs , const mint &rhs)
{
mint res = lhs ;
res -= rhs ;
return res ;
}
friend mint operator/(const mint &lhs , const mint &rhs)
{
mint res = lhs ;
res /= rhs ;
return res ;
}
} ;
ostream& operator<<(std::ostream& os, const mint& m)
{
os << m.x ;
return os ;
}
vector<mint> fac ;
vector<mint> inv ;
void init(int n)
{
n <<= 1 ;
fac.resize(0) ;
fac.resize(n + 10 , mint(1)) ;
inv.resize(0) ;
inv.resize(n + 10 , mint(1)) ;
for(int i = 2 ; i <= n ; i ++) fac[i] = fac[i - 1] * i ;
inv[n] = fac[n].inv() ;
for(int i = n - 1 ; i >= 1 ; i --) inv[i] = inv[i + 1] * (i + 1) ;
}
mint C(int n , int m)
{
if(n < 0 || m < 0 || n < m) return mint(0) ;
return fac[n] * inv[m] * inv[n - m] ;
}
using ll = long long ;
struct Linear_base
{
bool zero ;
int cnt ;
ll b[75] , p[75] ;
void init()
{
zero = 0 ;
cnt = 0 ;
memset(b , 0 , sizeof(b)) ;
memset(p , 0 , sizeof(p)) ;
}
bool insert(ll x)
{
for(int i = 60 ; i >= 0 ; i --)
if(x & (1ll << i))
{
if(b[i]) x ^= b[i] ;
else
{
cnt += 1 ;
b[i] = x ;
return 1 ;
}
}
zero = 1 ;
return 0 ;
}
} linear_base ;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()) ;
long long rand_l_r(long long l , long long r)
{
uniform_int_distribution<long long> dist(l , r) ;
return dist(rnd) ;
}
void solve()
{
int n = 1;
cin >> n ;
init(n) ;
vector<int> a(n) ;
for(int i = 0 ; i < n ; i ++) cin >> a[i] ;
sort(a.begin() , a.end()) ;
vector<int> c(n + 1) ;
mint ans = 0 ;
for(int i = 0 ; i < n ; i ++) c[a[i]] += 1 ;
vector<mint> f(n + 1 , mint(0)) ;
for(int i = 1 ; i <= n ; i ++)
{
for(int j = 0 ; j <= c[i] ; j += 2) f[i] += C(c[i] , j) ;
}
vector<mint> g(n + 1 , mint(0)) ;
for(int i = 1 ; i <= n ; i ++)
{
for(int j = 1 ; j <= c[i] ; j += 2) g[i] += C(c[i] , j) ;
}
vector<vector<int>> p(n + 1) ;
for(int i = 1 ; i <= n ; i ++)
for(int j = i ; j <= n ; j += i)
p[j].push_back(i) ;
for(int i = 1 ; i <= n ; i ++)
{
mint val = 1 ;
for(auto u : p[i])
{
if(u != i) val *= f[u] ;
else val *= g[u] ;
}
// cout << val << "??\n" ;
ans += val ;
}
linear_base.init() ;
for(auto u : a) linear_base.insert(u) ;
if(linear_base.zero) ans += power(mint(2) , n - linear_base.cnt) - 1 ;
cout << ans << '\n' ;
}
int main()
{
std::ios::sync_with_stdio(false) , cin.tie(0) ;
int T ;
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: 3644kb
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: 49ms
memory: 3884kb
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: 3656kb
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:
89 77 80 74 75 84 75 105 143 95 81 74 78 73 73 73 83 93 90 84 79 77 73 89 77 73 81 79 80 175 83 77 83 76 83 85 84 97 74 80 101 74 113 74 75 95 75 83 86 77 99 73 77 83 91 96 77 80 77 76 80 81 73 95 83 74 75 81 77 79 74 76 78 81 97 77 85 73 92 83 73 80 73 77 74 73 142 83 99 78 91 77 76 81 77 74 78 76 ...
result:
wrong answer 1st numbers differ - expected: '97', found: '89'