#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=1e5+5, mod=1e9+2022;
int n, m, p[2*nx], sz[2*nx], v[nx];
vector<int> d[nx];
void dfs(int u)
{
for (auto v:d[u]) sz[v]=sz[u]+1, dfs(v);
}
struct segtree
{
int d1[4*nx], d2[4*nx];
void build(int l, int r, int i, vector<int> &t)
{
if (l==r) return t[l]?d1[i]=v[l]:d2[i]=v[l], void();
int md=(l+r)/2;
build(l, md, 2*i, t);
build(md+1, r, 2*i+1, t);
d1[i]=(d1[2*i]+d1[2*i+1])%mod;
d2[i]=(d2[2*i]+d2[2*i+1])%mod;
}
void update(int l, int r, int i, int idx)
{
if (l>idx) return;
if (r<=idx) return void(swap(d1[i], d2[i]));
int md=(l+r)/2;
update(l, md, 2*i, idx);
update(md+1, r, 2*i+1, idx);
d1[i]=(d1[2*i]+d1[2*i+1])%mod;
d2[i]=(d2[2*i]+d2[2*i+1])%mod;
}
} s;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
p[0]=1; n=N; m=M;
for (int i=1; i<N+M; i++) p[i]=(p[i-1]*2)%mod;
for (int i=1; i<N+M; i++) d[P[i]].push_back(i);
sz[0]=1; dfs(0);
for (int i=N; i<N+M; i++) v[i-N]=p[N-(sz[i]-1)];
s.build(0, M-1, 1, A);
}
int count_ways(int L, int R) {
s.update(0, m-1, 1, R-n);
s.update(0, m-1, 1, L-n-1);
return s.d1[1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6488 KB |
2nd lines differ - on the 1st token, expected: '2', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6488 KB |
2nd lines differ - on the 1st token, expected: '2', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6488 KB |
2nd lines differ - on the 1st token, expected: '2', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
429 ms |
8796 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '357186114' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
429 ms |
8796 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '357186114' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6488 KB |
2nd lines differ - on the 1st token, expected: '2', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6488 KB |
2nd lines differ - on the 1st token, expected: '2', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6488 KB |
2nd lines differ - on the 1st token, expected: '2', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |