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 <vector>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1'000'002'022;
int n, m;
vector<ll> storage;
vector<int> a;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n = N;
m = M;
vector<ll> degrees(N, 0);
for (int i=1; i<(N+M); i++)
degrees[P[i]]++;
storage = vector<ll> (N+M, 0);
vector<vector<bool>> ancestor(N+M, vector<bool> (N, 0));
for (int i=1; i<(N+M); i++)
{
int par = P[i];
for (int j=0; j<N; j++)
ancestor[i][j] = ancestor[par][j];
ancestor[i][par] = 1;
}
a = A;
for (int i=N; i<(N+M); i++)
{
ll ans = 1;
for (int j = 0; j<N; j++)
if (ancestor[i][j] == 0)
ans = (ans*degrees[j])%MOD;
storage.push_back(ans);
}
}
int count_ways(int L, int R) {
L -= n;
R -= n;
for (int i=L; i<=R; i++)
a[i] = 1-a[i];
ll total = 0;
for (int i=0; i<m; i++)
{
if (a[i]==1)
total+=storage[i];
}
ll fa = total%MOD;
int ffa = fa;
return ffa;
}
# | 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... |