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;
const long long modulo = 1e9+2022;
namespace {
int N,M;
vector<int> A;
vector<long long> arr;
}
void init(int N,int M,vector<int> P,vector<int> A){
::N = N;
::M = M;
::A = A;
arr = vector<long long>(M);
vector<vector<int>> adj(N);
vector<vector<pair<long long,long long>>> ways(N);
for(int i=1;i<N+M;i++){adj[P[i]].emplace_back(i);ways[P[i]].emplace_back(1,1);}
{
function<long long(int)> dfs = [&](int x){
if(x>=N)return 1ll;
long long tot_ways = adj[x].size();
for(int i=0;i<adj[x].size();i++) {
ways[x][i].first=ways[x][i].second=dfs(adj[x][i]);
tot_ways=(tot_ways*ways[x][i].first)%modulo;
if(i)ways[x][i].first=(ways[x][i].first*ways[x][i-1].first)%modulo;
}
for(int i=adj[x].size()-2;i>=0;i--)ways[x][i].second=(ways[x][i].second*ways[x][i+1].second)%modulo;
return tot_ways;
};
dfs(0);
}
{
function<void(int,long long)> dfs = [&](int x,long long offset) {
if(x>=N) {
arr[x-N]=offset;
return;
}
for(int i=0;i<adj[x].size();i++) {
long long tot = 1;
if(i)tot=(tot*ways[x][i-1].first)%modulo;
if(i!=adj[x].size()-1)tot=(tot*ways[x][i+1].second)%modulo;
dfs(adj[x][i],tot);
}
};
dfs(0,1);
}
}
int count_ways(int L,int R){
L-=N;R-=N;
for(int i=L;i<=R;i++)A[i]^=1;
long long ans = 0;
for(int i=0;i<M;i++) {
if(A[i])ans+=arr[i];
ans%=modulo;
}
return ans;
}
Compilation message (stderr)
circuit.cpp: In lambda function:
circuit.cpp:25:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i=0;i<adj[x].size();i++) {
| ~^~~~~~~~~~~~~~
circuit.cpp: In lambda function:
circuit.cpp:41:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i=0;i<adj[x].size();i++) {
| ~^~~~~~~~~~~~~~
circuit.cpp:44:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | if(i!=adj[x].size()-1)tot=(tot*ways[x][i+1].second)%modulo;
| ~^~~~~~~~~~~~~~~~~
# | 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... |