QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#608719 | #7679. Master of Both IV | MENDAX | WA | 43ms | 18012kb | C++14 | 1.9kb | 2024-10-04 01:37:31 | 2024-10-04 01:37:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define x first
#define y second
const int N=5e5+5,mod=998244353;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int qmi(int a,int k){
int res=1;
while(k){
if(k&1) res=res*a%mod;
a=a*a%mod;
k>>=1;
}
return res;
}
typedef pair<int,int> PII;
int a[N];
const int B=30;
struct linear_basis{
int num[B+1];
void init(){
for(int i=0;i<=B;i++) num[i]=0;
}
bool insert(int x){
for(int i=B;i>=0;i--){
if(x>>i&1){
if(num[i]==0){num[i]=x;return true;}
x^=num[i];
}
}
return false;
}
int querymin(int x){
for(int i=B;i>=0;i--){
x=min(x,x^num[i]);
}
return x;
}
int querymax(int x){
for(int i=B;i>=0;i--){
x=max(x,x^num[i]);
}
return x;
}
}T;
/*
直接枚举异或完的结果,然后把所有的值都加进去即可
首先基向量至少得都是
*/
vector<int> pr[N];
int num[N];//实际上的
void slove(){
int n;cin>>n;
int m=2*n;
T.init();
for(int i=1;i<=n;i++) a[i]=0;
int pp=0;
for(int i=1;i<=n;i++){
int x;cin>>x;
a[x]++;
if(T.insert(x)) pp++;
}
int ans=0;
ans+=qmi(2,n-pp)-1;
for(int i=1;i<=m;i++) pr[i].clear(),num[i]=0;
for(int i=n;i>=1;i--){//看看能不能被异或表示出来即可
if(a[i]){
for(int j=i;j<=m;j+=i) pr[j].push_back(i),num[j]+=a[i];
}
}
for(int i=m;i>=1;i--){
if(pr[i].size()){
T.init();
int len=pr[i].size();
int zero=0;
for(auto zz:pr[i]){
if(T.insert(zz)) zero++;
}
bool ok=true;
for(int u=30;u>=0;u--){
if(i>>u&1){
if(!T.num[u]){
ok=false;
break;
}
}
}
if(ok){
// cout<<i<<" "<<zero<<endl;
ans+=qmi(2,num[i]-zero)%mod;
ans%=mod;
}
}
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int T=1;
cin>>T;
while(T--) slove();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 15972kb
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
Wrong Answer
time: 43ms
memory: 18012kb
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:
5 8 9 9 5 8 4 8 8 7 9 8 8 8 6 7 12 7 11 15 8 8 17 13 8 11 8 5 6 13 15 9 7 8 8 5 11 9 11 13 15 4 17 4 8 8 8 7 11 8 7 11 8 6 11 15 9 8 7 8 8 15 11 8 17 7 15 8 8 8 12 9 8 11 8 13 9 8 15 6 8 5 5 8 4 15 8 11 9 8 9 11 8 19 11 13 19 17 11 15 6 8 4 7 5 7 11 15 17 5 7 17 9 11 9 5 11 9 7 11 8 9 9 13 15 11 8 1...
result:
wrong answer 1st numbers differ - expected: '9', found: '5'