QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#518635#8520. Xor PartitionsrgnerdplayerWA 1ms3808kbC++203.2kb2024-08-13 23:24:212024-08-13 23:24:21

Judging History

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

  • [2024-08-13 23:24:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3808kb
  • [2024-08-13 23:24:21]
  • 提交

answer

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

using i64 = long long;

template <int P>
struct Modint {
    int v;

    constexpr Modint() : v(0) {}
    constexpr Modint(i64 v_) : v(v_ % P) {
        if (v < 0) {
            v += P;
        }
    }
    constexpr explicit operator int() const { return v; }
    constexpr friend ostream& operator<<(ostream &out, Modint n) {
        return out << int(n);
    }
    constexpr friend istream& operator>>(istream &in, Modint &n) {
        i64 v;
        in >> v;
        n = Modint(v);
        return in;
    }

    constexpr friend bool operator==(Modint a, Modint b) {
        return a.v == b.v;
    }
    constexpr friend bool operator!=(Modint a, Modint b) {
        return a.v != b.v;
    }

    constexpr Modint operator-() {
        Modint res;
        res.v = v ? P - v : 0;
        return res;
    }

    constexpr Modint& operator++() {
        v++;
        if (v == P) v = 0;
        return *this;
    }
    constexpr Modint& operator--() {
        if (v == 0) v = P;
        v--;
        return *this;
    }
    constexpr Modint& operator+=(Modint o) {
        v -= P - o.v;
        v = (v < 0) ? v + P : v;
        return *this;
    }
    constexpr Modint& operator-=(Modint o) {
        v -= o.v;
        v = (v < 0) ? v + P : v;
        return *this;
    }
    constexpr Modint& operator*=(Modint o) {
        v = 1LL * v * o.v % P;
        return *this;
    }
    constexpr Modint& operator/=(Modint o) { return *this *= o.inv(); }

    constexpr friend Modint operator++(Modint &a, int) {
        Modint r = a;
        ++a;
        return r;
    }
    constexpr friend Modint operator--(Modint &a, int) {
        Modint r = a;
        --a;
        return r;
    }

    constexpr friend Modint operator+(Modint a, Modint b) {
        return Modint(a) += b;
    }
    constexpr friend Modint operator-(Modint a, Modint b) {
        return Modint(a) -= b;
    }
    constexpr friend Modint operator*(Modint a, Modint b) {
        return Modint(a) *= b;
    }
    constexpr friend Modint operator/(Modint a, Modint b) {
        return Modint(a) /= b;
    }

    constexpr Modint qpow(i64 p) {
        Modint res = 1, x = v;
        while (p > 0) {
            if (p & 1) { res *= x; }
            x *= x;
            p >>= 1;
        }
        return res;
    }
    constexpr Modint inv() {
        return qpow(P - 2);
    }
};

constexpr int P = 998244353;
using Mint = Modint<P>;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    auto solve = [&]() {
        int n;
        cin >> n;

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

        constexpr int L = 60;
        vector f(L, vector<Mint>(2));
        i64 pref = 0;
        vector<Mint> dp(n + 1);
        dp[0] = 1;

        for (int i = 0; i < n; i++) {
            for (int b = 0; b < L; b++) {
                f[b][pref >> b & 1] += dp[i];
            }
            pref ^= a[i];
            for (int b = 0; b < L; b++) {
                dp[i + 1] += f[b][pref >> b & 1 ^ 1] * (1LL << b) ;
            }
        }

        cout << dp[n] << '\n';
    };
    
    solve();
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
7 3 1 2

output:

170

result:

ok 1 number(s): "170"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

1
0

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

3
1 2 3

output:

16

result:

ok 1 number(s): "16"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

4
0 1 0 1

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 3568kb

input:

562
918479109239293921 960173570446350728 374394588863436385 418106819278123099 473761712658352147 662782574081105364 824954323015093862 827581845536521847 184394794881199801 820907621998888642 606529830885621237 961790689782125501 582742201855597942 337901250755571075 287706594894797714 18578215893...

output:

589281374

result:

wrong answer 1st numbers differ - expected: '641941658', found: '589281374'