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
| #include<bits/stdc++.h> #define PII pair<int,int> using namespace std; const int N = 1e5 + 500; const int MOD = 998244353; int val[200 * N][5]; int tot,inv[10 * N],n,m,ls[200 * N],rs[200 * N],rt[10 * N]; int times(int a,int b){ int c; c = (1ll * a * b % MOD + 1ll * (1-a)%MOD * (1-b) % MOD)%MOD; c = (c + MOD)%MOD; return c; } int power(int a,int b){ int res = 1; while(b){ if(b & 1) res = 1ll * res * a % MOD; a = 1ll * a * a % MOD; b >>= 1; } return res; } void modify_y(int &now,int now_l,int now_r,int pos,int len){ if(!now){ now = ++tot; for(int i=0; i<=3; i++) val[now][i] = 1; } if(now_l == now_r){ int tmp; tmp = (1 - inv[len] + MOD)%MOD; val[now][0] = times(val[now][0],tmp); if(len >= 2){ tmp = (1 - 1ll * 2 * inv[len]%MOD + MOD) % MOD; val[now][1] = times(val[now][1],tmp); } tmp = inv[len]; val[now][2] = times(val[now][2],tmp); tmp = 0; val[now][3] = times(val[now][3],tmp); return; } int mid = (now_l + now_r)>>1; if(pos <= mid) modify_y(ls[now],now_l,mid,pos,len); if(pos > mid) modify_y(rs[now],mid+1,now_r,pos,len); for(int i=0; i<=3; i++){ val[now][i] = 1; if(ls[now]) val[now][i] = times(val[now][i],val[ls[now]][i]); if(rs[now]) val[now][i] = times(val[now][i],val[rs[now]][i]); } } void modify_x(int now,int now_l,int now_r,int x,int y,int len){ modify_y(rt[now],1,n,y,len); if(now_l == now_r) return; int mid = (now_l + now_r)>>1; if(x <= mid) modify_x(now<<1,now_l,mid,x,y,len); if(x > mid) modify_x(now<<1|1,mid+1,now_r,x,y,len); } int query_y(int now,int now_l,int now_r,int l,int r,int opt){ if(!now) return 1; if(l <= now_l && now_r <= r) return val[now][opt]; int mid = (now_l + now_r)>>1; int ans = 1; if(l <= mid) ans = times(ans,query_y(ls[now],now_l,mid,l,r,opt)); if(r > mid) ans = times(ans,query_y(rs[now],mid+1,now_r,l,r,opt)); return ans; } int query_x(int now,int now_l,int now_r,int xl,int xr,int yl,int yr,int opt){ if(xl > xr || yl > yr) return 1; if(xl <= now_l && now_r <= xr) return query_y(rt[now],1,n,yl,yr,opt); int mid = (now_l + now_r)>>1; int ans = 1; if(xl <= mid) ans = times(ans,query_x(now<<1,now_l,mid,xl,xr,yl,yr,opt)); if(xr > mid) ans = times(ans,query_x(now<<1|1,mid+1,now_r,xl,xr,yl,yr,opt)); return ans; } signed main(){
scanf("%d%d",&n,&m); inv[0] = 1; for(int i=1; i<=n; i++) inv[i] = power(i,MOD-2); while(m--){ int opt,l,r;scanf("%d%d%d",&opt,&l,&r); if(opt == 1) modify_x(1,1,n,l,r,r-l+1); if(opt == 2){ l = l-1; int ans; if(l == 0) ans = times(times(query_x(1,1,n,1,r-1,1,r-1,3),query_x(1,1,n,r+1,n,r+1,n,3)),query_x(1,1,n,1,r,r,n,2)); else ans = times(times(query_x(1,1,n,1,l,l,r-1,0),query_x(1,1,n,l+1,r,r,n,0)),query_x(1,1,n,1,l,r,n,1)); printf("%d\n",ans); } } return 0; }
|