QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#253049#7679. Master of Both IVzhuibaoWA 54ms7848kbC++203.1kb2023-11-16 17:04:142023-11-16 17:04:16

Judging History

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

  • [2023-11-16 17:04:16]
  • 评测
  • 测评结果:WA
  • 用时:54ms
  • 内存:7848kb
  • [2023-11-16 17:04:14]
  • 提交

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],fac[N],f[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])
            {
                if(vis[a[i]/d])
                {
                    sum+=vis[a[i]/d];
                    X.add(a[i]/d);
                }
            }
        }
        int cnt=X.rebuild();
        //cout<<fac[sum-cnt]<<' ';
        ans=(ans+fac[sum-cnt])%P;
        X.add(a[i]);cnt=X.rebuild();
        int len=j-i;
        for(int k=i+1;k<j;k++)
        {
            sum++;
            //cout<<fac[sum-cnt]<<' ';
            ans=(ans+fac[sum-cnt])%P;
        }
        i=j;
    }
    X.init();
    for(int i=1;i<=n;i++)
    {
        X.add(a[i]);
    }
    int cnt=X.rebuild();
    ans=(ans+fac[n-cnt]-1)%P;
    cout<<ans<<'\n';
}

signed main()
{
    for(int i=0,j=1;i<=2e5;i++,j=j*2%P)
    {
        fac[i]=j;
    }
    ac;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7480kb

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: 0
Accepted
time: 54ms
memory: 7508kb

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
17
13
8
11
8
8
8
13
15
9
9
8
8
8
11
9
11
13
15
9
17
9
8
8
8
13
11
8
9
11
8
8
11
15
9
8
9
8
8
15
11
8
17
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
17
13
15
8
8
8
9
8
9
13
15
17
9
9
17
9
11
9
9
11
9
9
11
8
9
9
13
15
11...

result:

ok 40000 numbers

Test #3:

score: -100
Wrong Answer
time: 54ms
memory: 7848kb

input:

20000
10
1 3 6 8 3 1 10 7 2 3
10
8 2 8 9 10 5 8 4 8 3
10
2 2 10 1 6 4 4 3 4 7
10
6 5 10 7 8 7 3 1 6 6
10
3 2 3 7 8 4 9 8 8 7
10
9 9 6 4 9 3 9 10 5 9
10
10 8 9 10 10 4 5 1 4 3
10
2 10 4 5 8 10 2 2 7 2
10
2 6 4 10 1 1 1 1 2 3
10
1 10 2 8 1 5 9 4 3 1
10
8 1 8 1 9 5 6 7 2 9
10
1 6 7 4 8 8 7 3 5 7
10
10 ...

output:

97
77
82
74
75
84
74
105
159
95
81
74
78
75
73
73
80
93
90
84
79
77
73
83
77
74
81
79
77
207
83
77
83
78
87
83
84
97
75
80
117
75
85
74
75
95
77
83
86
77
95
73
77
83
91
96
77
80
77
75
84
81
73
95
81
74
73
81
77
79
75
78
78
81
97
77
85
73
92
83
73
74
73
81
74
73
142
83
99
77
91
77
76
81
77
73
78
76
9...

result:

wrong answer 7th numbers differ - expected: '75', found: '74'