QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#265138 | #7679. Master of Both IV | qkm66666# | TL | 37ms | 20296kb | C++14 | 2.9kb | 2023-11-25 16:55:58 | 2023-11-25 16:55:58 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
const int maxn=4e5,mod=998244353;
int T,n;
int a[maxn],Cnt[maxn],cnt[maxn];
int base[maxn][30],siz[maxn];
long long po[maxn],fac[maxn],inv[maxn],Ans;
long long tot,p[maxn];
long long qpow(long long x,int n){
long long ret=1;
while(n){
if(n&1){ret=ret*x%mod;}
x=x*x%mod;
n>>=1;
}
return ret;
}
void Add(int num,int x){
for(int i=20;i>=0;i--){
if(x&(1<<i)){
if(base[num][i]){
x^=base[num][i];
}
else{
siz[num]++;
base[num][i]=x;
return;
}
}
}
return;
}
void Merge(int a,int b,int c){//a,b合并到c
if(siz[a]<siz[b]) swap(a,b);
siz[0]=siz[a];
for(int i=0;i<=20;i++){
base[0][i]=base[a][i];
}
for(int i=0;i<20;i++){
if(base[b][i]){
Add(0,base[b][i]);
}
}
siz[c]=siz[0];
for(int i=0;i<=20;i++){
base[c][i]=base[0][i];
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
po[0]=1;
for(int i=1;i<=200000;i++){
po[i]=po[i-1]*2%mod;
}
fac[0]=1;
for(int i=1;i<=200000;i++){
fac[i]=fac[i-1]*i%mod;
}
inv[200000]=qpow(fac[200000],mod-2);
for(int i=200000;i>=1;i--){
inv[i-1]=inv[i]*i%mod;
}
tot=0;
for(int i=2;i<=200000;i++){
bool flag=true;
for(int j=1;j<=tot;j++){
if(i%p[j]==0) flag=false;
if(p[j]*p[j]>i) break;
}
if(flag){
p[++tot]=i;
}
}
cin>>T;
while(T--){
cin>>n;
for(int i=1;i<=n;i++){
cnt[i]=0;
Cnt[i]=0;
siz[i]=0;
for(int j=0;j<=20;j++){
base[i][j]=0;
}
}
siz[0]=0;
for(int i=0;i<=20;i++){
base[0][i]=0;
}
for(int i=1;i<=n;i++){
cin>>a[i];
cnt[a[i]]++;
Add(0,a[i]);
}
Ans=(po[n-siz[0]]-1);
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j+=i){
Cnt[j]+=cnt[i];
}
}
for(int i=1;i<=n;i++){
siz[i]=siz[1];
for(int j=0;j<=20;j++){base[i][j]=base[1][j];}
for(int j=1;j<=tot;j++){
if(i%p[j]==0){
Merge(i,i/j,i);
}
}
long long C=0;
for(int j=1;j<=cnt[i];j+=2){
C=(C+fac[cnt[i]]*inv[j]%mod*inv[cnt[i]-j]%mod)%mod;
}
Ans=(Ans+1ll*C*po[Cnt[i]-cnt[i]-siz[i]])%mod;
if(cnt[i]){
Add(i,i);
}
}
printf("%lld\n",Ans);
}
//system("pause");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 37ms
memory: 20296kb
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 ...
output:
10 16 13 11 9 8 9 8 9 11 13 8 10 9 10 11 12 11 11 15 8 8 17 13 9 11 8 9 10 13 15 11 11 9 9 9 11 11 11 13 15 9 25 9 9 9 8 13 11 10 9 11 8 10 11 15 11 10 11 9 9 19 11 9 17 11 15 8 10 10 12 11 13 11 10 17 11 8 19 10 9 10 9 9 8 15 8 11 13 9 11 13 9 19 13 17 19 17 13 15 10 8 8 11 8 9 13 15 17 10 11 17 11...