QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#164328#5474. Incredibly Cute Penguin ChicksrgnerdplayerCompile Error//C++205.0kb2023-09-04 21:40:482023-09-04 21:40:48

Judging History

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

  • [2023-09-04 21:40:48]
  • 评测
  • [2023-09-04 21:40:48]
  • 提交

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);

        vector<function<int(int)>> get(3);
        vector<function<bool(int, int)>> cmp(3);
        for (int i = 0; i < 3; i++) {
            get[i] = [&pref, i](int x) { return pref[x][i] - pref[x][(i + 1) % 3]; };
        }
        for (int i = 0; i < 3; i++) {
            cmp[i] = [i](int x, int y) {
                return get[i](x) < get[i](y);
            };
        }

        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);

            for (int c = 0; c < 3; c++) {
                iota(o.begin() + l, o.begin() + r, l);
                sort(o.begin() + l, o.begin() + m, cmp[c]);
                sort(o.begin() + m, o.begin() + r, cmp[c]);

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

                for (int j = m; j < r; j++) {
                    while (i < m && cmp[c](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;
}

Details

answer.code: In lambda function:
answer.code:146:24: error: ‘get’ is not captured
  146 |                 return get[i](x) < get[i](y);
      |                        ^~~
answer.code:145:24: note: the lambda has no capture-default
  145 |             cmp[i] = [i](int x, int y) {
      |                        ^
answer.code:139:36: note: ‘std::vector<std::function<int(int)> > get’ declared here
  139 |         vector<function<int(int)>> get(3);
      |                                    ^~~
answer.code:146:36: error: ‘get’ is not captured
  146 |                 return get[i](x) < get[i](y);
      |                                    ^~~
answer.code:145:24: note: the lambda has no capture-default
  145 |             cmp[i] = [i](int x, int y) {
      |                        ^
answer.code:139:36: note: ‘std::vector<std::function<int(int)> > get’ declared here
  139 |         vector<function<int(int)>> get(3);
      |                                    ^~~
answer.code: In lambda function:
answer.code:147:13: error: no match for ‘operator=’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<std::function<bool(int, int)> >, std::function<bool(int, int)> >::value_type’ {aka ‘std::function<bool(int, int)>’} and ‘main()::<lambda()>::<lambda(int, int)>’)
  147 |             };
      |             ^
In file included from /usr/include/c++/11/functional:59,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from answer.code:1:
/usr/include/c++/11/bits/std_function.h:530:9: note: candidate: ‘template<class _Functor> std::function<_Res(_ArgTypes ...)>::_Requires<std::function<_Res(_ArgTypes ...)>::_Callable<_Functor>, std::function<_Res(_ArgTypes ...)>&> std::function<_Res(_ArgTypes ...)>::operator=(_Functor&&) [with _Functor = _Functor; _Res = bool; _ArgTypes = {int, int}]’
  530 |         operator=(_Functor&& __f)
      |         ^~~~~~~~
/usr/include/c++/11/bits/std_function.h:530:9: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/11/bits/move.h:57,
                 from /usr/include/c++/11/bits/stl_pair.h:59,
                 from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from answer.code:1:
/usr/include/c++/11/type_traits: In substitution of ‘template<bool _Cond, class _Tp> using __enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = std::function<bool(int, int)>&]’:
/usr/include/c++/11/bits/std_function.h:353:8:   required by substitution of ‘template<class _Res, class ... _ArgTypes> template<class _Cond, class _Tp> using _Requires = std::__enable_if_t<_Cond::value, _Tp> [with _Cond = std::function<bool(int, int)>::_Callable<main()::<lambda()>::<lambda(int, int)>, main()::<lambda()>::<lambda(int, int)>, std::__invoke_result<main()::<lambda()>::<lambda(int, int)>&, int, int> >; _Tp = std::function<bool(int, int)>&; _Res = bool; _ArgTypes = {int, int}]’
/usr/include/c++/11/bits/std_function.h:530:2:   required by substitution of ‘template<class _Functor> std::function<bool(int, int)>::_Requires<std::function<bool(int, int)>::_Callable<_Functor, typename std::enable_if<(! std::is_same<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type, std::function<bool(int, int)> >::value), std::decay<_Tp> >::type::type, std::__invoke_result<typename std::enable_if<(! std::is_same<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type, std::function<bool(int, int)> >::value), std::decay<_Tp> >::type::type&, int, int> >, std::function<bool(int, int)>&> std::function<bool(int, int)>::operator=<_Functor>(_Functor&&) [with _Functor = main()::<lambda()>::<lambda(int, int)>]’
answer.code:147:13:   required from here
/usr/include/c++/11/type_traits:2205:11: error: no type named ‘type’ in ‘struct std::enable_if<false, std::function<bool(int, int)>&>’
 2205 |     using __enable_if_t = typename enable_if<_Cond, _Tp>::type;
      |           ^~~~~~~~~~~~~
In file included from /usr/include/c++/11/functional:59,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from answer.code:1:
/usr/include/c++/11/bits/std_function.h:540:9: note: candidate: ‘template<class _Functor> std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes ...)>::operator=(std::reference_wrapper<_Functor>) [with _Functor = _Functor; _Res = bool; _ArgTypes = {int, int}]’
  540 |         operator=(reference_wrapper<_Functor> __f) noexcept
      |         ^~~~~~~~
/usr/include/c++/11/bits/std_function.h:54...