QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#552288#7679. Master of Both IVJiangnan01TL 24ms58060kbC++171.9kb2024-09-07 21:42:522024-09-07 21:42:52

Judging History

你现在查看的是最新测评结果

  • [2024-09-07 21:42:52]
  • 评测
  • 测评结果:TL
  • 用时:24ms
  • 内存:58060kb
  • [2024-09-07 21:42:52]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 2e5+10;
const int p1=998244353;
int p[MAXN][32];
int ra[MAXN],con[MAXN];//记录秩,因子个数
int mp[MAXN];//数的个数
set<int> a;
int r=0;

int ksm(int x,int y)
{
    int ans=1;
    while(y>0)
    {
        if(y&1)ans=ans*x%p1;
        x=x*x%p1;
        y>>=1;
    }
    return ans;
}

int add(int x,int k)
{
    for(int i=0;i<=31;i++)
    {
        if((x>>i) && p[k][i]==0)
        {
            p[k][i]=x;
            return 1;
        }
        else
        {
            x^=p[k][i];
        }
    }
    return 0;
}

void solve()
{
    int n;
    cin>>n;
    r=0;
    a.clear();
    for(int i=0;i<=n;i++)
    {
        mp[i]=0;
        for(int j=0;j<32;j++)p[i][j]=0;
        ra[i]=0;
        con[i]=0;
    }
    for(int i=1;i<=n;i++)
    {
        int k;
        cin>>k;
        a.insert(k);
        if(add(k,0)==1)r++;
        mp[k]++;
    }
    for(auto i:a)
    {
        if(mp[i]!=0)
        {
            for(int j=i;j<=2e5;j+=i)
            {
                if(add(i,j)==1 && (i!=j || mp[i]>1))ra[j]++;
                con[j]+=mp[i];
            }
        }
    }
    int ans=0;
    //cout<<r<<"\n";
    ans+=ksm(2,n-r);
    for(auto x:a)
    {
        //cout<<x<<" : "<<con[x]<<" "<<ra[x]<<"\n";
        int t=con[x]-ra[x];
        if(mp[x]==1)t-=1;
        ans+=ksm(2,t);
        ans%=p1;
    }
    cout<<(ans-1+p1)%p1<<"\n";
}





signed main()
{
    //freopen("E:\work tool\code document\data\input.in", "r", stdin);
	//freopen("E:\work tool\code document\data\output.out", "w", stdout);
    ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);    //关闭同步  如果使用 则不要使用<cstdio>
    // cout << fixed << setprecision(10);
    int T=1;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 24ms
memory: 58060kb

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:


result: