QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#250792#7679. Master of Both IVDateTreeTL 51ms24880kbC++171.7kb2023-11-13 17:47:282023-11-13 17:47:28

Judging History

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

  • [2023-11-13 17:47:28]
  • 评测
  • 测评结果:TL
  • 用时:51ms
  • 内存:24880kb
  • [2023-11-13 17:47:28]
  • 提交

answer

#include <bits/stdc++.h>

const int N = 2e5 + 5, mod = 998244353;

std::vector<int> fac[N];

struct linearBasis {
    int a[19], tot;
    void clear() {
        tot = 0;
        memset(a, 0, sizeof(a));
    }
    void insert(int x) {
        for (int i = 19; i >= 0; --i) {
            if ((x >> i) & 1) {
                if (a[i]) {
                    x ^= a[i];
                } else {
                    if (x) {
                        a[i] = x;
                        ++tot;
                    }
                    break;
                }
            }
        }
    }
} B;

void prep() {
    for (int i = 1; i < N; ++i)
        for (int j = i; j < N; j += i)
            fac[j].emplace_back(i);
}

int qpow(int base, int b, int ret = 1) {
    for (; b; b >>= 1, base = 1ll * base * base % mod)
        if (b & 1)
            ret = 1ll * ret * base % mod;
    return ret;
}

int main() {
    //freopen("in", "r", stdin);
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    prep();
    int ttt;
    std::cin >> ttt;
    while (ttt--) {
        int n;
        std::cin >> n;
        std::vector<int> a(n + 1);
        std::map<int,int> mp;
        B.clear();
        for (int i = 1; i <= n; ++i) {
            std::cin >> a[i];
            B.insert(a[i]);
            ++mp[a[i]];
        }
        int ans = (mod - 1 + qpow(2, n - B.tot)) % mod;
        for (auto &[x, y]: mp) {
            int tot = 0;
            B.clear();
            for (auto &d: fac[x]) {
                B.insert(d);
                tot += mp[d];
            }
            (ans += qpow(2, tot - B.tot)) %= mod;
        }
        std::cout << ans << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 51ms
memory: 24880kb

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
Time Limit Exceeded

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:


result: