QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#561416 | #7679. Master of Both IV | Albert711 | WA | 16ms | 3628kb | C++20 | 2.0kb | 2024-09-12 22:21:29 | 2024-09-12 22:21:29 |
Judging History
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;
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(a[i]==1) {
ans=(ans+c1*fp(2,c2)%mod)%mod;
continue;
}
for(int j=1;j*j<=a[i];j++){
if(!(a[i]%j)&&idx[j]!=0){
if(insert(j)){
c2+=idx[j]-1;
}else{
c2+=idx[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: 3532kb
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: 16ms
memory: 3628kb
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: 14ms
memory: 3612kb
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:
83 77 80 74 75 84 74 105 143 95 81 74 78 73 73 73 80 93 90 77 77 77 73 83 74 73 81 79 77 151 83 77 83 74 81 83 77 97 74 80 101 74 85 74 73 95 73 83 80 74 95 73 74 83 91 96 74 80 77 75 76 81 73 95 81 74 73 81 74 79 74 75 75 81 97 77 85 73 92 83 73 74 73 74 74 73 141 83 95 77 91 77 75 81 74 73 78 76 9...
result:
wrong answer 1st numbers differ - expected: '97', found: '83'