이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MOD = 1e9 + 2022;
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
int n, m;
vector<int> val, tot, a;
vector<vector<int>> filhos;
ll calc_tot(int x) {
if(x >= n) return 1;
tot[x] = sz(filhos[x]);
for(int viz : filhos[x]) {
tot[x] = (tot[x] * calc_tot(viz))%MOD;
}
return tot[x];
}
void dfs(int x) {
ll at = 1;
if(x >= n) return;
for(auto viz : filhos[x]) {
val[viz] = (val[x] * at)%MOD;
if(viz < n) at = (at*tot[viz])%MOD;
}
reverse(all(filhos[x]));
at = 1;
for(auto viz : filhos[x]) {
val[viz] = (val[viz] * at)%MOD;
if(viz < n) at = (at*tot[viz])%MOD;
}
for(auto viz : filhos[x]) dfs(viz);
}
void init(int N, int M, vector<int> P, vector<int> A) {
val.resize(N+M);
tot.resize(N);
filhos.resize(N);
a = A;
n = N;
m = M;
for(int i = 1; i < N+M; i++)
filhos[P[i]].pb(i);
calc_tot(0);
val[0] = 1;
dfs(0);
}
int count_ways(int L, int R) {
for(int i = L; i <= R; i++) a[i-n] = 1-a[i-n];
ll ans = 0;
for(int i = n; i < n + m; i++)
if(a[i-n]) ans = (ans + val[i])%MOD;
return ans;
}
# | 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... |