Submission #798675

#TimeUsernameProblemLanguageResultExecution timeMemory
798675JakobZorzDigital Circuit (IOI22_circuit)C++17
50 / 100
3033 ms10704 KiB
#include"circuit.h" #include<vector> #include<iostream> using namespace std; typedef long long ll; const int MOD=1000002022; int parents[200000]; ll sub_mul[200000]; vector<int>children[200000]; int n,m; ll vals[100000]; bool active[100000]; ll curr_res=0; void dfs2(int node){ if(children[node].empty()){ sub_mul[node]=1; return; } sub_mul[node]=children[node].size(); for(int ch:children[node]){ dfs2(ch); sub_mul[node]*=sub_mul[ch]; sub_mul[node]%=MOD; } } void dfs3(int node,ll val){ if(children[node].empty()){ vals[node-n]=val; return; } for(int ch:children[node]){ ll val2=val; for(int ch2:children[node]){ if(ch2!=ch){ val2*=sub_mul[ch2]; val2%=MOD; } } dfs3(ch,val2); } } void init(int N, int M, std::vector<int> P, std::vector<int> A) { n=N; m=M; for(int i=0;i<n+m;i++){ parents[i]=P[i]; if(parents[i]!=-1) children[parents[i]].push_back(i); } dfs2(0); dfs3(0,1); for(int i=0;i<(int)A.size();i++){ if(A[i]==1){ curr_res+=vals[i]; curr_res%=MOD; } active[i]=A[i]==1; } } int count_ways(int L, int R) { L-=n; R-=n; for(int i=L;i<=R;i++){ if(active[i]){ active[i]=false; curr_res+=MOD-vals[i]; curr_res%=MOD; }else{ active[i]=true; curr_res+=vals[i]; curr_res%=MOD; } } /*for(int i=0;i<m;i++) cout<<active[i]<<" "; cout<<"\n"; for(int i=0;i<m;i++) cout<<vals[i]<<" "; cout<<"\n";*/ return (int)curr_res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...