55分求助

P7077 [CSP-S2020] 函数调用

frank15 @ 2021-03-13 16:19:13

#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const ll mod=998244353;
int n,m,Q,C,TOT,X;
ll a[maxn],in1[maxn],in2[maxn];
struct change{
    int op,pos,val;
    ll mul,add;
}func[maxn];
vector<int> v1[maxn],v2[maxn];
void topo1(){
    queue<int> q;
    for(int i=0;i<=m;i++){
        in1[i]=v2[i].size();
        if(!v2[i].size()){
            q.push(i);
        }
    }
    while(q.size()){
        int now=q.front();
        q.pop();
        for(int i=0;i<v1[now].size();i++){
            in1[v1[now][i]]--;
            func[v1[now][i]].mul*=func[now].mul;
            func[v1[now][i]].mul%=mod;
            if(!in1[v1[now][i]])
                q.push(v1[now][i]);
        }
    }
    return ;
}
void topo2(){
    queue<int> q;
    for(int i=0;i<=m;i++){
        in2[i]=v1[i].size();
        if(!in2[i])
            q.push(i);
    }
    while(q.size()){
        int now=q.front();
        q.pop();
        ll now_mul=1;
        for(int i=v2[now].size()-1;i>=0;i--){
            in2[v2[now][i]]--;
            func[v2[now][i]].add+=func[now].add*now_mul;
            func[v2[now][i]].add%=mod;
            now_mul*=func[v2[now][i]].mul;
            now_mul%=mod;
            if(!in2[v2[now][i]])
                q.push(v2[now][i]);
        }
    }
    return ;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    scanf("%d",&m);
    for(int i=1;i<=m;i++){
        scanf("%d",&func[i].op);
        if(func[i].op==1){
            scanf("%d%d",&func[i].pos,&func[i].val);
            func[i].mul=1;
        }
        if(func[i].op==2)
            scanf("%lld",&func[i].mul);
        if(func[i].op==3){
            scanf("%d",&TOT);
            func[i].mul=1;
            for(int j=1;j<=TOT;j++){
                scanf("%d",&C);
                v1[C].push_back(i);
                v2[i].push_back(C);
            }
        }
    }
    scanf("%d",&Q);
    for(int i=1;i<=Q;i++){
        scanf("%d",&X);
        v1[X].push_back(0);
        v2[0].push_back(X);
    }
    func[0].mul=1;
    func[0].add=1;
    topo1();
    topo2();
    for(int i=1;i<=m;i++){
        a[i]*=func[0].mul;
        a[i]%=mod;
    }
    for(int i=1;i<=m;i++)
        if(func[i].op==1){
            a[func[i].pos]+=func[i].add*func[i].val;
            a[func[i].pos]%=mod;
        }
    for(int i=1;i<=n;i++)
        printf("%lld ",a[i]);
    return 0;
}

by frank15 @ 2021-03-13 16:21:35

我智障了,倒数十三行应是n。。。。。。


by Blunt_Feeling @ 2022-11-18 22:21:05

@frank15 大草 https://www.luogu.com.cn/record/94506440 一模一样的错误……


by _Extroversion @ 2023-11-02 15:26:19

我是处理每个函数的等价影响时把 m 写成 n 了,喜提 50pts,WA的点第几万列才有错qwq


|