QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#561442#7679. Master of Both IVAlbert711WA 20ms3652kbC++202.4kb2024-09-12 22:37:262024-09-12 22:37:26

Judging History

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

  • [2024-09-12 22:37:26]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:3652kb
  • [2024-09-12 22:37:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long 
const int mod=998244353;
const int N=2e5+10;

int BIT=20;
int bas[25];
int idx[N];
// int cnt=0;
// int isp[N];
// int pri[100005];
// void getprime(int n){
//     for(int i=1;i<=n;i++) isp[i]=i;
//     for(int i=2;i<=n;i++){
//         if(isp[i]==i) pri[++cnt]=i;
//         for(int j=1;j<=cnt&&i*pri[j]<=n;j++){
//             pri[i*pri[j]]=pri[j];
//             if(!(i%pri[j])) break;
//         }
//     }
// }

int fp(int ba,int po){
    int r=1;
    while(po){
        if(po&1) r=r*ba%mod;
        po>>=1;
        ba=ba*ba%mod;
    }
    return r;
}



bool insert(int num) {
	for (int i = BIT; i >= 0; i--) {
		if ((num >> i) == 1) {
			if (bas[i] == 0) {
				bas[i] = num;
				return true;
			}
			num ^= bas[i];
		}
	}
	return false;
}



void abt(){
    memset(bas,0,sizeof(bas));
    int n;
    cin>>n;
    int cc=0;
    vector<int> a(n+1);
    int c1=0;
    for(int i=1;i<=n;i++){
    	cin>>a[i];
    	if(!insert(a[i])) ++cc;
        idx[a[i]]++;
        if(a[i]==1) c1++;
    }
    int ans=fp(2,cc)-1;
    // cout<<ans<<'\n';
    sort(a.begin(),a.end());
    a.erase(unique(a.begin(),a.end()),a.end());
    int siz=a.size();
    for(int i=1;i<siz;i++){
        memset(bas,0,sizeof(bas));
        int c1=fp(2,idx[a[i]]-1);
        int c2=0;
        if(i!=1&&idx[1]>0){
            if(insert(1)){
                c2+=idx[1]-1;
            }else{
                c2+=idx[1];
            }
        }
        for(int j=2;j*j<=a[i];j++){
            if(!(a[i]%j)){
                if(idx[j]!=0){
                    if(insert(j)){
                        c2+=idx[j]-1;
                    }else{
                        c2+=idx[j];
                    }
                }
                if(idx[a[i]/j]!=0){
                    if(insert(a[i]/j)){
                        c2+=idx[a[i]/j]-1;
                    }else{
                        c2+=idx[a[i]/j];
                    }
                }
            }
        }
        ans=(ans+c1*fp(2,c2)%mod)%mod;
    }
    cout<<ans<<'\n';
    for(auto i:a){
        idx[i]=0;
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int T=1;
    cin>>T;
    while(T--) abt();
    return 0;
}






Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

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: 20ms
memory: 3652kb

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:

10
16
13
15
9
8
9
8
9
15
13
8
10
9
10
15
12
15
11
15
8
8
17
13
9
11
8
9
10
13
15
15
15
9
9
9
11
15
11
13
15
9
41
9
9
9
8
13
11
10
9
11
8
10
11
15
15
10
15
9
9
19
11
9
17
15
15
8
10
10
12
15
13
11
10
25
15
8
19
10
9
10
9
9
8
15
8
11
13
9
15
13
9
19
13
25
19
17
13
15
10
8
8
15
8
9
13
15
17
10
15
17
15...

result:

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