QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#610898 | #7679. Master of Both IV | ANIG# | TL | 620ms | 26740kb | C++14 | 1.7kb | 2024-10-04 17:58:59 | 2024-10-04 17:59:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mods=998244353,N=5e5+5;
int M;
int pows(int a,int b){
if(b==0)return 1;
int res=pows(a,b>>1);
res=res*res%mods;
if(b&1)res=res*a%mods;
return res;
}
const int inv2=pows(2,mods-2);
int t,n,p[N],sm[N],jc[N],ny[N],f[N],pw[N],cnt[N],g[N],dp[N][2];
void XOR(int *p,int n,int op){
for(int mid=1;mid<n;mid<<=1){
for(int i=0;i<n;i+=mid<<1){
for(int j=0;j<mid;j++){
int x=p[i+j],y=p[i+j+mid];
p[i+j]=(x+y)%mods,p[i+j+mid]=(x-y)%mods;
}
}
}
if(op!=1)for(int i=0;i<n;i++)p[i]=p[i]*pows(n,mods-2)%mods;
}
bool ok(int x){
for(int i=1;i<=n;i++)if(sm[i])if(cnt[i&x]&1)return 0;
return 1;
}
bool ok(int x,int y){
for(int i=1;i<=n;i++)if(sm[i]&&y%i==0&&y!=i)if(cnt[i&x]&1)return 0;
return 1;
}
int C(int a,int b){
return jc[a]*ny[b]%mods*ny[a-b]%mods;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
jc[0]=ny[0]=1;pw[0]=1;
for(int i=1;i<N;i++)jc[i]=jc[i-1]*i%mods,ny[i]=pows(jc[i],mods-2),pw[i]=pw[i-1]*2%mods,cnt[i]=cnt[i&-i^i]+1;
cin>>t;
while(t--){
for(int i=0;i<M;i++)f[i]=0;
for(int i=1;i<=n;i++)sm[i]=0;
int res=0;
cin>>n;
M=1;
while(M<=n)M<<=1;
for(int i=1;i<=n;i++)cin>>p[i],sm[p[i]]++;
for(int i=0;i<M;i++){
if(ok(i))f[i]=pw[n];
}
for(int i=1;i<=n;i++){
if(!sm[i])continue;
for(int j=0;j<M;j++)g[j]=0;
int sms=0;
for(int j=1;j<i;j++)if(i%j==0)sms+=sm[j];
for(int j=0;j<M;j++)if(ok(j,i))g[j]=pw[sms+sm[i]-1];
XOR(g,M,inv2);
res+=g[0]%mods;
}
XOR(f,M,inv2);
res+=f[0];
cout<<(res%mods-1+mods)%mods<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 98ms
memory: 26740kb
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: 391ms
memory: 25384kb
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: 0
Accepted
time: 620ms
memory: 25464kb
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 77 82 74 75 84 75 105 159 95 81 74 78 75 73 73 83 93 90 84 79 77 73 89 77 74 81 79 80 207 83 77 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:
ok 20000 numbers
Test #4:
score: -100
Time Limit Exceeded
input:
10000 20 5 12 4 16 11 20 3 1 3 13 19 16 3 17 15 9 10 18 19 13 20 4 17 14 3 3 10 6 17 16 17 16 8 1 15 13 12 8 12 10 9 20 18 11 5 11 5 5 9 3 17 10 6 8 5 10 11 15 19 9 10 11 20 7 7 12 13 20 9 14 17 1 10 13 20 10 19 3 12 1 8 8 3 20 13 20 17 12 6 1 16 5 3 2 18 7 2 7 20 1 12 4 7 1 20 15 6 13 1 10 5 13 3 4...
output:
32801 32799 32832 32817 32955 65621 32919 32865 32843 32798 32792 32843 32796 32823 32803 32807 32797 32859 32806 32799 32806 32813 32893 32798 32798 32799 32832 32792 32825 32817 32867 32795 32806 32796 32794 32943 32795 32791 65732 32842 32841 32841 32806 32804 32852 32795 32867 32798 32841 32823 ...