#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll mod=998244353; ll fac[310000],inv[310000]; ll C(int n,int m) { ll res=fac[n]*inv[m]%mod*inv[n-m]%mod; return res; } struct node { int l,r,w,id; }a[210000]; int now; int n,m,nn; ll cc(int x,ll w,int id,int y) { if (x>y) return 0; return w*C(id+1+y-x,y-x)%mod; } ll cal(int x) { ll res=0; for (int i=1;i<=nn;i++) if (a[i].l<=x){ int tmp=now-a[i].id; ll par1 = cc(a[i].l,a[i].w,tmp,x)-cc(a[i].r+1, a[i].w,tmp,x); while(par1<0) par1 += mod; res=(res+par1+mod)%mod; } return res; } int main() { fac[0]=1; for (int i=1;i<=210010;i++) fac[i]=(fac[i-1]*i)%mod; inv[1]=inv[0]=1; for (int i=2;i<=210010;i++) { inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod; } for (int i=2;i<=210010;i++) inv[i]=(inv[i-1]*inv[i])%mod; int T; scanf("%d",&T); while (T--) { scanf("%d %d",&n,&m); now=nn=0; while (m--) { int op; scanf("%d",&op); if (op==1) { int l,r,w; scanf("%d %d %d",&l,&r,&w); a[++nn]={l,r,w,now}; } else if (op==2) now++; else { int l,r; scanf("%d %d",&l,&r); ll ans=(cal(r)-cal(l-1)+mod)%mod; printf("%lld\n",ans); } } } return 0; }
|