QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#299532#5474. Incredibly Cute Penguin ChicksrgnerdplayerCompile Error//C++144.9kb2024-01-07 00:15:452024-01-07 00:15:45

Judging History

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

  • [2024-01-07 00:15:45]
  • 评测
  • [2024-01-07 00:15:45]
  • 提交

answer

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

using i64 = long long;

template <int P>
struct Modint {
private:
    int v;

    static int minv(int a, int m) {
        a %= m;
        assert(a);
        return a == 1 ? 1 : m - 1LL * minv(m, a) * m / a;
    }

public:
    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, const 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==(const Modint &a, const Modint &b) {
        return a.v == b.v;
    }
    constexpr friend bool operator!=(const Modint &a, const Modint &b) {
        return a.v != b.v;
    }

    constexpr Modint inv() const {
        Modint res;
        res.v = minv(v, P);
        return res;
    }

    constexpr Modint operator-() const {
        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+=(const Modint &o) {
        v -= P - o.v;
        v = (v < 0) ? v + P : v;
        return *this;
    }
    constexpr Modint& operator-=(const Modint &o) {
        v -= o.v;
        v = (v < 0) ? v + P : v;
        return *this;
    }
    constexpr Modint& operator*=(const Modint &o) {
        v = 1LL * v * o.v % P;
        return *this;
    }
    constexpr Modint& operator/=(const 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+(const Modint &a, const Modint &b) {
        return Modint(a) += b;
    }
    constexpr friend Modint operator-(const Modint &a, const Modint &b) {
        return Modint(a) -= b;
    }
    constexpr friend Modint operator*(const Modint &a, const Modint &b) {
        return Modint(a) *= b;
    }
    constexpr friend Modint operator/(const Modint &a, const 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 int P = 998244353;
using Mint = Modint<P>;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    
    auto solve = [&]() {
        string s;
        cin >> s;
        int n = s.size();

        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            a[i] = string("ICP").find(s[i]);
        }

        vector pref(n + 1, vector<int>(3));
        for (int i = 0; i < n; i++) {
            pref[i + 1] = pref[i];
            pref[i + 1][a[i]]++;
        }

        vector<int> o(n + 1);

        auto get = [&](int c, int x) {
            return pref[x][c] - pref[x][(c + 1) % 3];
        };

        vector<Mint> cnt(2 * n + 1), dp(n + 1);
        dp[0] = 1;

        auto dc = [&](auto dc, int l, int r) -> void {
            if (r - l == 1) {
                return;
            }

            int m = l + r >> 1;
            dc(dc, l, m);

            iota(o.begin() + l, o.begin() + r, l);

            for (int c = 0; c < 3; c++) {
                auto cmp0 = [&](int x, int y) { return get(c, x) < get(c, y); };
                auto cmp1 = [&](int x, int y) { return get((c + 1) % 3, x) < get((c + 1) % 3, y); };
                sort(o.begin() + l, o.begin() + m, cmp0);
                sort(o.begin() + m, o.begin() + r, cmp0);

                int i = l;
                int c1 = (c + 1) % 3;

                for (int j = m; j < r; j++) {
                    while (i < m && cmp0(o[i], o[j])) {
                        int x = get(c1, o[i]) + n;
                        assert(x >= 0 && x <= 2 * n);
                        cnt[x] += dp[o[i]];
                        i++;
                    }
                    int x = get(c1, o[j]) + n;
                    assert(x >= 0 && x <= 2 * n);
                    dp[o[j]] += cnt[x];
                }

                while (i > l) {
                    i--;
                    int x = get(c1, o[i]) + n;
                    assert(x >= 0 && x <= 2 * n);
                    cnt[x] -= dp[o[i]];
                }
            }

            dc(dc, m, r);
        };
        dc(dc, 0, n + 1);

        cout << dp[n] << '\n';
    };

    solve();

    return 0;
}


詳細信息

answer.code: In lambda function:
answer.code:131:16: error: missing template arguments before ‘pref’
  131 |         vector pref(n + 1, vector<int>(3));
      |                ^~~~
answer.code:133:13: error: ‘pref’ was not declared in this scope
  133 |             pref[i + 1] = pref[i];
      |             ^~~~
answer.code: In lambda function:
answer.code:140:20: error: ‘pref’ was not declared in this scope
  140 |             return pref[x][c] - pref[x][(c + 1) % 3];
      |                    ^~~~