M1saka16I72 @ 2024-08-26 09:52:03
盯着看半天了都没看出来问题在哪,大样例都过不去/ll/ll/ll
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pil pair<int,long long>
#define pll pair<long long,long long>
#define mp_ make_pair
#define pb_ push_back
#define pob_ pop_back
#define fst first
#define snd second
#define debug cout<<"********\n";
#define reset(x,y) memset(x,y,sizeof(x))
#define fi(x) freopen(x,"r",stdin)
#define fo(x) freopen(x,"w",stdout)
#define iosf ios::sync_with_stdio(0);cin.tie(0);
#define prec(x) cout<<setprecision(x);
#define prec0(x) cout<<fixed<<setprecision(x);
#define Misaka16172 sb
#define kamisako femboy
using ll = long long;
using ld = long double;
using db = double;
using ull = unsigned long long;
using uint = unsigned int;
constexpr int inf = 0x3f3f3f3f;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ull mod1 = 1e9+7,mod9 = 998244353;
using namespace std;
template <class T>
inline void read(T &x){
x = 0;T w = 1;
char c = 0;
while(!isdigit(c)){
if(c=='-') w = -1;
c = getchar();
}
while(isdigit(c)){
x = ((x<<3)+(x<<1))+c-'0';
c = getchar();
}
x = x*w;
}
template<class T,typename ...Args>
inline void read(T &x,Args &...rest){read(x);read(rest...);}
template<class T>
inline void write(T x){
if(!x) return putchar('0'),void();
else if(x<0) putchar('-'),x*=-1;
int st[40],t = 0;
while(x){st[++t] = x%10,x/=10;}
while(t){putchar(st[t--]+'0');}
}
template <class T>
inline string bin(T x,int d = 0){return (((d>1)||(x>>1))?bin(x>>1,d-1):"")+to_string(x&1);}
int Test = 1,Case = 1;
template<uint mod>
class modInt{
int v;
private:
inline int qpow(int x,int y){
int res = 1;
while(y){
if(y&1) res = 1ll*res*x%mod;
x = 1ll*x*x%mod,y>>=1;
}
return res;
}
inline int fix(ll x){return x>=mod?(x%mod):x;}
public:
modInt(){v = 0;}
modInt(ll x){v = fix(x);}
inline modInt operator +(const modInt &x)const{return modInt((ll)v+x.v);}
inline modInt operator +(const ll &x)const{return *this+modInt(x);}
inline modInt operator -(const modInt &x)const{return modInt(v-x.v>=0?(v-x.v):(v-x.v+mod));}
inline modInt operator -(const ll &x)const{return *this-modInt(x);}
inline modInt operator *(const modInt &x)const{return modInt(1ll*v*x.v);}
inline modInt operator *(const ll &x)const{return *this*modInt(x);}
inline modInt operator /(const modInt x){return modInt(1ll*v*qpow(x.v,mod-2));} //can only be used when mod is a prime
inline modInt operator /(const ll &x)const{return modInt(v/x);}
inline modInt operator %(const modInt &x)const{return modInt(v%x.v);}
inline modInt operator %(const ll &x)const{return modInt(v%x);}
inline modInt operator <<(const modInt &x)const{return modInt((ll)v<<x.v);}
inline modInt operator <<(const int &x)const{return modInt((ll)v<<x);}
inline modInt operator >>(const modInt &x)const{return modInt(v>>x.v);}
inline modInt operator >>(const int &x)const{return modInt((ll)v>>x);}
inline void operator +=(modInt x){v = fix((ll)v+x.v);}
inline void operator +=(ll x){v = fix((ll)v+x);}
inline void operator -=(modInt x){v = (v-x.v>=0)?(v-x.v):(v-x.v+mod);}
inline void operator -=(ll x){x = fix(x),v = (v-x>=0)?(v-x):(v-x+mod);}
inline void operator *=(modInt x){v = 1ll*v*x.v%mod;}
inline void operator *=(ll x){x = fix(x),v = 1ll*v*x%mod;}
inline void operator /=(modInt x){v = 1ll*v*qpow(x.v,mod-2)%mod;}
inline void operator /=(ll x){v/=x;}
inline void operator %=(modInt x){v%=x.v;}
inline void operator %=(ll x){v%=x;}
inline void operator <<=(modInt x){v = fix((ll)v<<x.v);}
inline void operator <<=(int x){v = fix((ll)v<<x);}
inline void operator >>=(modInt x){v>>=x.v;}
inline void operator >>=(int x){v>>=x;}
explicit operator int()const{return v;}
};
using mint = modInt<mod9>;
constexpr int N = 1e5+5;
mint f[N],a[N],v[N],k[N];
bool vis[N];
vector<int> G[N];
int t[N],p[N],deg[N],n,m;
mint dp(int u){
if(!vis[u]){
f[u] = vis[u] = 1;
if(t[u]==2) f[u] = v[u];
if(t[u]==3) for(int v:G[u]) f[u]*=dp(v);
}
return f[u];
}
void topo(){
queue<int> q;
q.push(0);
while(!q.empty()){
int u = q.front();q.pop();
mint tag = k[u];
for(auto it=G[u].rbegin();it!=G[u].rend();it++){
deg[*it]--;
if(!deg[*it]) q.push(*it);
k[*it]+=tag;
tag*=dp(*it);
}
}
}
void solve(){
read(n);
for(int i=1;i<=n;i++) read(a[i]);
read(m);
for(int i=1;i<=m;i++){
read(t[i]);
if(t[i]==1) read(p[i],v[i]);
else if(t[i]==2) read(v[i]);
else{
int c;read(c);
for(int j=0;j<c;j++){
int x;read(x);
G[i].pb_(x),deg[x]++;
}
}
}
t[0] = 3;
int q;read(q);
for(int i=1;i<=q;i++){
int x;read(x);
G[0].pb_(x),deg[x]++;
}
for(int i=0;i<=n;i++) a[i]*=dp(0);
k[0] = 1;
topo();
for(int i=1;i<=m;i++) if(t[i]==1) a[p[i]]+=v[i]*k[i];
for(int i=1;i<=n;i++) cout<<(int)a[i]<<" ";
}
int main(){
// read(Test);
for(;Case<=Test;++Case) solve();
return 0;
}
by M1saka16I72 @ 2024-08-26 10:07:56
调过了。
死因:初始状态下入度为