QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#252983#7679. Master of Both IVzhuibaoWA 36ms5592kbC++202.7kb2023-11-16 16:13:522023-11-16 16:13:52

Judging History

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

  • [2023-11-16 16:13:52]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:5592kb
  • [2023-11-16 16:13:52]
  • 提交

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)*(j-i))%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: 5592kb

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: 36ms
memory: 5452kb

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:

8
12
8
9
8
8
8
8
8
9
12
8
8
8
8
9
12
9
11
14
8
8
15
12
8
11
8
8
8
12
15
9
9
8
8
8
11
9
11
12
15
8
15
8
8
8
8
12
11
8
8
11
8
8
11
15
9
8
9
8
8
14
11
8
15
9
15
8
8
8
12
9
8
11
8
13
9
8
14
8
8
8
8
8
8
15
8
11
12
8
9
11
8
18
11
13
18
15
12
14
8
8
8
9
8
8
12
15
15
8
9
15
9
11
8
8
11
8
9
11
8
9
8
12
15
11...

result:

wrong answer 1st numbers differ - expected: '9', found: '8'