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 <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,ll> pll;
#define ALL(x) x.begin(),x.end()
#define SIZE(x) (int)x.size()
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define fst first
#define snd second
#define pb push_back
const int MAXN = 2000;
const int MOD = 1e9+2022;
vi s, adj[MAXN];
int n, m;
void init(int N, int M, vi P, vi A) {
s=A, n=N, m=M;
forsn(i,1,n+m) adj[P[i]].pb(i);
}
pll dfs(int u) {
if(SIZE(adj[u])==0) {
return {!s[u-n], s[u-n]};
}
pll l = dfs(adj[u][0]);
forsn(i,1,SIZE(adj[u])) {
pll r = dfs(adj[u][i]);
ll ways = (l.fst * r.snd % MOD + l.snd * r.fst % MOD) % MOD;
l = {(ways + 2LL * l.fst * r.fst % MOD) % MOD,
(ways + 2LL * l.snd * r.snd % MOD) % MOD};
}
return l;
}
int count_ways(int L, int R) {
forsn(i,L,R+1) {
s[i-n]^=1;
}
return int(dfs(0).snd);
}
# | 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... |