1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| #include<cstdio> #define fo(i,a,b) for(int i=a;i<=b;i++) using namespace std;
typedef long long LL;
const int maxn=1e5+5, maxtr=4e7+5; const LL mo=998244353;
int n,m;
LL mul(LL x,LL y) { LL t=(1-2*y)%mo; t=(t<0) ?t+mo :t ; t=t*x+y; t=(t>=mo) ?t%mo :t ; return t; }
int son[maxtr][2],bz[maxtr],root[4*maxn],sum; LL ans; void xg_sec(int &k,int l,int r,int x,int y,LL z) { if (!k) bz[ k=++sum ]=0; if (l==x && r==y) { bz[k]=mul(bz[k],z); return; } int t1=(l+r)>>1; if (y<=t1) xg_sec(son[k][0],l,t1,x,y,z); else if (x>t1) xg_sec(son[k][1],t1+1,r,x,y,z); else xg_sec(son[k][0],l,t1,x,t1,z), xg_sec(son[k][1],t1+1,r,t1+1,y,z); } void xg_fir(int k,int l,int r,int x1,int y1,int x2,int y2,LL z) { if (l==x1 && r==y1) { xg_sec(root[k],0,n,x2,y2,z); return; } int t=k<<1, t1=(l+r)>>1; if (y1<=t1) xg_fir(t,l,t1,x1,y1,x2,y2,z); else if (x1>t1) xg_fir(t+1,t1+1,r,x1,y1,x2,y2,z); else xg_fir(t,l,t1,x1,t1,x2,y2,z), xg_fir(t+1,t1+1,r,t1+1,y1,x2,y2,z); } void cx_sec(int k,int l,int r,int x) { while (l<r) { if (!k) return; ans=mul(ans,bz[k]); int t1=(l+r)>>1; if (x<=t1) k=son[k][0], r=t1; else k=son[k][1], l=t1+1; } if (k) ans=mul(ans,bz[k]); } void cx_fir(int k,int l,int r,int x,int y) { while (l<r) { if (root[k]) cx_sec(root[k],0,n,y); int t=k<<1, t1=(l+r)>>1; if (x<=t1) k=t, r=t1; else k=t+1, l=t1+1; } if (root[k]) cx_sec(root[k],0,n,y); }
LL mi(LL x,LL y) { LL re=1; for(; y; y>>=1, x=x*x%mo) if (y&1) re=re*x%mo; return re; }
int main() { scanf("%d %d",&n,&m); while (m--) { int ty,x,y; scanf("%d %d %d",&ty,&x,&y); if (ty==1) { LL p=mi(y-x+1,mo-2); if (1<=x-1) xg_fir(1,0,n,1,x-1,x,y,p); if (y+1<=n) xg_fir(1,0,n,x,y,y+1,n,p); xg_fir(1,0,n,x,y,x,y,p*2%mo); xg_fir(1,0,n,0,0,0,x-1,1); if (y+1<=n) xg_fir(1,0,n,0,0,y+1,n,1); xg_fir(1,0,n,0,0,x,y,p*(y-x)%mo); } else { ans=1; cx_fir(1,0,n,x-1,y); printf("%lld\n",ans); } } }
|