#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "circuit.h"
const ll MOD = 1000002022;
VL contr;
struct SEGTREE {
int n;
VL tree1, tree2;
VI lazy;
SEGTREE(){}
SEGTREE(VI val) {
n = 1;
while (n < val.size()) n *= 2;
tree1 = tree2 = VL(2*n);
lazy = VI(2*n);
rep(i, val.size()) {
if (val[i]) tree1[i + n-1] = contr[i];
else tree2[i + n-1] = contr[i];
}
build(0, 0, n-1);
}
void build(int N, int L, int R) {
if (L == R) return;
int M = (L + R) / 2;
build(2*N+1, L, M);
build(2*N+2, M+1, R);
tree1[N] = (tree1[2*N+1] + tree1[2*N+2]) % MOD;
tree2[N] = (tree2[2*N+1] + tree2[2*N+2]) % MOD;
}
void push(int N) {
if (lazy[N]%2) swap(tree1[N], tree2[N]);
if (2*N+2 < 2*n) {
lazy[2*N+1] += lazy[N];
lazy[2*N+2] += lazy[N];
}
lazy[N] = 0;
}
void upd(int N, int L, int R, int l, int r) {
push(N);
if (R < l || L > r) return;
if (l <= L && R <= r) {
lazy[N]++;
push(N);
return;
}
int M = (L + R) / 2;
upd(2*N+1, L, M, l, r);
upd(2*N+2, M+1, R, l, r);
tree1[N] = (tree1[2*N+1] + tree1[2*N+2]) % MOD;
tree2[N] = (tree2[2*N+1] + tree2[2*N+2]) % MOD;
}
void upd(int l, int r) {
upd(0, 0, n-1, l, r);
}
ll get() {
return tree1[0];
}
} seg;
int n;
VVI gp;
VL sub;
ll dfs1(int u = 0) {
sub[u] = max((ll)gp[u].size(), 1ll);
for (int v : gp[u]) sub[u] = sub[u] * dfs1(v) % MOD;
return sub[u];
}
void dfs2(int u = 0, ll prod = 1) {
contr[u] = prod;
VL a;
a.pb(1);
for (int v : gp[u]) a.pb(sub[v]);
a.pb(1);
int c = a.size();
VL pref, suff;
pref = suff = a;
replr(i, 1, c-1) pref[i] = pref[i-1] * pref[i] % MOD;
reprl(i, c-2, 0) suff[i] = suff[i+1] * suff[i] % MOD;
int i = 1;
for (int v : gp[u]) dfs2(v, prod*pref[i-1]%MOD*suff[i+1]%MOD), i++;
}
void init(int N, int M, VI par, VI A) {
n = N + M;
gp = VVI(n);
rep(u, n) if (u) gp[par[u]].pb(u);
VI val = VI(n);
rep(u, M) val[u+N] = A[u];
contr = VL(n);
sub = VL(n);
dfs1();
dfs2();
seg = SEGTREE(val);
}
int count_ways(int L, int R) {
seg.upd(L, R);
return seg.get();
}
Compilation message
circuit.cpp: In constructor 'SEGTREE::SEGTREE(VI)':
circuit.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | while (n < val.size()) n *= 2;
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
544 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
420 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
544 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
376 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
420 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
856 KB |
Output is correct |
19 |
Correct |
1 ms |
856 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
564 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
856 KB |
Output is correct |
37 |
Correct |
1 ms |
700 KB |
Output is correct |
38 |
Correct |
1 ms |
856 KB |
Output is correct |
39 |
Correct |
1 ms |
600 KB |
Output is correct |
40 |
Correct |
1 ms |
600 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 |
414 ms |
7768 KB |
Output is correct |
2 |
Correct |
732 ms |
15184 KB |
Output is correct |
3 |
Correct |
652 ms |
15192 KB |
Output is correct |
4 |
Correct |
726 ms |
15184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
414 ms |
7768 KB |
Output is correct |
2 |
Correct |
732 ms |
15184 KB |
Output is correct |
3 |
Correct |
652 ms |
15192 KB |
Output is correct |
4 |
Correct |
726 ms |
15184 KB |
Output is correct |
5 |
Correct |
600 ms |
7768 KB |
Output is correct |
6 |
Correct |
726 ms |
15184 KB |
Output is correct |
7 |
Correct |
704 ms |
15180 KB |
Output is correct |
8 |
Correct |
747 ms |
15188 KB |
Output is correct |
9 |
Correct |
327 ms |
868 KB |
Output is correct |
10 |
Correct |
685 ms |
1368 KB |
Output is correct |
11 |
Correct |
655 ms |
1368 KB |
Output is correct |
12 |
Correct |
683 ms |
1368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
420 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
414 ms |
7768 KB |
Output is correct |
14 |
Correct |
732 ms |
15184 KB |
Output is correct |
15 |
Correct |
652 ms |
15192 KB |
Output is correct |
16 |
Correct |
726 ms |
15184 KB |
Output is correct |
17 |
Correct |
600 ms |
7768 KB |
Output is correct |
18 |
Correct |
726 ms |
15184 KB |
Output is correct |
19 |
Correct |
704 ms |
15180 KB |
Output is correct |
20 |
Correct |
747 ms |
15188 KB |
Output is correct |
21 |
Correct |
327 ms |
868 KB |
Output is correct |
22 |
Correct |
685 ms |
1368 KB |
Output is correct |
23 |
Correct |
655 ms |
1368 KB |
Output is correct |
24 |
Correct |
683 ms |
1368 KB |
Output is correct |
25 |
Correct |
731 ms |
25284 KB |
Output is correct |
26 |
Correct |
867 ms |
25424 KB |
Output is correct |
27 |
Correct |
766 ms |
25424 KB |
Output is correct |
28 |
Correct |
647 ms |
25416 KB |
Output is correct |
29 |
Correct |
822 ms |
45648 KB |
Output is correct |
30 |
Correct |
756 ms |
45632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
544 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
376 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
420 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
856 KB |
Output is correct |
19 |
Correct |
1 ms |
856 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
564 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
856 KB |
Output is correct |
37 |
Correct |
1 ms |
700 KB |
Output is correct |
38 |
Correct |
1 ms |
856 KB |
Output is correct |
39 |
Correct |
1 ms |
600 KB |
Output is correct |
40 |
Correct |
1 ms |
600 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
425 ms |
1184 KB |
Output is correct |
44 |
Correct |
694 ms |
1264 KB |
Output is correct |
45 |
Correct |
663 ms |
1224 KB |
Output is correct |
46 |
Correct |
645 ms |
1836 KB |
Output is correct |
47 |
Correct |
659 ms |
1832 KB |
Output is correct |
48 |
Correct |
709 ms |
1832 KB |
Output is correct |
49 |
Correct |
680 ms |
1832 KB |
Output is correct |
50 |
Correct |
707 ms |
1840 KB |
Output is correct |
51 |
Correct |
657 ms |
1120 KB |
Output is correct |
52 |
Correct |
682 ms |
1116 KB |
Output is correct |
53 |
Correct |
594 ms |
2136 KB |
Output is correct |
54 |
Correct |
702 ms |
1824 KB |
Output is correct |
55 |
Correct |
667 ms |
1280 KB |
Output is correct |
56 |
Correct |
651 ms |
1208 KB |
Output is correct |
57 |
Correct |
688 ms |
1088 KB |
Output is correct |
58 |
Correct |
646 ms |
2648 KB |
Output is correct |
59 |
Correct |
712 ms |
2648 KB |
Output is correct |
60 |
Correct |
611 ms |
2648 KB |
Output is correct |
61 |
Correct |
639 ms |
1508 KB |
Output is correct |
62 |
Correct |
629 ms |
1156 KB |
Output is correct |
63 |
Correct |
676 ms |
1124 KB |
Output is correct |
64 |
Correct |
733 ms |
1152 KB |
Output is correct |
65 |
Correct |
344 ms |
880 KB |
Output is correct |
66 |
Correct |
676 ms |
1368 KB |
Output is correct |
67 |
Correct |
676 ms |
1620 KB |
Output is correct |
68 |
Correct |
663 ms |
1368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
544 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
376 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
420 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
856 KB |
Output is correct |
19 |
Correct |
1 ms |
856 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
564 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
856 KB |
Output is correct |
37 |
Correct |
1 ms |
700 KB |
Output is correct |
38 |
Correct |
1 ms |
856 KB |
Output is correct |
39 |
Correct |
1 ms |
600 KB |
Output is correct |
40 |
Correct |
1 ms |
600 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
414 ms |
7768 KB |
Output is correct |
44 |
Correct |
732 ms |
15184 KB |
Output is correct |
45 |
Correct |
652 ms |
15192 KB |
Output is correct |
46 |
Correct |
726 ms |
15184 KB |
Output is correct |
47 |
Correct |
600 ms |
7768 KB |
Output is correct |
48 |
Correct |
726 ms |
15184 KB |
Output is correct |
49 |
Correct |
704 ms |
15180 KB |
Output is correct |
50 |
Correct |
747 ms |
15188 KB |
Output is correct |
51 |
Correct |
327 ms |
868 KB |
Output is correct |
52 |
Correct |
685 ms |
1368 KB |
Output is correct |
53 |
Correct |
655 ms |
1368 KB |
Output is correct |
54 |
Correct |
683 ms |
1368 KB |
Output is correct |
55 |
Correct |
731 ms |
25284 KB |
Output is correct |
56 |
Correct |
867 ms |
25424 KB |
Output is correct |
57 |
Correct |
766 ms |
25424 KB |
Output is correct |
58 |
Correct |
647 ms |
25416 KB |
Output is correct |
59 |
Correct |
822 ms |
45648 KB |
Output is correct |
60 |
Correct |
756 ms |
45632 KB |
Output is correct |
61 |
Correct |
425 ms |
1184 KB |
Output is correct |
62 |
Correct |
694 ms |
1264 KB |
Output is correct |
63 |
Correct |
663 ms |
1224 KB |
Output is correct |
64 |
Correct |
645 ms |
1836 KB |
Output is correct |
65 |
Correct |
659 ms |
1832 KB |
Output is correct |
66 |
Correct |
709 ms |
1832 KB |
Output is correct |
67 |
Correct |
680 ms |
1832 KB |
Output is correct |
68 |
Correct |
707 ms |
1840 KB |
Output is correct |
69 |
Correct |
657 ms |
1120 KB |
Output is correct |
70 |
Correct |
682 ms |
1116 KB |
Output is correct |
71 |
Correct |
594 ms |
2136 KB |
Output is correct |
72 |
Correct |
702 ms |
1824 KB |
Output is correct |
73 |
Correct |
667 ms |
1280 KB |
Output is correct |
74 |
Correct |
651 ms |
1208 KB |
Output is correct |
75 |
Correct |
688 ms |
1088 KB |
Output is correct |
76 |
Correct |
646 ms |
2648 KB |
Output is correct |
77 |
Correct |
712 ms |
2648 KB |
Output is correct |
78 |
Correct |
611 ms |
2648 KB |
Output is correct |
79 |
Correct |
639 ms |
1508 KB |
Output is correct |
80 |
Correct |
629 ms |
1156 KB |
Output is correct |
81 |
Correct |
676 ms |
1124 KB |
Output is correct |
82 |
Correct |
733 ms |
1152 KB |
Output is correct |
83 |
Correct |
344 ms |
880 KB |
Output is correct |
84 |
Correct |
676 ms |
1368 KB |
Output is correct |
85 |
Correct |
676 ms |
1620 KB |
Output is correct |
86 |
Correct |
663 ms |
1368 KB |
Output is correct |
87 |
Correct |
1 ms |
344 KB |
Output is correct |
88 |
Correct |
489 ms |
23760 KB |
Output is correct |
89 |
Correct |
756 ms |
15184 KB |
Output is correct |
90 |
Correct |
776 ms |
14948 KB |
Output is correct |
91 |
Correct |
810 ms |
25680 KB |
Output is correct |
92 |
Correct |
843 ms |
25680 KB |
Output is correct |
93 |
Correct |
826 ms |
25680 KB |
Output is correct |
94 |
Correct |
799 ms |
25680 KB |
Output is correct |
95 |
Correct |
772 ms |
25680 KB |
Output is correct |
96 |
Correct |
717 ms |
12060 KB |
Output is correct |
97 |
Correct |
727 ms |
12064 KB |
Output is correct |
98 |
Correct |
722 ms |
36684 KB |
Output is correct |
99 |
Correct |
839 ms |
25424 KB |
Output is correct |
100 |
Correct |
767 ms |
21156 KB |
Output is correct |
101 |
Correct |
757 ms |
14372 KB |
Output is correct |
102 |
Correct |
781 ms |
12368 KB |
Output is correct |
103 |
Correct |
795 ms |
45648 KB |
Output is correct |
104 |
Correct |
790 ms |
45388 KB |
Output is correct |
105 |
Correct |
727 ms |
45388 KB |
Output is correct |
106 |
Correct |
753 ms |
18768 KB |
Output is correct |
107 |
Correct |
783 ms |
13136 KB |
Output is correct |
108 |
Correct |
741 ms |
13136 KB |
Output is correct |
109 |
Correct |
790 ms |
12388 KB |
Output is correct |