#include #include using namespace std; using namespace atcoder; istream &operator>>(istream &is, modint &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint &a) { return os << a.val(); } istream &operator>>(istream &is, modint998244353 &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint998244353 &a) { return os << a.val(); } istream &operator>>(istream &is, modint1000000007 &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint1000000007 &a) { return os << a.val(); } typedef long long ll; typedef vector> Graph; typedef pair pii; typedef pair pll; #define FOR(i,l,r) for (int i = l;i < (int)(r); i++) #define rep(i,n) for (int i = 0;i < (int)(n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define my_sort(x) sort(x.begin(), x.end()) #define my_max(x) *max_element(all(x)) #define my_min(x) *min_element(all(x)) template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = (1<<30) - 1; const ll LINF = (1LL<<62) - 1; const int MOD = 998244353; const int MOD2 = 1e9+7; const double PI = acos(-1); vector di = {1,0,-1,0}; vector dj = {0,1,0,-1}; #ifdef LOCAL # include # define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define debug(...) (static_cast(0)) #endif // https://youtu.be/ylWYSurx10A?t=2352 template struct Matrix{ int h, w; vector> d; Matrix() {} Matrix(int h, int w, T val=0): h(h), w(w), d(h, vector(w,val)) {} Matrix(int n, T val=0): h(n), w(n), d(n, vector(n,val)) {} Matrix& unit(){ assert(h == w); rep(i,h) d[i][i] = 1; return *this; } const vector& operator[](int i) const { return d[i];} vector& operator[](int i) { return d[i];} Matrix operator+(const Matrix& a) const { assert(h == a.h && w == a.w); Matrix r(h, w); rep(i,h)rep(j,w){ r[i][j] = d[i][j] + a[i][j]; } return r; } Matrix &operator+=(const Matrix& a) const { assert(h == a.h && w == a.w); rep(i,h)rep(j,w){ (*this)[i][j] += a[i][j]; } return (*this); } Matrix operator-(const Matrix& a) const { assert(h == a.h && w == a.w); Matrix r(h, w); rep(i,h)rep(j,w){ r[i][j] = d[i][j] - a[i][j]; } return r; } Matrix &operator-=(const Matrix& a) const { assert(h == a.h && w == a.w); rep(i,h)rep(j,w){ (*this)[i][j] -= a[i][j]; } return (*this); } Matrix operator*(const Matrix& a) const { assert(w == a.h); Matrix r(h, a.w); rep(i,h)rep(k,w)rep(j,a.w){ r[i][j] += d[i][k] * a[k][j]; } return r; } Matrix &operator*=(const Matrix& a) const { assert(w == a.h); vector> nd(h, vector(w)); rep(i,h)rep(k,w)rep(j,a.w){ nd[i][j] += (*this)[i][k] * a[k][j]; } d = move(nd); return (*this); } vector operator*(const vector &a) const { // res[i] = sum{ M[i][j] * x[j] } (j = 0 ... h-1) assert(w == (int)a.size()); vector r(h); rep(i,h)rep(j,w){ r[i] += (*this)[i][j] * a[j]; } return r; } Matrix operator*(const T &a) const { Matrix r(h, w); rep(i,h)rep(j,w){ r[i][j] = (*this)[i][j] * a; } return r; } Matrix &operator*=(const T &a) const { vector> nd(h, vector(w)); rep(i,h)rep(j,w){ nd[i][j] = (*this)[i][j] * a; } d = move(nd); return (*this); } bool operator==(const Matrix &a){ if(h != a.h || w != a.w) return false; rep(i,h)rep(j,w){ if((*this)[i][j] != a[i][j]) return false; } return true; } friend ostream &operator<<(ostream &os, Matrix &a){ rep(i,a.h){ os << (i == 0 ? '[' : ' '); rep(j,a.w) os << (j == 0 ? '[' : ' ') << a[i][j] << (j == a.w - 1 ? "]" : ","); os << (i == a.h - 1 ? "]" : ",") << '\n'; } return os; } // pii hw = mat.shape(); pair shape() {return {this->h, this->w};} // auto eye = Matrix::eye(3); static Matrix eye(int n){ Matrix mat(n, n); mat.unit(); return mat; } // auto AK = A.pow(K); Matrix pow(long long t) const { assert(h == w); if(!t) Matrix(h, h).unit(); if(t == 1) return *this; Matrix r = pow(t >> 1); r = r * r; if(t & 1) r = r * (*this); return r; } T det(){ assert(h == w); T res = 1; rep(k,h){ for(int i = k; i < h; i++){ if(d[i][k] == 0) continue; if(i != k){ swap(d[i], d[k]); res = -res; } } if(d[k][k] == 0) return 0; res *= d[k][k]; T inv = T(1) / d[k][k]; rep(j,h) d[k][j] *= inv; for(int i = k + 1; i < h; i++){ T c = d[i][k]; for(int j = k; j < h; j++) d[i][j] -= d[k][j] * c; } } return res; } }; const int D = 3; using mint = modint998244353; using S = Matrix; S op(S a, S b){return a * b;} S e(){ return Matrix::eye(D);} int main(){ cin.tie(0); ios_base::sync_with_stdio(false); int N, Q; cin >> N >> Q; string T; cin >> T; S eye = e(); S zero = e(); zero[0][1] = 1; S one = e(); one[1][0] = 1; one[1][2] = 1; vector dat(N); rep(i, N){ if(T[i] == '0') dat[N - 1 - i] = zero; if(T[i] == '1') dat[N - 1 - i] = one; } segtree seg(dat); set rest; rep(i, N) rest.insert(i); while(Q--){ int f, l, r; cin >> f >> l >> r; l--; if(f == 1){ auto itr = rest.lower_bound(l); while(itr != rest.end() && *itr < r){ seg.set(N - 1 - *itr, eye); itr = rest.erase(itr); } } else{ S res = seg.prod((N - 1) - r + 1, N - 1 - l + 1); cout << res[0][2] + res[1][2] << endl; } } }