all_unkown @ 2023-06-10 13:20:21
#include<cstdio>
#include<vector>
#define rt register int
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int N=1e6;
int n,m;
ll a[N+1],tmul=1;
ll t[N+1];
ll add[N+1],pos[N+1],mul[N+1],f[N+1];
ll enda[N+1];
inline int read()
{
char c=getchar();
int f=1,s=0;
while(c<48||c>57){if(c=='-')f=-f;c=getchar();}
while(c>=48&&c<=57){s=(s<<3)+(s<<1)+(c^48);c=getchar();}
return s*f;
}
int adj[N+1],nadj[N+1],nex[N+1],nnex[N+1],ter[N+1],nter[N+1],sum,nsum;
inline void adde(int x,int y){ter[++sum]=y,nex[sum]=adj[x],adj[x]=sum;}
inline void nadd(int x,int y){nter[++nsum]=y,nnex[nsum]=nadj[x],nadj[x]=nsum;}
inline void dfs(int x)
{
for(rt i=nadj[x];i;i=nnex[i])
{
int now=nter[i];
if(t[now]==1) enda[pos[now]]=(enda[pos[now]]+add[now]*tmul%mod)%mod;
if(tmul!=0)if(t[now]==2) tmul=tmul*mul[now]%mod;
if(t[now]==3)
dfs(now);
}
}
int main()
{
n=read();
int c,sg,Q;
for(rt i=1;i<=n;i++)
a[i]=read();
m=read();
for(rt i=1;i<=m;i++)
{
t[i]=read();
if(t[i]==1)
pos[i]=read(),add[i]=read();
if(t[i]==2)
mul[i]=read();
if(t[i]==3)
{
c=read();
for(rt j=1;j<=c;j++)
{
sg=read();
nadd(i,sg);
}
}
}
Q=read();
for(rt i=1;i<=Q;i++)
f[i]=read();
for(rt i=1;i<=Q;i++)
adde(f[0],f[i]);
for(rt i=adj[0];i;i=nex[i])
{
rt now=ter[i];
if(t[now]==1) enda[pos[now]]=(enda[pos[now]]+add[now]*tmul%mod)%mod;
if(tmul!=0)if(t[now]==2) tmul=tmul*mul[now]%mod;
if(t[now]==3)
dfs(now);
}
for(rt i=1;i<=n;i++)
printf("%lld ",(a[i]*tmul%mod+enda[i])%mod);
return 0;
}
by all_unkown @ 2023-06-10 13:23:38
10,11,18,19,20T了
by all_unkown @ 2023-06-10 13:33:28
我认为是O(∑Cj+max{n,m,Q})
by all_unkown @ 2023-06-10 13:46:00
利用了链表从后往前的性质,主函数之间加边t==3的函数的附属函数连特殊边