#include #include #include using namespace std; template struct matrix { public: int row,col; matrix(int row, int col) { this->row=row; this->col=col; this->A.resize(row); for(int i=0;iA[i].resize(col); } matrix(const vector>&v) { this->row=v.size(); this->col=v[0].size(); A.resize(row); for(int i=0;i> M) { int n=M.size(),m=M[0].size(); int r=M[0][0].row,c=M[0][0].col; row=n*r,col=m*c; A.resize(row); for(int i=0;i&operator[](int p){return this->A[p];} const vector&operator[](int p)const{return this->A[p];} matrix& operator+=(const matrix& B) { assert(B.row==row); assert(B.col==col); B.col=1; for(int i=0;iA[i][j]+=B[i][j]; } return *this; } matrix& operator-=(const matrix& B) { assert(B.row==row); assert(B.col==col); for(int i=0;irow;i++)for(int j=0;jcol;j++) { this->A[i][j]-=B[i][j]; } return *this; } matrix& operator*=(const matrix& B) { assert(row==col); assert(B.row==row); assert(B.col==col); matrix res(row,row); for(int i=0;iA[i][k]*B[k][j]; } return *this=res; } matrix operator*(const matrix& B)const { assert(B.row==col); matrix res(row,B.col); for(int i=0;iA[i][k]*B[k][j]; } return res; } matrix& operator*=(const mint& r) { for(int i=0;iA[i][j]*=r; } return *this; } matrix& operator/=(const mint& r) { mint inv=mint(r).inv(); (*this)*=inv; return *this; } matrix operator+(const matrix& B)const{return matrix(*this)+=B;} matrix operator-(const matrix &B)const{return matrix(*this)-=B;} matrix operator*(const mint& r)const{return matrix(*this)*=r;} matrix operator/(const mint& r)const{return matrix(*this)/=r;} bool operator==(const matrix& B)const { if(row!=B.row||col!=B.col)return 0; for(int i=0;i>=1; } return res; } mint det()const { assert(row==col); int cnt=0; matrix B=*this; for(int i=0;idet()!=0); matrix B=*this; matrix invB=I(row); for(int i=0;i>A; }; using mint=atcoder::modint998244353; using mat=matrix; const mat I=mat::I(3); const mat zero=vector>{{1,1,0},{0,1,0},{0,0,1}}; const mat one=vector>{{1,0,0},{1,1,1},{0,0,1}}; mat op(mat a, mat b){return a*b;} mat e(){return I;} int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N,Q; cin>>N>>Q; atcoder::segtreeseg(N); setbar; for(int i=0;i>S; reverse(S.begin(),S.end()); for(int i=0;i>t>>l>>r; int L=N-r,R=N-l+1; if(t==1) { auto it=bar.lower_bound(L); while(it!=bar.end()&&*it