#include "circuit.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const ll MOD = 1000002022;
const int MN = 1e5 + 10;
vvi ch;
vll w;
int n, m;
vll totPos;
void sdfs(int c) {
totPos[c] = c >= n ? 1 : ch[c].size();
for(int i : ch[c]) {
sdfs(i);
totPos[c] = totPos[c] * totPos[i] % MOD;
}
}
void dfs(int c, ll cw) {
w[c] = cw;
for(int i : ch[c]) {
ll wCh = cw;
for(int j : ch[c]) if(j != i) wCh = wCh * totPos[j] % MOD;
dfs(i, wCh);
}
}
vb tgl;
struct node {
ll tot, iTot;
bool lz;
};
const int MM = 1e5 + 10, ME = 4 * MM;
node seg[ME];
void push(int c) {
if(2 * c + 1 < ME) {
if(seg[c].lz) {
swap(seg[2*c].tot, seg[2*c].iTot);
seg[2*c].lz = !seg[2*c].lz;
swap(seg[2*c+1].tot, seg[2*c+1].iTot);
seg[2*c+1].lz = !seg[2*c+1].lz;
seg[c].lz = false;
}
}
}
void build(int v, int nl, int nr) {
if(nl == nr) {
if(tgl[nl + n]) seg[v].tot = w[nl+n], seg[v].iTot = 0;
else seg[v].tot = 0, seg[v].iTot = w[nl+n];
} else {
int mid = (nl+nr)/2;
build(2*v, nl, mid);
build(2*v+1, mid+1, nr);
seg[v].tot = (seg[2*v].tot+seg[2*v+1].tot) % MOD;
seg[v].iTot = (seg[2*v].iTot+seg[2*v+1].iTot) % MOD;
}
}
void upd(int v, int nl, int nr, int l, int r) {
push(v);
if(l > r) return;
if(l == nl && r == nr) {
swap(seg[v].tot, seg[v].iTot);
assert(!seg[v].lz);
seg[v].lz = true;
} else {
int mid = (nl+nr)/2;
upd(2*v, nl, mid, l, min(mid, r));
upd(2*v+1, mid+1, nr, max(mid+1,l), r);
seg[v].tot = (seg[2*v].tot + seg[2*v+1].tot) % MOD;
seg[v].iTot = (seg[2*v].iTot + seg[2*v+1].iTot) % MOD;
}
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
::n = N, ::m = M;
ch.resize(N+M);
totPos.resize(N+M);
w.resize(N+M);
tgl.resize(N+M);
REP(i, 1, N+M) ch[P[i]].push_back(i);
sdfs(0);
dfs(0, 1);
forR(i, M) tgl[N+i] = A[i] == 1;
build(1, 0, m-1);
}
int count_ways(int L, int R) {
upd(1, 0, m-1, L-n, R-n);
ll tot = seg[1].tot;
return (int) tot;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
504 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
504 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
0 ms |
600 KB |
Output is correct |
26 |
Correct |
0 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
600 KB |
Output is correct |
28 |
Correct |
0 ms |
600 KB |
Output is correct |
29 |
Correct |
4 ms |
344 KB |
Output is correct |
30 |
Correct |
4 ms |
496 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
600 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
37 |
Correct |
4 ms |
600 KB |
Output is correct |
38 |
Correct |
4 ms |
636 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
344 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
356 ms |
8104 KB |
Output is correct |
2 |
Correct |
598 ms |
14572 KB |
Output is correct |
3 |
Correct |
573 ms |
14776 KB |
Output is correct |
4 |
Correct |
582 ms |
14784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
356 ms |
8104 KB |
Output is correct |
2 |
Correct |
598 ms |
14572 KB |
Output is correct |
3 |
Correct |
573 ms |
14776 KB |
Output is correct |
4 |
Correct |
582 ms |
14784 KB |
Output is correct |
5 |
Correct |
466 ms |
7580 KB |
Output is correct |
6 |
Correct |
603 ms |
14576 KB |
Output is correct |
7 |
Correct |
583 ms |
14708 KB |
Output is correct |
8 |
Correct |
570 ms |
13400 KB |
Output is correct |
9 |
Correct |
285 ms |
856 KB |
Output is correct |
10 |
Correct |
564 ms |
3160 KB |
Output is correct |
11 |
Correct |
557 ms |
3160 KB |
Output is correct |
12 |
Correct |
559 ms |
3160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
356 ms |
8104 KB |
Output is correct |
14 |
Correct |
598 ms |
14572 KB |
Output is correct |
15 |
Correct |
573 ms |
14776 KB |
Output is correct |
16 |
Correct |
582 ms |
14784 KB |
Output is correct |
17 |
Correct |
466 ms |
7580 KB |
Output is correct |
18 |
Correct |
603 ms |
14576 KB |
Output is correct |
19 |
Correct |
583 ms |
14708 KB |
Output is correct |
20 |
Correct |
570 ms |
13400 KB |
Output is correct |
21 |
Correct |
285 ms |
856 KB |
Output is correct |
22 |
Correct |
564 ms |
3160 KB |
Output is correct |
23 |
Correct |
557 ms |
3160 KB |
Output is correct |
24 |
Correct |
559 ms |
3160 KB |
Output is correct |
25 |
Runtime error |
42 ms |
37584 KB |
Execution killed with signal 6 |
26 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
504 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
0 ms |
600 KB |
Output is correct |
26 |
Correct |
0 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
600 KB |
Output is correct |
28 |
Correct |
0 ms |
600 KB |
Output is correct |
29 |
Correct |
4 ms |
344 KB |
Output is correct |
30 |
Correct |
4 ms |
496 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
600 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
37 |
Correct |
4 ms |
600 KB |
Output is correct |
38 |
Correct |
4 ms |
636 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
344 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
376 ms |
2904 KB |
Output is correct |
44 |
Correct |
553 ms |
2904 KB |
Output is correct |
45 |
Correct |
547 ms |
2904 KB |
Output is correct |
46 |
Correct |
558 ms |
3160 KB |
Output is correct |
47 |
Correct |
579 ms |
3160 KB |
Output is correct |
48 |
Correct |
544 ms |
3160 KB |
Output is correct |
49 |
Correct |
626 ms |
3160 KB |
Output is correct |
50 |
Correct |
571 ms |
3160 KB |
Output is correct |
51 |
Correct |
609 ms |
2968 KB |
Output is correct |
52 |
Correct |
676 ms |
2972 KB |
Output is correct |
53 |
Correct |
489 ms |
1120 KB |
Output is correct |
54 |
Correct |
495 ms |
3160 KB |
Output is correct |
55 |
Correct |
536 ms |
2904 KB |
Output is correct |
56 |
Correct |
556 ms |
2904 KB |
Output is correct |
57 |
Correct |
531 ms |
2904 KB |
Output is correct |
58 |
Correct |
580 ms |
3416 KB |
Output is correct |
59 |
Correct |
668 ms |
3684 KB |
Output is correct |
60 |
Correct |
632 ms |
3688 KB |
Output is correct |
61 |
Correct |
498 ms |
3160 KB |
Output is correct |
62 |
Correct |
558 ms |
2904 KB |
Output is correct |
63 |
Correct |
587 ms |
2904 KB |
Output is correct |
64 |
Correct |
542 ms |
2904 KB |
Output is correct |
65 |
Correct |
271 ms |
856 KB |
Output is correct |
66 |
Correct |
540 ms |
3160 KB |
Output is correct |
67 |
Correct |
546 ms |
3160 KB |
Output is correct |
68 |
Correct |
571 ms |
3160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
504 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
0 ms |
600 KB |
Output is correct |
26 |
Correct |
0 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
600 KB |
Output is correct |
28 |
Correct |
0 ms |
600 KB |
Output is correct |
29 |
Correct |
4 ms |
344 KB |
Output is correct |
30 |
Correct |
4 ms |
496 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
600 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
37 |
Correct |
4 ms |
600 KB |
Output is correct |
38 |
Correct |
4 ms |
636 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
344 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
356 ms |
8104 KB |
Output is correct |
44 |
Correct |
598 ms |
14572 KB |
Output is correct |
45 |
Correct |
573 ms |
14776 KB |
Output is correct |
46 |
Correct |
582 ms |
14784 KB |
Output is correct |
47 |
Correct |
466 ms |
7580 KB |
Output is correct |
48 |
Correct |
603 ms |
14576 KB |
Output is correct |
49 |
Correct |
583 ms |
14708 KB |
Output is correct |
50 |
Correct |
570 ms |
13400 KB |
Output is correct |
51 |
Correct |
285 ms |
856 KB |
Output is correct |
52 |
Correct |
564 ms |
3160 KB |
Output is correct |
53 |
Correct |
557 ms |
3160 KB |
Output is correct |
54 |
Correct |
559 ms |
3160 KB |
Output is correct |
55 |
Runtime error |
42 ms |
37584 KB |
Execution killed with signal 6 |
56 |
Halted |
0 ms |
0 KB |
- |