This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |