asasas @ 2022-10-08 22:06:48
#include <bits/stdc++.h>
using namespace std;
vector<int> edge[200005];
long long mod=998244353;
struct as{
int op;
long long p,v,mul,s;
}cc[200005];
int n,m;
int ru[200005];
long long a[200005],b[200005],tp[200005];
int cnt;
void tuopu(){
queue<int> q;
for (register int i=1;i<=m;i++) if (!ru[i]) q.push(i);
// cout << endl;
while(!q.empty()){
int u=q.front();
q.pop();
tp[++cnt]=u;
// cout << u << ' ';
int len=edge[u].size();
for (register int i=0;i<len;i++){
int v=edge[u][i];
ru[v]--;
if (ru[v]==0){
q.push(v);
}
}
}
// cout << endl;
}
void pushdown1(){
for (register int i=m;i>=1;i--){
int u=tp[i];
int len=edge[u].size();
for (register int j=0;j<len;j++){
int v=edge[u][j];
cc[u].mul=(cc[v].mul*cc[u].mul)%mod;
}
}
}
void pushdown2(){
for (register int i=1;i<=m;i++){
int u=tp[i];
long long czmg=1;
int len=edge[u].size();
for (register int j=0;j<len;j++){
int v=edge[u][j];
cc[v].s=(cc[v].s+cc[u].s*czmg%mod)%mod;
czmg=czmg*cc[v].mul%mod;
}
}
}
int main(){
cin >> n;
for (register int i=1;i<=n;i++){
cin >> a[i];
}
cin >> m;
for (register int i=1;i<=m;i++){
cin >> cc[i].op;
if (cc[i].op==1){
cin >> cc[i].p >> cc[i].v;
cc[i].mul=1;
}
if (cc[i].op==2){
cin >> cc[i].mul;
cc[i].v=cc[i].mul;
}
if (cc[i].op==3){
int p;
cc[i].mul=1;
cin >> p;
for (register int j=1;j<=p;j++){
int v;
cin >> v;
edge[i].push_back(v);
ru[v]++;
}
}
}
tuopu();
pushdown1();
int q;
cin >> q;
for (register int i=1;i<=q;i++){
cin >> b[i];
}
long long now=1;
for (register int i=q;i>=1;i--){
cc[b[i]].s=(cc[b[i]].s+now)%mod;
now=now*cc[b[i]].mul%mod;
}
pushdown2();
for (register int i=1;i<=n;i++) a[i]=a[i]*now%mod;
for (register int i=1;i<=m;i++){
if (cc[i].op==1){
cout << cc[i].v << ' ' << cc[i].s << ' ' << cc[i].mul << ' ';
a[cc[i].p]=(a[cc[i].p]+cc[i].v*cc[i].s)%mod;
}
}
for (register int i=1;i<=n;i++) cout << a[i] << ' ';
}
by asasas @ 2022-10-08 22:08:34
调试没删