23333
代码:
#include<cstdio> #include<cstring> #include<iostream> #define For(i,x,y) for(int i=x;i<=y;++i) using namespace std; const int N = 1e5+5; const int P = 998244353; int pw(int x,int y){int p=1;for(;y;y>>=1,x=(1ll*x*x)%P) if(y&1) p=(1ll*p*x)%P;return p;} int inv(int x){return pw(x,P-2);} int n,q,rt[N*4]; void mul(int&x,int y){x=((1-2ll*y)*x+y)%P;} struct Seg{ int ls[N*230],rs[N*230],w[N*230][2],tot; void ins(int&p,int l,int r,int x,int v){ if(!p) p=++tot; mul(w[p][0],v); mul(w[p][1],(v+v)%P); if(l==r) return; int m=l+r>>1; if(x<=m) ins(ls[p],l,m,x,v); else ins(rs[p],m+1,r,x,v); } int query(int p,int l,int r,int x,int y,int v){ if(!p||x<=l&&r<=y) return w[p][v]; int m=l+r>>1; int res=0; if(x<=m) mul(res,query(ls[p],l,m,x,y,v)); if(y> m) mul(res,query(rs[p],m+1,r,x,y,v)); return res; } }T; void ins(int p,int l,int r,int x,int y,int v){ T.ins(rt[p],1,n,y,v); if(l==r) return; int m=l+r>>1; if(x<=m) ins(p<<1,l,m,x,y,v); else ins(p<<1|1,m+1,r,x,y,v); } int query(int p,int l,int r,int xl,int xr,int yl,int yr,int v){ if(xl<=l&&r<=xr) return T.query(rt[p],1,n,yl,yr,v); int m=l+r>>1;int res=0; if(xl<=m) mul(res,query(p<<1,l,m,xl,xr,yl,yr,v)); if(xr> m) mul(res,query(p<<1|1,m+1,r,xl,xr,yl,yr,v)); return res; } bool F; int main(){ scanf("%d%d",&n,&q); for(int opt,x,y;q--;){ scanf("%d%d%d",&opt,&x,&y); if(opt==1){ F^=1; int p=inv(y-x+1); ins(1,0,n,x,y,p); }else{ --x; int T=0; mul(T,query(1,0,n,0,x,y,n,1)); mul(T,query(1,0,n,0,x,x,y-1,0)); mul(T,query(1,0,n,x+1,y,y,n,0)); for(;T<0;T+=P); if(x||!F) T=(1-T+P)%P; printf("%d\n",T); } } }