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
| #pragma GCC optimize(3) #include<bits/stdc++.h> using namespace std;
void read(int &x) { x=0;int f=1;char ch=getchar(); for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f; for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f; }
void print(int x) { if(x<0) putchar('-'),x=-x; if(!x) return ;print(x/10),putchar(x%10+48); } void write(int x) {if(!x) putchar('0');else print(x);putchar(' ');}
#define lf double #define ll long long
#define pii pair<int,int > #define vec vector<int >
#define pb push_back #define mp make_pair #define fr first #define sc second
#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)
const int maxn = 1e6+10; const int inf = 1e9; const lf eps = 1e-8; const int mod = 998244353;
int n,f[502][502],q,t[502],w[502],g[502],inv[502];
int qpow(int a,int x) { int res=1; for(;x;x>>=1,a=1ll*a*a%mod) if(x&1) res=1ll*res*a%mod; return res; }
int add(int x,int y) {x+=y;if(x>=mod) x-=mod;return x;} int del(int x,int y) {x-=y;x+=x>>31&mod;return x;}
void modify() { int x,p,v;read(x),read(p),read(v),p=1ll*p*qpow(v,mod-2)%mod; for(int i=1;i<=100;i++) t[i]=add(1ll*f[x][i]*(1-p+mod)%mod,1ll*f[x][i+1]*p%mod); t[0]=add(f[x][0],1ll*f[x][1]*p%mod); for(int i=0;i<=100;i++) f[x][i]=t[i]; }
void solve() { int k;read(k); memset(g,0,sizeof g);g[0]=1; for(int i=1,x;i<=k;i++) { read(x),w[i]=del(1,f[x][0]); for(int j=k;j;j--) g[j]=add(1ll*g[j]*(1-w[i]+mod)%mod,1ll*g[j-1]*w[i]%mod); g[0]=1ll*g[0]*(1-w[i]+mod)%mod; } for(int i=1;i<=k;i++) { if(w[i]==0) {putchar('0'),putchar(' ');continue;} if(w[i]==1) { int ans=0; for(int j=1;j<=k;j++) ans=add(ans,1ll*g[j]*inv[j]%mod); write(ans); continue; } int tmp=qpow(1-w[i]+mod,mod-2); t[0]=1ll*g[0]*tmp%mod; for(int j=1;j<k;j++) t[j]=del(g[j],1ll*w[i]*t[j-1]%mod),t[j]=1ll*t[j]*tmp%mod; int ans=0; for(int j=0;j<k;j++) ans=add(ans,1ll*t[j]*inv[j+1]%mod); write(1ll*ans*w[i]%mod); }putchar('\n'); }
int main() { read(n);inv[0]=1; for(int i=1,x;i<=n;i++) read(x),f[i][x]=1,inv[i]=qpow(i,mod-2); read(q); for(int i=1,op;i<=q;i++) read(op),op?(solve(),0):(modify(),0); for(int i=1;i<=n;i++) { int ans=0; for(int j=1;j<=100;j++) ans=(ans+1ll*j*f[i][j]%mod)%mod; write(ans); }putchar('\n'); return 0; }
|