답안 #642860

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
642860 2022-09-20T16:22:21 Z dykw 디지털 회로 (IOI22_circuit) C++17
100 / 100
1158 ms 42612 KB
#include <bits/stdc++.h>

using i64 = long long;

constexpr int N = 2e5 + 5, MOD = 1000002022;

int n, m, s[N];
i64 w[N], f[N], wp[N];
std::vector<int> g[N];

void calc_sum(int u) {
	if (u > n) return w[u] = 1, void();
	w[u] = g[u].size();
	for (int v : g[u]) calc_sum(v), w[u] = w[u]*w[v]%MOD;
}

void calc_coef(int u) {
	if (u > n) return;
	std::vector<i64> pre(g[u].size() + 2), suf(g[u].size() + 2);
	pre[0] = suf[g[u].size()+1] = 1;
	for (int i = 1; i <= int(g[u].size()); ++i) pre[i] = pre[i-1]*w[g[u][i-1]]%MOD;
	for (int i = int(g[u].size()); i >= 1; --i) suf[i] = suf[i+1]*w[g[u][i-1]]%MOD;
	for (int i = 0; i < int(g[u].size()); ++i)
		wp[g[u][i]] = wp[u]*pre[i]%MOD*suf[i+2]%MOD, calc_coef(g[u][i]);
}

#define ls(x) (x*2)
#define rs(x) (x*2+1)

struct {
	int l, r, ans0, ans1;
	bool tag;
} tr[N*4];

void pushup(int x) {
	tr[x].ans0 = (tr[ls(x)].ans0+tr[rs(x)].ans0)%MOD;
	tr[x].ans1 = (tr[ls(x)].ans1+tr[rs(x)].ans1)%MOD;
}

void build(int l, int r, int x = 1) {
	tr[x] = {l, r, 0, 0, false};
	if (l == r) {
		if (s[l]) tr[x].ans1 = wp[l+n];
		else tr[x].ans0 = wp[l+n];
		return;
	}
	int mid = (l+r)/2;
	build(l, mid, ls(x)), build(mid+1, r, rs(x));
	pushup(x);
}

void update(int x) {
	std::swap(tr[x].ans0, tr[x].ans1);
	tr[x].tag ^= 1;
}

void pushdown(int x) {
	if (tr[x].tag) {
		update(ls(x)), update(rs(x));
		tr[x].tag = false;
	}
}

void flip(int l, int r, int x = 1) {
	if (l <= tr[x].l && tr[x].r <= r) return update(x);
	pushdown(x);
	int mid = (tr[x].l+tr[x].r)/2;
	if (l <= mid) flip(l, r, ls(x));
	if (r > mid) flip(l, r, rs(x));
	pushup(x);
}

#undef ls
#undef rs

void init(int n, int m, std::vector<int> p, std::vector<int> a) {
	::n = n, ::m = m;
	for (int i = 1; i <= m; ++i) s[i] = a[i-1];
	for (int i = 1; i < n+m; ++i) g[p[i]+1].push_back(i+1);
	calc_sum(1);
	wp[1] = 1, calc_coef(1);
	build(1, m);
}

