QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#164324 | #5474. Incredibly Cute Penguin Chicks | rgnerdplayer | Compile Error | / | / | C++20 | 5.0kb | 2023-09-04 21:34:20 | 2023-09-04 21:34:21 |
Judging History
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;
}
详细
answer.code: In lambda function: answer.code:142:30: error: expected identifier before ‘=’ token 142 | get[i] = [&pref, =i](int x) { return pref[x][i] - pref[x][(i + 1) % 3]; }; | ^ answer.code: In lambda function: answer.code:142:58: error: ‘i’ is not captured 142 | get[i] = [&pref, =i](int x) { return pref[x][i] - pref[x][(i + 1) % 3]; }; | ^ answer.code:142:32: note: the lambda has no capture-default 142 | get[i] = [&pref, =i](int x) { return pref[x][i] - pref[x][(i + 1) % 3]; }; | ^ answer.code:141:18: note: ‘int i’ declared here 141 | for (int i = 0; i < 3; i++) { | ^ answer.code:142:72: error: ‘i’ is not captured 142 | get[i] = [&pref, =i](int x) { return pref[x][i] - pref[x][(i + 1) % 3]; }; | ^ answer.code:142:32: note: the lambda has no capture-default 142 | get[i] = [&pref, =i](int x) { return pref[x][i] - pref[x][(i + 1) % 3]; }; | ^ answer.code:141:18: note: ‘int i’ declared here 141 | for (int i = 0; i < 3; i++) { | ^ answer.code: In lambda function: answer.code:142:85: error: no match for ‘operator=’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<std::function<int(int)> >, std::function<int(int)> >::value_type’ {aka ‘std::function<int(int)>’} and ‘main()::<lambda()>::<lambda(int)>’) 142 | get[i] = [&pref, =i](int x) { return pref[x][i] - pref[x][(i + 1) % 3]; }; | ^ 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:501:9: note: candidate: ‘template<class _Functor> std::function<_Res(_ArgTypes ...)>::_Requires<std::function<_Res(_ArgTypes ...)>::_Callable<typename std::decay<_Functor>::type>, std::function<_Res(_ArgTypes ...)>&> std::function<_Res(_ArgTypes ...)>::operator=(_Functor&&) [with _Functor = _Functor; _Res = int; _ArgTypes = {int}]’ 501 | operator=(_Functor&& __f) | ^~~~~~~~ /usr/include/c++/11/bits/std_function.h:501:9: note: template argument deduction/substitution failed: /usr/include/c++/11/bits/std_function.h: In substitution of ‘template<class _Res, class ... _ArgTypes> template<class _Cond, class _Tp> using _Requires = typename std::enable_if<_Cond::value, _Tp>::type [with _Cond = std::function<int(int)>::_Callable<main()::<lambda()>::<lambda(int)>, std::__invoke_result<main()::<lambda()>::<lambda(int)>&, int> >; _Tp = std::function<int(int)>&; _Res = int; _ArgTypes = {int}]’: /usr/include/c++/11/bits/std_function.h:501:2: required by substitution of ‘template<class _Functor> std::function<int(int)>::_Requires<std::function<int(int)>::_Callable<typename std::decay<_Tp>::type, std::__invoke_result<typename std::decay<_Tp>::type&, int> >, std::function<int(int)>&> std::function<int(int)>::operator=<_Functor>(_Functor&&) [with _Functor = main()::<lambda()>::<lambda(int)>]’ answer.code:142:85: required from here /usr/include/c++/11/bits/std_function.h:344:15: error: no type named ‘type’ in ‘struct std::enable_if<false, std::function<int(int)>&>’ 344 | using _Requires = typename enable_if<_Cond::value, _Tp>::type; | ^~~~~~~~~ /usr/include/c++/11/bits/std_function.h:510:9: note: candidate: ‘template<class _Functor> std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes ...)>::operator=(std::reference_wrapper<_Functor>) [with _Functor = _Functor; _Res = int; _ArgTypes = {int}]’ 510 | operator=(reference_wrapper<_Functor> __f) noexcept | ^~~~~~~~ /usr/include/c++/11/bits/std_function.h:510:9: note: template argument deduction/substitution failed: answer.code:142:85: note: ‘main()::<lambda()>::<lambda(int)>’ is not derived from ‘std::reference_wrapper<_Tp>’ 142 | get[i] = [&pref, =i](int x) { return pref[x][i] - pref[x][(i + 1) % 3]; }; | ^ 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:440:7: note: candidate: ‘std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes ...)>::operator=(const std::function<_Res(_ArgTy...