Submission #825415

#TimeUsernameProblemLanguageResultExecution timeMemory
825415pere_gilDigital Circuit (IOI22_circuit)C++17
7 / 100
3081 ms2097152 KiB
#include "circuit.h" #include "bits/stdc++.h" using namespace std; #define ll long long #define ii pair<ll,ll> const ll mod=1000002022; const int mxn=2e5+5; int n,m; vector<int> p,a; ll res[mxn][2]; int adj[mxn][2]; void init(int N, int M, vector<int> P, vector<int> A) { n=N,m=M; p=P; for(int i=0;i<n;i++) a.emplace_back(0); for(int i=0;i<m;i++) a.emplace_back(A[i]); memset(adj,-1,sizeof adj); for(int i=1;i<n+m;i++) adj[p[i]][adj[p[i]][0]!=-1]=i; } ii dfs(int u){ if(u>=n) return {!a[u],a[u]}; ii l=dfs(adj[u][0]),r=dfs(adj[u][1]); ll left=((l.first*r.second)%mod+(l.second*r.first)%mod+(2*l.first*r.first)%mod)%mod; ll right=((l.first*r.second)%mod+(l.second*r.first)%mod+(2*l.second*r.second)%mod)%mod; return {left,right}; } int count_ways(int l, int r) { for(int i=l;i<=r;i++) a[i]=1-a[i]; return dfs(0).second; }
#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...