QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#467507#7679. Master of Both IVroger_yrjWA 20ms10252kbC++141.1kb2024-07-08 16:30:512024-07-08 16:30:51

Judging History

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

  • [2024-07-08 16:30:51]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:10252kb
  • [2024-07-08 16:30:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10,mod=998244353;
int a[N],n,ans=1,b[30],vis[N],cnt[N];
vector<int>g[N];
int qpow(int x){
	int y=2,ret=1;
	while(x){
		if(x&1)ret=1ll*ret*y%mod;
		y=1ll*y*y%mod;
		x>>=1;
	}
	return ret;
}
void solve(){
	ans=1;
	cin>>n;
	memset(b,0,sizeof(b));
	for(int i=1;i<=n;i++)cnt[i]=0,g[i].clear();
	for(int i=1;i<=n;i++){
		cin>>a[i];cnt[a[i]]++;
		int x=a[i];
		for(int j=20;j>=0;j--){
			if(x&(1<<j)){
				if(b[j])x^=b[j];
				else{
					b[j]=x;
					break;
				}
			}
		}
		if(!x)ans=1ll*ans*2%mod;
	}ans--;
	for(int i=1;i<=n;i++)
		if(cnt[i])
			for(int j=i;j<=n;j+=i)
				if(cnt[j])g[j].push_back(a[i]);
	for(int i=1;i<=n;i++){
		if(cnt[i]){
			int Cnt=0;
			memset(b,0,sizeof(b));
			for(int j:g[i]){
				Cnt+=cnt[j];
					for(int k=20;k>=0;k--){
						if(j&(1<<k)){
						if(b[k])j^=b[k];
						else{
							b[k]=j;
							break;
						}
					}
				}
				if(j)Cnt--;
			}
			ans=(1ll*ans+qpow(Cnt))%mod;
		}
	}
	cout<<ans<<"\n";
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int T;cin>>T;
	while(T--)solve(); 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 8984kb

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:

12
16
40
11
8
8
9
8
9
11
13
17
11
8
11
14
12
15
17
43
17
17
43
75
11
9
17
9
8
13
15
17
11
8
8
8
17
8
17
19
12
15
19
9
8
8
9
13
17
17
12
11
9
14
9
12
11
17
15
8
10
71
17
17
17
9
21
9
11
9
12
10
9
8
15
29
17
8
40
10
8
40
9
9
8
15
9
8
13
8
11
17
8
19
17
14
43
19
15
9
9
17
8
11
8
9
15
15
19
43
10
17
17
...

result:

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