QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#558958 | #7679. Master of Both IV | wdw | WA | 28ms | 58292kb | C++20 | 2.8kb | 2024-09-11 19:28:38 | 2024-09-11 19:28:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define int long long
const int N = 2e5 + 10;
const double eps = 1e-10;
#define ull unsigned long long
#define endl '\n'
using i64 = int64_t;
const int mod =998244353;
int ans = 0;int ksm(int a, int b) {
int ans = 1;
while (b) {
if (b % 2 == 1) {
ans = ans * a % mod;
}
b /= 2;
a = a * a % mod;
}
return ans;
}
namespace binom {
int fac[N], ifac[N];
int __ = [] {
fac[0] = 1;
for (int i = 1; i <= N - 5; i++) {
fac[i] = fac[i - 1] * i % mod;
}
ifac[N - 5] = ksm(fac[N - 5], mod - 2);
for (int i = N - 5; i; i--) {
ifac[i - 1] = ifac[i] * i % mod;
}
return 0;
}();
inline int C(int n, int m) {
if (n < m || m < 0) return 0;
return fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
inline int A(int n, int m) {
if ((n < m || m < 0)) return 0;
return fac[n] * ifac[n - m] % mod;
}
}
using namespace binom;
struct node {
int h[32];
int cnt=0;
//线性基增加了return true
bool in(int x) {
for (int i = 31; i >= 0; i--) {
if ((1ll << i) & x) {
if (h[i] == 0) {
h[i] = x;
cnt++;
return true;
} else {
x ^= h[i];
}
}
}
return false;
}
int ma(int x,int y) {
for (int i = 31; i >= 0; i--) {
if(ans>max(x^h[i],y^h[i])){
ans=max(x^h[i],y^h[i]);
x^=h[i];
y^=h[i];
}
}
return x;
}
}t1[N];
void solve() {
int n;
cin >> n ;
int ans=0;
int p=0;
for(int i=0;i<=n;i++){
for(int j=31;j>=0;j--){
t1[i].h[j]=0;
}
t1[i].cnt=0;
}
vector<int>a(n+5),num(n+5),siz(n+5);
for(int i=1;i<=n;i++){
cin>>a[i];
num[a[i]]++;
if(!t1[0].in(a[i])){
p++;
}
}
ans+=ksm(2,p)-1;
ans%=mod;
for(int i=1;i<=n;i++){
for(int j=2;j*i<=n;j++){
siz[i*j]+=num[i];
t1[i*j].in(i);
}
}
//cout<<ans<<" ";
for(int i=1;i<=n;i++){
if(num[i]==0)continue;
int c1=ksm(2,num[i]-1),c2=ksm(2,siz[i]-t1[i].cnt);
//cout<<siz[i]<<" "<<i<<'\n';
ans+=c1*c2%mod;
ans%=mod;
//cout<<ans<<" ";
}
cout <<ans << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// cout<<fixed<<setprecision(2);
int T = 1;
cin>>T;
while (T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 9ms
memory: 58216kb
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: 28ms
memory: 58292kb
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 8 13 8 8 8 8 8 12 8 10 15 8 8 17 13 8 11 8 8 8 13 15 9 8 8 8 8 11 9 10 13 14 9 13 9 8 8 8 13 11 8 9 11 8 8 10 14 9 8 8 8 8 15 11 8 17 8 13 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 17 11 13 19 13 13 15 8 8 8 8 8 9 13 14 17 9 8 13 9 10 9 9 11 9 8 11 8 9 9 13 13 11...
result:
wrong answer 10th numbers differ - expected: '9', found: '8'