QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#487252#7679. Master of Both IVyaoyWA 29ms5436kbC++205.8kb2024-07-22 19:19:592024-07-22 19:20:00

Judging History

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

  • [2024-07-22 19:20:00]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:5436kb
  • [2024-07-22 19:19:59]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

template<class T>
constexpr T power(T a, i64 b) {
    T res {1};
    for (; b; b /= 2, a *= a) {
        if (b % 2) {
            res *= a;
        }
    }
    return res;
}
  
constexpr i64 mul(i64 a, i64 b, i64 p) {
    i64 res = a * b - i64(1.L * a * b / p) * p;
    res %= p;
    if (res < 0) {
        res += p;
    }
    return res;
}
  
template<i64 P>
struct MInt {
    i64 x;
    constexpr MInt() : x {0} {}
    constexpr MInt(i64 x) : x {norm(x % getMod())} {}
     
    static i64 Mod;
    constexpr static i64 getMod() {
        if (P > 0) {
            return P;
        } else {
            return Mod;
        }
    }
    static void setMod(i64 Mod_) {
        Mod = Mod_;
    }
    constexpr i64 norm(i64 x) const {
        if (x < 0) {
            x += getMod();
        }
        if (x >= getMod()) {
            x -= getMod();
        }
        return x;
    }
    constexpr i64 val() const {
        return x;
    }
    constexpr MInt operator-() const {
        MInt res;
        res.x = norm(getMod() - x);
        return res;
    }
    constexpr MInt inv() const {
        return power(*this, getMod() - 2);
    }
    constexpr MInt &operator*=(MInt rhs) & {
        if (getMod() < (1ULL << 31)) {
            x = x * rhs.x % int(getMod());
        } else {
            x = mul(x, rhs.x, getMod());
        }
        return *this;
    }
    constexpr MInt &operator+=(MInt rhs) & {
        x = norm(x + rhs.x);
        return *this;
    }
    constexpr MInt &operator-=(MInt rhs) & {
        x = norm(x - rhs.x);
        return *this;
    }
    constexpr MInt &operator/=(MInt rhs) & {
        return *this *= rhs.inv();
    }
    friend constexpr MInt operator*(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res *= rhs;
        return res;
    }
    friend constexpr MInt operator+(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res += rhs;
        return res;
    }
    friend constexpr MInt operator-(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res -= rhs;
        return res;
    }
    friend constexpr MInt operator/(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res /= rhs;
        return res;
    }
    friend constexpr std::istream &operator>>(std::istream &is, MInt &a) {
        i64 v;
        is >> v;
        a = MInt(v);
        return is;
    }
    friend constexpr std::ostream &operator<<(std::ostream &os, const MInt &a) {
        return os << a.val();
    }
    friend constexpr bool operator==(MInt lhs, MInt rhs) {
        return lhs.val() == rhs.val();
    }
    friend constexpr bool operator!=(MInt lhs, MInt rhs) {
        return lhs.val() != rhs.val();
    }
    friend constexpr bool operator<(MInt lhs, MInt rhs) {
        return lhs.val() < rhs.val();
    }
};
  
template<>
i64 MInt<0>::Mod = 998244353;
  
constexpr int P = 998244353;
using Mint = MInt<P>;

const int B = 16 + 1;
struct LinearBasis {
    int ex, m;
    std::vector<i64> bit, b;
    LinearBasis() {
        std::vector<i64> t;
        init(t);
    }
    template<class T>
    LinearBasis(std::vector<T> &a) {
        init(a);
    }
    template<class T>
    void init(std::vector<T> &a) {
        this->ex = 0;
        bit.assign(B, 0);
        for (auto &x : a) {
            if (!insert(x)) {
                this->ex++;
            }
        }
        // build();
    }
    void build() {
        b.clear();
        for (int i = 0; i < B; i++) {
            if (!bit[i]) {
                continue;
            }
            b.emplace_back(bit[i]);
        }
        this->m = b.size();
    }

    bool insert(i64 x) {
        for (int i = B - 1; i >= 0; i--) {
            if (x >> i & 1) {
                if (!bit[i]) {
                    bit[i] = x;
                    // build();
                    return true;
                } else {
                    x ^= bit[i];
                }
            }
        }
        return false;
    }
    i64 queryMin(i64 x) {
        for (int i = B - 1; i >= 0; i--) {
            x = std::min(x, bit[i] ^ x);
        }
        return x;
    }
    i64 queryMax(i64 x) {
        for (int i = B - 1; i >= 0; i--) {
            x = std::max(x, bit[i] ^ x);
        }
        return x;
    }
    i64 kth(i64 k) { // the kth smallest element in set
        // multiset: k >> this->ex
        if (this->ex > 0) {
            k--;
        }
        if (k > (1LL << m) - 1) {
            return -1;
        }
        i64 x = 0;
        for (int i = m - 1; i >= 0; i--) {
            if (k >> i & 1) {
                x = std::max(x, x ^ b[i]);
            } else {
                x = std::min(x, x ^ b[i]);
            }
        }
        return x;
    }
};

const int N = 2E5 + 1;
Mint pw[N];

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    LinearBasis L0(a);
    std::vector<int> cnt(n + 1);
    for (int i = 0; i < n; i++) {
        cnt[a[i]]++;
    }
    Mint ans = pw[L0.ex] - 1;

    std::sort(a.begin(), a.end());
    a.erase(std::unique(a.begin(), a.end()), a.end());
    const int m = a.size();
    const int mx = a.back();

    std::vector<LinearBasis> L(mx + 1);
    for (auto &x : a) {
        for (int j = x; j <= mx; j += x) {
            L[j].insert(x);
            L[j].ex += (cnt[x] - 1);
        }
    }

    for (auto &x : a) {
        ans += pw[L[x].ex];
    }
    std::cout << ans << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    pw[0] = 1;
    for (int i = 1; i < N; i++) {
        pw[i] = pw[i - 1] * 2;
    }

    int t;
    std::cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}
 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 28ms
memory: 5436kb

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: 29ms
memory: 5132kb

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:

89
77
80
74
75
84
75
105
143
95
81
74
78
73
73
73
83
93
90
84
79
77
73
89
77
73
81
79
80
175
83
77
83
76
83
85
84
97
74
80
101
74
113
74
75
95
75
83
86
77
99
73
77
83
91
96
77
80
77
76
80
81
73
95
83
74
75
81
77
79
74
76
78
81
97
77
85
73
92
83
73
80
73
77
74
73
142
83
99
78
91
77
76
81
77
74
78
76
...

result:

wrong answer 1st numbers differ - expected: '97', found: '89'