#include #include using namespace std; using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; using mint = modint998244353; const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n) - 1; i >= 0; --i) #define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define P pair template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } template struct Matrix { int row, column; std::vector>mat; Matrix(int r = 0, int c = 0, T val = 0) :row(r), column(c) { mat = std::vector>(row, std::vector(column, val)); } std::vector& operator[](const int i) { return mat[i]; } Matrix& operator+=(const Matrix & other) { assert(row == other.row && column == other.column); for (int i = 0; i < row; ++i) { for (int j = 0; j < column; ++j) { mat[i][j] += other.mat[i][j]; } } return *this; } Matrix& operator-=(const Matrix & other) { assert(row == other.row && column == other.column); for (int i = 0; i < row; ++i) { for (int j = 0; j < column; ++j) { mat[i][j] -= other.mat[i][j]; } } return *this; } Matrix& operator*=(const Matrix & other) { assert(column == other.row); Matrix ret(row, other.column); for (int i = 0; i < row; ++i) { for (int k = 0; k < column; ++k) { for (int j = 0; j < other.column; ++j) { ret.mat[i][j] += mat[i][k] * other.mat[k][j]; } } } return *this = ret; } Matrix& operator*=(T k) { for (int i = 0; i < row; ++i) { for (int j = 0; j < column; ++j) { mat[i][j] *= k; } } return *this; } Matrix operator+(const Matrix other)const { return Matrix(*this) += other; } Matrix operator-(const Matrix other)const { return Matrix(*this) -= other; } Matrix operator*(const Matrix other)const { return Matrix(*this) *= other; } Matrix operator*(const T k)const { return Matrix(*this) *= k; } std::vector operator*(const std::vector other) const { assert(column == (int)other.size()); std::vector ret(row); for (int i = 0; i < row; ++i) { for (int j = 0; j < column; ++j) { ret[i] += mat[i][j] * other[j]; } } return ret; } Matrix pow(long long n) const { assert(row == column); if (n == 0) { Matrix e(row, column); for (int i = 0; i < row; ++i) e.mat[i][i] = 1; return e; } Matrix ret = pow(n >> 1); ret *= ret; if (n & 1) ret *= *this; return ret; } Matrix debug() { for (int i = 0; i < row; ++i) { for (int j = 0; j < column; ++j) std::cout << mat[i][j] << " "; std::cout << std::endl; } } mint det() { auto copyMat = mat; mint res = 1; for (int i = 0; i < row; ++i) { for (int j = i; j < row; ++j) { if (0 == copyMat[j][i])continue; if (i != j) { std::swap(copyMat[i], copyMat[j]); res *= -1; } } if (0 == copyMat[i][i])return 0; res *= copyMat[i][i]; mint inv = mint(1) / copyMat[i][i]; for (int j = 0; j < column; ++j) { copyMat[i][j] *= inv; } for (int j = i + 1; j < row; ++j) { mint c = copyMat[j][i]; for (int k = i; k < column; ++k) { copyMat[j][k] -= c * copyMat[i][k]; } } } return res; } }; Matrix op(Matrix a, Matrix b) { return b * a; } Matrix e() { auto e = Matrix(3, 3); rep(i, 3)e[i][i] = 1; return e; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); auto unit = Matrix(3, 3); unit[0] = { 1, 0, 0 }; unit[1] = { 0, 1, 0 }; unit[2] = { 0, 0, 1 }; auto zero = Matrix(3, 3); zero[0] = { 1, 1, 0 }; zero[1] = { 0, 1, 0 }; zero[2] = { 0, 0, 1 }; auto one = Matrix(3, 3); one[0] = { 1, 0, 0 }; one[1] = { 1, 1, 1 }; one[2] = { 0, 0, 1 }; int n, q; cin >> n >> q; string s; cin >> s; vector>init(n); rep(i, n) { if ('0' == s[i])init[i] = zero; else init[i] = one; } segtree, op, e>seg(init); setst; rep(i, n)st.insert(i); while (q--) { int t, l, r; cin >> t >> l >> r; l--; if (1 == t) { auto ite = st.lower_bound(l); while (ite != st.end() && *ite < r) { seg.set(*ite, unit); ite = st.erase(ite); } } else { auto get = seg.prod(l, r); mint ans = get[0][2] + get[1][2]; cout << ans.val() << endl; } } return 0; }