QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#252534#7679. Master of Both IVCu_OH_2WA 25ms3608kbC++142.1kb2023-11-15 20:40:122023-11-15 20:40:12

Judging History

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

  • [2023-11-15 20:40:12]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:3608kb
  • [2023-11-15 20:40:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MOD = 998244353;

template<int bit>
struct LinearBasis
{
    vector<ll> v;
    LinearBasis() { v.resize(bit); }
    void insert(ll x)
    {
        for (int i = bit - 1; i >= 0; --i)
        {
            if (x >> i & 1ll)
            {
                if (v[i]) x ^= v[i];
                else
                {
                    v[i] = x;
                    break;
                }
            }
        }
        return;
    }
    int rank()
    {
        int cnt = 0;
        for (auto e : v)
        {
            if (e) cnt++;
        }
        return cnt;
    }
};

ll qpow(ll a, ll p)
{
    ll res = 1;
    while (p)
    {
        if (p & 1) res = res * a % MOD;
        a = a * a % MOD;
        p >>= 1;
    }
    return res;
}

int n, a[200005];

void solve()
{
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    // xorsum = max_element
    vector<ll> cnt(n + 1);
    for (int i = 1; i <= n; ++i) cnt[a[i]]++;
    vector<ll> mf(n + 1), f(n + 1);
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j * i <= n; ++j)
        {
            f[i * j] += cnt[i];
        }
    }
    for (int i = 2; i <= n; ++i)
    {
        for (int j = 2; i * j <= n; ++j)
        {
            if (!mf[i * j]) mf[i * j] = i;
        }
    }
    ll ans = 0;
    vector<LinearBasis<32>> lb(n + 1);
    for (int i = 1; i <= n; ++i)
    {
        if (!cnt[i]) continue;
        if (cnt[1]) lb[i].insert(1);
        if (!mf[i]) lb[i].insert(i);
        else lb[i] = lb[i / mf[i]], lb[i].insert(mf[i]);
        ans += qpow(2, f[i] - lb[i].rank());
        // cerr << i << ' ' << f[i] << ' ' << lb[i].rank() << endl;
        ans %= MOD;
    }
    LinearBasis<32> lbb;
    for (int i = 1; i <= n; ++i) lbb.insert(a[i]);
    ans += qpow(2, n - lbb.rank());
    ans %= MOD;
    cout << (ans + MOD - 1) % MOD << '\n';
    return;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

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: 25ms
memory: 3600kb

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:

10
16
13
11
9
9
9
9
9
11
13
8
10
9
10
11
14
11
13
15
8
8
17
13
9
11
8
9
10
17
15
11
11
9
9
9
11
11
13
14
17
9
25
9
9
9
8
13
11
10
9
11
10
10
13
17
11
10
11
9
9
19
11
9
17
11
19
9
10
10
12
11
13
11
10
17
11
8
19
10
9
10
9
9
8
15
9
11
13
9
11
13
9
23
13
17
19
25
13
15
10
8
8
11
8
9
13
17
17
10
11
25
1...

result:

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