QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#252999 | #7679. Master of Both IV | zhuibao | WA | 66ms | 5604kb | C++20 | 2.9kb | 2023-11-16 16:28:33 | 2023-11-16 16:28:35 |
Judging History
answer
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll>pi; typedef complex<double>cx;
#define int ll
#define X first
#define Y second
#define fer(i,a,n) for(int i=a;i<=n;i++)
#define ref(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,x) memset(a,x,sizeof a)
#define ac IO;int t;cin>>t;while(t--)solve()
#define AC signed main(){IO;solve();}
#define NO {cout<<"No"<<endl;return;}
#define YES {cout<<"Yes"<<endl;return;}
#define re(a) {cout<<a<<endl;return;}
#define all(v) v.begin(),v.end()
//ofstream fout("1.out", ios::out);
//ifstream fin("1.in", ios::in);
//#define cout fout
//#define cin fin
//--------------------瑞神神中神--------------------
const int N=2e5+10,MB=18,P=998244353;
int a[N],vis[N];
int n;
void init()
{
for(int i=1;i<=n;i++)
{
vis[i]=0;
}
}
int qsm(int a,int b)
{
int ans=1;
while(b)
{
if(b&1)ans=ans*a%P;
a=a*a%P;
b>>=1;
}
return ans;
}
struct xxj
{
int p[20];
void init()
{
for(int i=0;i<=MB;i++)
{
p[i]=0;
}
}
void add(int x)
{
if(x==0)return;
for(int i=MB;i>=0;i--)
{
if(!(x&(1ll<<i)))continue;
if(!p[i])
{
p[i]=x;return;
}
x^=p[i];
}
}
int rebuild()
{
int cnt=0;
for(int i=MB;i>=0;i--)
{
for(int j=i-1;j>=0;j--)
if(p[i]&(1<<j))p[i]^=p[j];
}
for(int i=0;i<=MB;i++)
{
if(p[i])cnt++;
}
return cnt;
}
}X;
void solve()
{
cin>>n;
init();
for(int i=1;i<=n;i++)
{
cin>>a[i];
vis[a[i]]++;
}
sort(a+1,a+n+1);
int ans=0;
for(int i=1;i<=n;)
{
int j=i;
while(j<=n&&a[j]==a[i])j++;
X.init();
int sum=0;
for(int d=1;d*d<=a[i];d++)
{
if(a[i]%d||d==a[i])continue;
if(!vis[d])continue;
X.add(d);
sum+=vis[d];
if(d*d!=a[i]&&a[i]/d!=a[i])
{
sum+=vis[a[i]/d];
X.add(a[i]/d);
}
}
int cnt=X.rebuild();
ans=(ans+(qsm(2,sum-cnt)-1)*(j-i)%P)%P;
int len=j-i;
for(int k=1,c=1;i+k<=j;k++)
{
c=c*(len-k+1)%P*qsm(k,P-2)%P;
if(k&1)
{
ans=(ans+c)%P;
}
}
i=j;
}
X.init();
for(int i=1;i<=n;i++)
{
X.add(a[i]);
}
int cnt=X.rebuild();
ans=(ans+(qsm(2,n-cnt))-1)%P;
cout<<ans<<'\n';
}
signed main()
{
ac;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3400kb
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: 66ms
memory: 5604kb
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 16 13 8 11 8 8 8 13 15 9 9 8 8 8 11 9 11 13 15 9 16 9 8 8 8 13 11 8 9 11 8 8 11 15 9 8 9 8 8 15 11 8 16 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 16 13 15 8 8 8 9 8 9 13 15 16 9 9 16 9 11 9 9 11 9 9 11 8 9 9 13 15 11...
result:
wrong answer 23rd numbers differ - expected: '17', found: '16'