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
| #include<bits/stdc++.h> using namespace std;
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
char IO; int rd(){ int s=0,f=0; while(!isdigit(IO=getchar())) if(IO=='-') f=1; do s=(s<<1)+(s<<3)+(IO^'0'); while(isdigit(IO=getchar())); return f?-s:s; }
const int N=1e5+10,P=998244353;
int n,m; int A[N],T[N],H[N];
int O[N],X[N],Y[N]; int B[N*11],C,L[N],R[N],ind[N]; int Q[N],QL,QR;
int main() { rep(i,1,n=rd()) A[i]=rd(); m=rd()+1; rep(i,1,m) { O[i]=i<m?rd():3,T[i]=1; if(O[i]==1) X[i]=rd(),Y[i]=rd(); else if(O[i]==2) T[i]=rd(); else { L[i]=C+1,R[i]=C+=rd(); rep(j,L[i],R[i]) ind[B[j]=rd()]++; } } rep(i,QL=1,m) if(!ind[i]) Q[++QR]=i; while(QL<=QR) { int u=Q[QL++]; if(O[u]==3) rep(j,L[u],R[u]) if(--ind[B[j]]==0) Q[++QR]=B[j]; } drep(k,m,1){ int u=Q[k]; if(O[u]==3) rep(j,L[u],R[u]) T[u]=1ll*T[u]*T[B[j]]%P; } rep(i,H[m]=1,n) A[i]=1ll*A[i]*T[m]%P; rep(k,1,m) { int u=Q[k],x=1; drep(j,R[u],L[u]){ int v=B[j]; H[v]=(H[v]+1ll*x*H[u])%P; x=1ll*x*T[v]%P; } if(O[u]==1) A[X[u]]=(A[X[u]]+1ll*H[u]*Y[u])%P; } rep(i,1,n) printf("%d ",A[i]); puts(""); }
|