QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#670649 | #7679. Master of Both IV | crush_codemaker | TL | 67ms | 38792kb | C++14 | 1.8kb | 2024-10-23 22:45:08 | 2024-10-23 22:45:30 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define N 200007
#pragma GCC optimize(2)
using namespace std;
struct basis
{
int ba[22],r;
void init()
{
for(int j=0;j<22;j++)
{
ba[j]=0;
}
r=0;
}
void ins(int x)
{
for(int j=21;j>=0;j--)
{
if((x>>j)&1)
{
if(!ba[j])
{
ba[j]=x;
r++;
break;
}
x=x^ba[j];
}
}
}
int rk()
{
return r;
}
};
basis bs;
int T,n,a[N],c[N];
vector<int>vc[N];
const int p=998244353;
int qpow(int a,int x)
{
int ans=1;
while(x)
{
if(x&1)
{
ans=(ans*a)%p;
}
a=(a*a)%p;
x>>=1;
}
return ans;
}
void pre()
{
for(int i=1;i<N;i++)
{
for(int j=i+i;j<N;j+=i)
{
vc[j].push_back(i);
}
}
}
void solve()
{
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
for(int i=1;i<=n;i++)
{
c[i]=0;
}
for(int i=1;i<=n;i++)
{
c[a[i]]++;
}
int ans=0;
bs.init();
for(int i=1;i<=n;i++)
{
bs.ins(a[i]);
}
ans=(ans+qpow(2,n-bs.rk()))%p;
ans=((ans-1)%p+p)%p;
for(int i=1;i<=n;i++)
{
if(!c[i])
{
continue;
}
bs.init();
int all=0;
for(int j:vc[i])
{
all+=c[j];
bs.ins(j);
}
ans=(ans+qpow(2,all-bs.rk()+c[i]-1))%p;
}
printf("%lld\n",ans);
}
signed main()
{
cin>>T;
pre();
while(T--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 67ms
memory: 38792kb
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 ...