#include #ifdef LOCAL #include #else #define debug(...) void(0) #endif template std::istream& operator>>(std::istream& is, std::vector& v) { for (auto& e : v) { is >> e; } return is; } template std::ostream& operator<<(std::ostream& os, const std::vector& v) { for (std::string_view sep = ""; const auto& e : v) { os << std::exchange(sep, " ") << e; } return os; } template bool chmin(T& x, U&& y) { return y < x and (x = std::forward(y), true); } template bool chmax(T& x, U&& y) { return x < y and (x = std::forward(y), true); } template void mkuni(std::vector& v) { std::ranges::sort(v); auto result = std::ranges::unique(v); v.erase(result.begin(), result.end()); } template int lwb(const std::vector& v, const T& x) { return std::distance(v.begin(), std::ranges::lower_bound(v, x)); } #include #include template struct SquareMatrix { std::array, N> A; SquareMatrix() : A{{}} {} size_t size() const { return N; } inline const std::array& operator[](int k) const { return A[k]; } inline std::array& operator[](int k) { return A[k]; } static SquareMatrix I() { SquareMatrix res; for (size_t i = 0; i < N; i++) res[i][i] = 1; return res; } SquareMatrix& operator+=(const SquareMatrix& B) { for (size_t i = 0; i < N; i++) { for (size_t j = 0; j < N; j++) { (*this)[i][j] += B[i][j]; } } return *this; } SquareMatrix& operator-=(const SquareMatrix& B) { for (size_t i = 0; i < N; i++) { for (size_t j = 0; j < N; j++) { (*this)[i][j] -= B[i][j]; } } return *this; } SquareMatrix& operator*=(const SquareMatrix& B) { std::array, N> C = {}; for (size_t i = 0; i < N; i++) { for (size_t k = 0; k < N; k++) { for (size_t j = 0; j < N; j++) { C[i][j] += (*this)[i][k] * B[k][j]; } } } A.swap(C); return *this; } SquareMatrix& operator*=(const T& v) { for (size_t i = 0; i < N; i++) { for (size_t j = 0; j < N; j++) { (*this)[i][j] *= v; } } return *this; } SquareMatrix& operator/=(const T& v) { T inv = T(1) / v; for (size_t i = 0; i < N; i++) { for (size_t j = 0; j < N; j++) { (*this)[i][j] *= inv; } } return *this; } SquareMatrix& operator^=(long long k) { assert(0 <= k); SquareMatrix B = SquareMatrix::I(); while (k > 0) { if (k & 1) B *= *this; *this *= *this; k >>= 1; } A.swap(B.A); return *this; } SquareMatrix operator-() const { SquareMatrix res; for (size_t i = 0; i < N; i++) { for (size_t j = 0; j < N; j++) { res[i][j] = -(*this)[i][j]; } } return res; } SquareMatrix operator+(const SquareMatrix& B) const { return SquareMatrix(*this) += B; } SquareMatrix operator-(const SquareMatrix& B) const { return SquareMatrix(*this) -= B; } SquareMatrix operator*(const SquareMatrix& B) const { return SquareMatrix(*this) *= B; } SquareMatrix operator*(const T& v) const { return SquareMatrix(*this) *= v; } SquareMatrix operator/(const T& v) const { return SquareMatrix(*this) /= v; } SquareMatrix operator^(const long long k) const { return SquareMatrix(*this) ^= k; } bool operator==(const SquareMatrix& B) const { return A == B.A; } bool operator!=(const SquareMatrix& B) const { return A != B.A; } SquareMatrix transpose() const { SquareMatrix res; for (size_t i = 0; i < N; i++) { for (size_t j = 0; j < N; j++) { res[j][i] = (*this)[i][j]; } } return res; } T determinant() const { SquareMatrix B(*this); T res = 1; for (size_t i = 0; i < N; i++) { int pivot = -1; for (size_t j = i; j < N; j++) { if (B[j][i] != 0) { pivot = j; break; } } if (pivot == -1) return 0; if (pivot != (int)i) { res *= -1; std::swap(B[i], B[pivot]); } res *= B[i][i]; T inv = T(1) / B[i][i]; for (size_t j = 0; j < N; j++) B[i][j] *= inv; for (size_t j = i + 1; j < N; j++) { T a = B[j][i]; for (size_t k = 0; k < N; k++) { B[j][k] -= B[i][k] * a; } } } } SquareMatrix inv() const { SquareMatrix B(*this), C = SquareMatrix::I(); for (size_t i = 0; i < N; i++) { int pivot = -1; for (size_t j = i; j < N; j++) { if (B[j][i] != 0) { pivot = j; break; } } if (pivot == -1) return {}; if (pivot != (int)i) { std::swap(B[i], B[pivot]); std::swap(C[i], C[pivot]); } T inv = T(1) / B[i][i]; for (size_t j = 0; j < N; j++) { B[i][j] *= inv; C[i][j] *= inv; } for (size_t j = 0; j < N; j++) { if (j == i) continue; T a = B[j][i]; for (size_t k = 0; k < N; k++) { B[j][k] -= B[i][k] * a; C[j][k] -= C[i][k] * a; } } } return C; } friend std::ostream& operator<<(std::ostream& os, const SquareMatrix& p) { os << "[(" << N << " * " << N << " Matrix)"; os << "\n[columun sums: "; for (size_t j = 0; j < N; j++) { T sum = 0; for (size_t i = 0; i < N; i++) sum += p[i][j]; ; os << sum << (j + 1 < N ? "," : ""); } os << "]"; for (size_t i = 0; i < N; i++) { os << "\n["; for (size_t j = 0; j < N; j++) os << p[i][j] << (j + 1 < N ? "," : ""); os << "]"; } os << "]\n"; return os; } }; using ll = long long; using namespace std; using mint = atcoder::modint998244353; constexpr int SIZE = 2; using SM = SquareMatrix; // 末尾が i の整数の個数 SM op(SM l, SM r) { return r * l; } SM e() { return SM::I(); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int N, Q; cin >> N >> Q; string S; cin >> S; vector init; for (int i = 0; i < N; i++) { int x = S[i] - '0'; auto m = SM::I(); for (int j = 0; j < SIZE + (x != 0); j++) m[x][j] = 1; init.emplace_back(m); } atcoder::segtree seg(init); set alive; for (int i = 0; i < N; i++) alive.emplace(i); for (; Q--;) { int t, l, r; cin >> t >> l >> r; l--; if (t == 1) { for (auto itr = alive.lower_bound(l); itr != alive.end() and *itr < r; itr = alive.erase(itr)) { seg.set(*itr, SM::I()); } } else { auto res = seg.prod(l, r); mint ans = 0; for (int j = 0; j < SIZE; j++) ans += res[j][SIZE]; cout << ans.val() << '\n'; } } return 0; }