#if __INCLUDE_LEVEL__ == 0 #include __BASE_FILE__ namespace { using Fp = atcoder::modint998244353; struct S { std::array n; std::array l; std::array r; Fp dl; Fp dr; Fp ans; }; S op(const S& x, const S& y) { S ret; for (const int i : rep(2)) { ret.n[i] = x.n[i] + y.n[i]; ret.l[i] = x.l[i] + y.l[i] + (x.n[0] + x.n[1]) * y.n[i]; ret.r[i] = x.r[i] + y.r[i] + x.n[i] * (y.n[0] + y.n[1]); } ret.dl = x.dl + y.dl; ret.dl += (y.n[0] + y.n[1]) * x.n[0] * x.n[1]; ret.dl += x.n[0] * y.r[1] + x.n[1] * y.r[0]; ret.dr = x.dr + y.dr; ret.dr += (x.n[0] + x.n[1]) * y.n[0] * y.n[1]; ret.dr += y.n[0] * x.l[1] + y.n[1] * x.l[0]; ret.ans = x.ans + y.ans; ret.ans += (y.n[0] + y.n[1]) * x.dr; ret.ans += (x.n[0] + x.n[1]) * y.dl; ret.ans += x.l[0] * y.r[1]; ret.ans += x.l[1] * y.r[0]; return ret; } S e() { return {}; } S make(int x) { assert(x == 0 || x == 1); S ret{}; ret.n[x] = 1; ret.l[x] = 1; ret.r[x] = 1; return ret; } void solve() { int n, q; scan(n, q); std::string s; scan(s); atcoder::segtree seg(n); for (const int i : rep(n)) { seg.set(i, make(s[i] - '0')); } while (q--) { int t; scan(t); if (t == 1) { int i; scan(i); --i; s[i] ^= 1; seg.set(i, make(s[i] - '0')); } else { int l, r; scan(l, r); --l; print(seg.prod(l, r).ans); } } } } // namespace int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); solve(); } #else // __INCLUDE_LEVEL__ #include #include #include template bool chmin(T& x, U&& y) { return y < x && (x = std::forward(y), true); } template bool chmax(T& x, U&& y) { return x < y && (x = std::forward(y), true); } template T inf() { T ret; std::memset(&ret, 0x3f, sizeof(ret)); return ret; } template T inf() { return std::numeric_limits::infinity(); } template concept Range = std::ranges::range && !std::convertible_to; template concept TupleLike = std::__is_tuple_like::value && !Range; namespace std { istream& operator>>(istream& is, Range auto&& r) { for (auto&& e : r) { is >> e; } return is; } istream& operator>>(istream& is, TupleLike auto&& t) { return apply([&](auto&... xs) -> istream& { return (is >> ... >> xs); }, t); } ostream& operator<<(ostream& os, Range auto&& r) { string_view sep = ""; for (auto&& e : r) { os << exchange(sep, " ") << e; } return os; } ostream& operator<<(ostream& os, TupleLike auto&& t) { const auto f = [&](auto&... xs) -> ostream& { [[maybe_unused]] string_view sep = ""; ((os << exchange(sep, " ") << xs), ...); return os; }; return apply(f, t); } #define DEF_INC_OR_DEC(op) \ auto& operator op(Range auto&& r) { \ for (auto&& e : r) { \ op e; \ } \ return r; \ } \ auto& operator op(TupleLike auto&& t) { \ apply([](auto&... xs) { (op xs, ...); }, t); \ return t; \ } DEF_INC_OR_DEC(++) DEF_INC_OR_DEC(--) #undef DEF_INC_OR_DEC } // namespace std namespace atcoder { template * = nullptr> std::istream& operator>>(std::istream& is, T& x) { int v; is >> v; x = T::raw(v); return is; } template * = nullptr> std::ostream& operator<<(std::ostream& os, const T& x) { return os << x.val(); } } // namespace atcoder void scan(auto&&... xs) { std::cin >> std::tie(xs...); } void print(auto&&... xs) { std::cout << std::tie(xs...) << '\n'; } #define FWD(...) static_cast(__VA_ARGS__) template class fix { public: explicit fix(F f) : f_(std::move(f)) {} decltype(auto) operator()(auto&&... xs) const { return f_(std::ref(*this), FWD(xs)...); } private: F f_; }; template concept LambdaExpr = std::is_placeholder_v> != 0 || std::is_bind_expression_v>; auto operator++(LambdaExpr auto&& x, int) { return std::bind([](auto&& x) -> decltype(auto) { return FWD(x)++; }, FWD(x)); } auto operator--(LambdaExpr auto&& x, int) { return std::bind([](auto&& x) -> decltype(auto) { return FWD(x)--; }, FWD(x)); } #define DEF_UNARY_OP(op) \ auto operator op(LambdaExpr auto&& x) { \ return std::bind([](auto&& x) -> decltype(auto) { return op FWD(x); }, FWD(x)); \ } DEF_UNARY_OP(++) DEF_UNARY_OP(--) DEF_UNARY_OP(+) DEF_UNARY_OP(-) DEF_UNARY_OP(~) DEF_UNARY_OP(!) DEF_UNARY_OP(*) DEF_UNARY_OP(&) #undef DEF_UNARY_OP #define DEF_BINARY_OP(op) \ template \ requires LambdaExpr || LambdaExpr \ auto operator op(T1&& x, T2&& y) { \ return std::bind([](auto&& x, auto&& y) -> decltype(auto) { return FWD(x) op FWD(y); }, \ FWD(x), FWD(y)); \ } DEF_BINARY_OP(+=) DEF_BINARY_OP(-=) DEF_BINARY_OP(*=) DEF_BINARY_OP(/=) DEF_BINARY_OP(%=) DEF_BINARY_OP(^=) DEF_BINARY_OP(&=) DEF_BINARY_OP(|=) DEF_BINARY_OP(<<=) DEF_BINARY_OP(>>=) DEF_BINARY_OP(+) DEF_BINARY_OP(-) DEF_BINARY_OP(*) DEF_BINARY_OP(/) DEF_BINARY_OP(%) DEF_BINARY_OP(^) DEF_BINARY_OP(&) DEF_BINARY_OP(|) DEF_BINARY_OP(<<) DEF_BINARY_OP(>>) DEF_BINARY_OP(==) DEF_BINARY_OP(!=) DEF_BINARY_OP(<) DEF_BINARY_OP(>) DEF_BINARY_OP(<=) DEF_BINARY_OP(>=) DEF_BINARY_OP(&&) DEF_BINARY_OP(||) #undef DEF_BINARY_OP template requires LambdaExpr || LambdaExpr auto at(T1&& x, T2&& y) { return std::bind([](auto&& x, auto&& y) -> decltype(auto) { return FWD(x)[FWD(y)]; }, FWD(x), FWD(y)); } template auto get(LambdaExpr auto&& x) { return std::bind([](auto&& x) -> decltype(auto) { return std::get(FWD(x)); }, FWD(x)); } inline auto rep(int l, int r) { return std::views::iota(std::min(l, r), r); } inline auto rep(int n) { return rep(0, n); } inline auto rep1(int l, int r) { return rep(l, r + 1); } inline auto rep1(int n) { return rep(1, n + 1); } using namespace std::literals; using namespace std::placeholders; namespace ranges = std::ranges; namespace views = std::views; using i64 = std::int64_t; #endif // __INCLUDE_LEVEL__