int count_ways(int l, int r) {
	flip(l-n+1, r-n+1);
	return tr[1].ans1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5084 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 4 ms 5328 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 5084 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 4 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 4 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 3 ms 5120 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 4 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 4 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 4 ms 5328 KB Output is correct
39 Correct 4 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 4 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 760 ms 9216 KB Output is correct
2 Correct 814 ms 13552 KB Output is correct
3 Correct 933 ms 13452 KB Output is correct
4 Correct 967 ms 13408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 760 ms 9216 KB Output is correct
2 Correct 814 ms 13552 KB Output is correct
3 Correct 933 ms 13452 KB Output is correct
4 Correct 967 ms 13408 KB Output is correct
5 Correct 748 ms 9160 KB Output is correct
6 Correct 909 ms 13384 KB Output is correct
7 Correct 1134 ms 13460 KB Output is correct
8 Correct 741 ms 13388 KB Output is correct
9 Correct 538 ms 5264 KB Output is correct
10 Correct 758 ms 5456 KB Output is correct
11 Correct 825 ms 5456 KB Output is correct
12 Correct 889 ms 5456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5084 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 4 ms 5328 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 760 ms 9216 KB Output is correct
14 Correct 814 ms 13552 KB Output is correct
15 Correct 933 ms 13452 KB Output is correct
16 Correct 967 ms 13408 KB Output is correct
17 Correct 748 ms 9160 KB Output is correct
18 Correct 909 ms 13384 KB Output is correct
19 Correct 1134 ms 13460 KB Output is correct
20 Correct 741 ms 13388 KB Output is correct
21 Correct 538 ms 5264 KB Output is correct
22 Correct 758 ms 5456 KB Output is correct
23 Correct 825 ms 5456 KB Output is correct
24 Correct 889 ms 5456 KB Output is correct
25 Correct 846 ms 18888 KB Output is correct
26 Correct 980 ms 19016 KB Output is correct
27 Correct 1049 ms 19112 KB Output is correct
28 Correct 835 ms 19100 KB Output is correct
29 Correct 1088 ms 42524 KB Output is correct
30 Correct 916 ms 42612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 5084 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 4 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 4 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 3 ms 5120 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 4 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 4 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 4 ms 5328 KB Output is correct
39 Correct 4 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 4 ms 5072 KB Output is correct
43 Correct 655 ms 5388 KB Output is correct
44 Correct 873 ms 5456 KB Output is correct
45 Correct 790 ms 5392 KB Output is correct
46 Correct 879 ms 5772 KB Output is correct
47 Correct 993 ms 5772 KB Output is correct
48 Correct 775 ms 5712 KB Output is correct
49 Correct 874 ms 5712 KB Output is correct
50 Correct 897 ms 5712 KB Output is correct
51 Correct 670 ms 5644 KB Output is correct
52 Correct 764 ms 5640 KB Output is correct
53 Correct 608 ms 6224 KB Output is correct
54 Correct 912 ms 5704 KB Output is correct
55 Correct 1027 ms 5644 KB Output is correct
56 Correct 907 ms 5512 KB Output is correct
57 Correct 758 ms 5520 KB Output is correct
58 Correct 1018 ms 6864 KB Output is correct
59 Correct 1100 ms 6864 KB Output is correct
60 Correct 958 ms 6796 KB Output is correct
61 Correct 990 ms 5640 KB Output is correct
62 Correct 903 ms 5328 KB Output is correct
63 Correct 697 ms 5328 KB Output is correct
64 Correct 913 ms 5520 KB Output is correct
65 Correct 482 ms 5200 KB Output is correct
66 Correct 782 ms 5512 KB Output is correct
67 Correct 776 ms 5520 KB Output is correct
68 Correct 765 ms 5456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 5084 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 4 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 4 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 3 ms 5120 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 4 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 4 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 4 ms 5328 KB Output is correct
39 Correct 4 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 4 ms 5072 KB Output is correct
43 Correct 760 ms 9216 KB Output is correct
44 Correct 814 ms 13552 KB Output is correct
45 Correct 933 ms 13452 KB Output is correct
46 Correct 967 ms 13408 KB Output is correct
47 Correct 748 ms 9160 KB Output is correct
48 Correct 909 ms 13384 KB Output is correct
49 Correct 1134 ms 13460 KB Output is correct
50 Correct 741 ms 13388 KB Output is correct
51 Correct 538 ms 5264 KB Output is correct
52 Correct 758 ms 5456 KB Output is correct
53 Correct 825 ms 5456 KB Output is correct
54 Correct 889 ms 5456 KB Output is correct
55 Correct 846 ms 18888 KB Output is correct
56 Correct 980 ms 19016 KB Output is correct
57 Correct 1049 ms 19112 KB Output is correct
58 Correct 835 ms 19100 KB Output is correct
59 Correct 1088 ms 42524 KB Output is correct
60 Correct 916 ms 42612 KB Output is correct
61 Correct 655 ms 5388 KB Output is correct
62 Correct 873 ms 5456 KB Output is correct
63 Correct 790 ms 5392 KB Output is correct
64 Correct 879 ms 5772 KB Output is correct
65 Correct 993 ms 5772 KB Output is correct
66 Correct 775 ms 5712 KB Output is correct
67 Correct 874 ms 5712 KB Output is correct
68 Correct 897 ms 5712 KB Output is correct
69 Correct 670 ms 5644 KB Output is correct
70 Correct 764 ms 5640 KB Output is correct
71 Correct 608 ms 6224 KB Output is correct
72 Correct 912 ms 5704 KB Output is correct
73 Correct 1027 ms 5644 KB Output is correct
74 Correct 907 ms 5512 KB Output is correct
75 Correct 758 ms 5520 KB Output is correct
76 Correct 1018 ms 6864 KB Output is correct
77 Correct 1100 ms 6864 KB Output is correct
78 Correct 958 ms 6796 KB Output is correct
79 Correct 990 ms 5640 KB Output is correct
80 Correct 903 ms 5328 KB Output is correct
81 Correct 697 ms 5328 KB Output is correct
82 Correct 913 ms 5520 KB Output is correct
83 Correct 482 ms 5200 KB Output is correct
84 Correct 782 ms 5512 KB Output is correct
85 Correct 776 ms 5520 KB Output is correct
86 Correct 765 ms 5456 KB Output is correct
87 Correct 2 ms 4944 KB Output is correct
88 Correct 571 ms 18164 KB Output is correct
89 Correct 999 ms 13512 KB Output is correct
90 Correct 872 ms 13312 KB Output is correct
91 Correct 1022 ms 19208 KB Output is correct
92 Correct 1158 ms 19204 KB Output is correct
93 Correct 1006 ms 19144 KB Output is correct
94 Correct 1038 ms 19308 KB Output is correct
95 Correct 993 ms 19316 KB Output is correct
96 Correct 934 ms 14072 KB Output is correct
97 Correct 958 ms 14116 KB Output is correct
98 Correct 733 ms 30792 KB Output is correct
99 Correct 828 ms 19076 KB Output is correct
100 Correct 872 ms 16328 KB Output is correct
101 Correct 914 ms 15488 KB Output is correct
102 Correct 874 ms 14080 KB Output is correct
103 Correct 941 ms 42500 KB Output is correct
104 Correct 826 ms 39808 KB Output is correct
105 Correct 982 ms 39820 KB Output is correct
106 Correct 1006 ms 18116 KB Output is correct
107 Correct 939 ms 14408 KB Output is correct
108 Correct 1012 ms 14560 KB Output is correct
109 Correct 997 ms 14236 KB Output is correct