답안 #770853

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
770853 2023-07-02T04:27:42 Z josanneo22 디지털 회로 (IOI22_circuit) C++17
100 / 100
956 ms 43720 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 1, MOD = 1e9 + 2022;
class SegmentTree {
private:
	struct node {
		int rev, sum[2];
		node() { rev = 0, sum[0] = sum[1] = 0; }
	}tree[maxn << 2];

	inline int left(int x) { return x << 1; }
	inline int right(int x) { return x << 1 | 1; }
	inline void pushup(int pos) {
		tree[pos].sum[0] = (tree[left(pos)].sum[0] + tree[right(pos)].sum[0]) % MOD;
		tree[pos].sum[1] = (tree[left(pos)].sum[1] + tree[right(pos)].sum[1]) % MOD;
	}
	inline void reverse(int pos) {
		tree[pos].rev ^= 1;
		swap(tree[pos].sum[0], tree[pos].sum[1]);
	}
	inline void pushdown(int pos) {
		if (tree[pos].rev) {
			reverse(left(pos));
			reverse(right(pos));
			tree[pos].rev = 0;
		}
	}
public:
	inline void Insert(int u, int s, int k, int l, int r, int pos) {
		tree[pos] = node();
		if (l == r) {
			tree[pos].sum[s] = k;
			return;
		}
		int mid = (l + r) >> 1;
		if (u <= mid) Insert(u, s, k, l, mid, left(pos));
		if (mid < u) Insert(u, s, k, mid + 1, r, right(pos));
		pushup(pos);
	}
	inline void Modify(int ul, int ur, int l, int r, int pos) {
		if (ul <= l && r <= ur) {
			reverse(pos);
			return;
		}
		int mid = (l + r) >> 1;
		pushdown(pos);
		if (ul <= mid) Modify(ul, ur, l, mid, left(pos));
		if (mid < ur) Modify(ul, ur, mid + 1, r, right(pos));
		pushup(pos);
	}
	inline int Query() { return tree[1].sum[1]; }
}S;

vector<int> G[maxn];
int n, m, siz[maxn], coef[maxn], prod[maxn];
inline void dfs1(int u) {
	if (!siz[u]) {
		prod[u] = 1; return;
	}
	prod[u] = siz[u];
	for (int v : G[u]) {
		dfs1(v);
		prod[u] = (ll)prod[v] * (ll)prod[u] % MOD;
	}
}
inline void dfs2(int u, int k) {
	coef[u] = k;

	if (!siz[u]) return;
	vector <int> pre(siz[u]), suf(siz[u]);

	pre[0] = prod[G[u][0]];
	for (int i = 1; i <= siz[u] - 1; ++i) pre[i] = (ll)prod[G[u][i]] * (ll)pre[i - 1] % MOD;

	suf[siz[u] - 1] = prod[G[u][siz[u] - 1]];
	for (int i = siz[u] - 2; i >= 0; --i) suf[i] = (ll)prod[G[u][i]] * (ll)suf[i + 1] % MOD;

	for (int i = 0; i < siz[u]; ++i) {
		int tmp = k;
		if (i > 0) tmp = (ll)tmp * (ll)pre[i - 1] % MOD;
		if (i < siz[u] - 1) tmp = (ll)tmp * (ll)suf[i + 1] % MOD;
		dfs2(G[u][i], tmp);
	}
}
void init(int N, int M, vector <int> P, vector <int> A) {
	n = N, m = M;
	for (int i = 1; i < n + m; ++i) G[P[i]].push_back(i);
	for (int i = 0; i < n + m; ++i) siz[i] = G[i].size();
	dfs1(0), dfs2(0, 1);
	for (int i = 0; i < m; ++i) S.Insert(i + 1, A[i], coef[n + i], 1, m, 1);
}
int count_ways(int L, int R) {
	S.Modify(L - n + 1, R - n + 1, 1, m, 1);
	return S.Query();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14288 KB Output is correct
2 Correct 7 ms 14288 KB Output is correct
3 Correct 7 ms 14352 KB Output is correct
4 Correct 6 ms 14416 KB Output is correct
5 Correct 6 ms 14416 KB Output is correct
6 Correct 6 ms 14416 KB Output is correct
7 Correct 6 ms 14416 KB Output is correct
8 Correct 6 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14288 KB Output is correct
2 Correct 6 ms 14416 KB Output is correct
3 Correct 7 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 6 ms 14372 KB Output is correct
6 Correct 6 ms 14416 KB Output is correct
7 Correct 6 ms 14416 KB Output is correct
8 Correct 6 ms 14416 KB Output is correct
9 Correct 6 ms 14416 KB Output is correct
10 Correct 6 ms 14672 KB Output is correct
11 Correct 7 ms 14580 KB Output is correct
12 Correct 7 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14288 KB Output is correct
2 Correct 7 ms 14288 KB Output is correct
3 Correct 7 ms 14352 KB Output is correct
4 Correct 6 ms 14416 KB Output is correct
5 Correct 6 ms 14416 KB Output is correct
6 Correct 6 ms 14416 KB Output is correct
7 Correct 6 ms 14416 KB Output is correct
8 Correct 6 ms 14416 KB Output is correct
9 Correct 5 ms 14288 KB Output is correct
10 Correct 6 ms 14416 KB Output is correct
11 Correct 7 ms 14416 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
13 Correct 6 ms 14372 KB Output is correct
14 Correct 6 ms 14416 KB Output is correct
15 Correct 6 ms 14416 KB Output is correct
16 Correct 6 ms 14416 KB Output is correct
17 Correct 6 ms 14416 KB Output is correct
18 Correct 6 ms 14672 KB Output is correct
19 Correct 7 ms 14580 KB Output is correct
20 Correct 7 ms 14428 KB Output is correct
21 Correct 7 ms 14416 KB Output is correct
22 Correct 6 ms 14416 KB Output is correct
23 Correct 6 ms 14416 KB Output is correct
24 Correct 6 ms 14416 KB Output is correct
25 Correct 6 ms 14416 KB Output is correct
26 Correct 7 ms 14416 KB Output is correct
27 Correct 6 ms 14416 KB Output is correct
28 Correct 7 ms 14416 KB Output is correct
29 Correct 6 ms 14416 KB Output is correct
30 Correct 6 ms 14416 KB Output is correct
31 Correct 6 ms 14544 KB Output is correct
32 Correct 6 ms 14472 KB Output is correct
33 Correct 6 ms 14416 KB Output is correct
34 Correct 7 ms 14416 KB Output is correct
35 Correct 6 ms 14416 KB Output is correct
36 Correct 6 ms 14672 KB Output is correct
37 Correct 7 ms 14672 KB Output is correct
38 Correct 7 ms 14688 KB Output is correct
39 Correct 6 ms 14448 KB Output is correct
40 Correct 6 ms 14416 KB Output is correct
41 Correct 7 ms 14372 KB Output is correct
42 Correct 6 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 579 ms 16936 KB Output is correct
2 Correct 776 ms 19400 KB Output is correct
3 Correct 850 ms 19400 KB Output is correct
4 Correct 764 ms 19504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 579 ms 16936 KB Output is correct
2 Correct 776 ms 19400 KB Output is correct
3 Correct 850 ms 19400 KB Output is correct
4 Correct 764 ms 19504 KB Output is correct
5 Correct 565 ms 16932 KB Output is correct
6 Correct 797 ms 19528 KB Output is correct
7 Correct 776 ms 19500 KB Output is correct
8 Correct 730 ms 19500 KB Output is correct
9 Correct 413 ms 14544 KB Output is correct
10 Correct 601 ms 14640 KB Output is correct
11 Correct 759 ms 14640 KB Output is correct
12 Correct 604 ms 14620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14288 KB Output is correct
2 Correct 6 ms 14416 KB Output is correct
3 Correct 7 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 6 ms 14372 KB Output is correct
6 Correct 6 ms 14416 KB Output is correct
7 Correct 6 ms 14416 KB Output is correct
8 Correct 6 ms 14416 KB Output is correct
9 Correct 6 ms 14416 KB Output is correct
10 Correct 6 ms 14672 KB Output is correct
11 Correct 7 ms 14580 KB Output is correct
12 Correct 7 ms 14428 KB Output is correct
13 Correct 579 ms 16936 KB Output is correct
14 Correct 776 ms 19400 KB Output is correct
15 Correct 850 ms 19400 KB Output is correct
16 Correct 764 ms 19504 KB Output is correct
17 Correct 565 ms 16932 KB Output is correct
18 Correct 797 ms 19528 KB Output is correct
19 Correct 776 ms 19500 KB Output is correct
20 Correct 730 ms 19500 KB Output is correct
21 Correct 413 ms 14544 KB Output is correct
22 Correct 601 ms 14640 KB Output is correct
23 Correct 759 ms 14640 KB Output is correct
24 Correct 604 ms 14620 KB Output is correct
25 Correct 956 ms 22072 KB Output is correct
26 Correct 671 ms 22188 KB Output is correct
27 Correct 927 ms 22216 KB Output is correct
28 Correct 651 ms 22172 KB Output is correct
29 Correct 891 ms 42440 KB Output is correct
30 Correct 713 ms 42440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14288 KB Output is correct
2 Correct 7 ms 14288 KB Output is correct
3 Correct 7 ms 14352 KB Output is correct
4 Correct 6 ms 14416 KB Output is correct
5 Correct 6 ms 14416 KB Output is correct
6 Correct 6 ms 14416 KB Output is correct
7 Correct 6 ms 14416 KB Output is correct
8 Correct 6 ms 14416 KB Output is correct
9 Correct 5 ms 14288 KB Output is correct
10 Correct 6 ms 14416 KB Output is correct
11 Correct 7 ms 14416 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
13 Correct 6 ms 14372 KB Output is correct
14 Correct 6 ms 14416 KB Output is correct
15 Correct 6 ms 14416 KB Output is correct
16 Correct 6 ms 14416 KB Output is correct
17 Correct 6 ms 14416 KB Output is correct
18 Correct 6 ms 14672 KB Output is correct
19 Correct 7 ms 14580 KB Output is correct
20 Correct 7 ms 14428 KB Output is correct
21 Correct 7 ms 14416 KB Output is correct
22 Correct 6 ms 14416 KB Output is correct
23 Correct 6 ms 14416 KB Output is correct
24 Correct 6 ms 14416 KB Output is correct
25 Correct 6 ms 14416 KB Output is correct
26 Correct 7 ms 14416 KB Output is correct
27 Correct 6 ms 14416 KB Output is correct
28 Correct 7 ms 14416 KB Output is correct
29 Correct 6 ms 14416 KB Output is correct
30 Correct 6 ms 14416 KB Output is correct
31 Correct 6 ms 14544 KB Output is correct
32 Correct 6 ms 14472 KB Output is correct
33 Correct 6 ms 14416 KB Output is correct
34 Correct 7 ms 14416 KB Output is correct
35 Correct 6 ms 14416 KB Output is correct
36 Correct 6 ms 14672 KB Output is correct
37 Correct 7 ms 14672 KB Output is correct
38 Correct 7 ms 14688 KB Output is correct
39 Correct 6 ms 14448 KB Output is correct
40 Correct 6 ms 14416 KB Output is correct
41 Correct 7 ms 14372 KB Output is correct
42 Correct 6 ms 14416 KB Output is correct
43 Correct 492 ms 14556 KB Output is correct
44 Correct 759 ms 14632 KB Output is correct
45 Correct 730 ms 14504 KB Output is correct
46 Correct 715 ms 14760 KB Output is correct
47 Correct 714 ms 14772 KB Output is correct
48 Correct 735 ms 14672 KB Output is correct
49 Correct 792 ms 14772 KB Output is correct
50 Correct 703 ms 14692 KB Output is correct
51 Correct 604 ms 14524 KB Output is correct
52 Correct 802 ms 14512 KB Output is correct
53 Correct 778 ms 15664 KB Output is correct
54 Correct 778 ms 14772 KB Output is correct
55 Correct 670 ms 14672 KB Output is correct
56 Correct 750 ms 14628 KB Output is correct
57 Correct 685 ms 14516 KB Output is correct
58 Correct 814 ms 15800 KB Output is correct
59 Correct 723 ms 15776 KB Output is correct
60 Correct 671 ms 15824 KB Output is correct
61 Correct 808 ms 14768 KB Output is correct
62 Correct 627 ms 14520 KB Output is correct
63 Correct 637 ms 14544 KB Output is correct
64 Correct 715 ms 14512 KB Output is correct
65 Correct 335 ms 14544 KB Output is correct
66 Correct 737 ms 14632 KB Output is correct
67 Correct 740 ms 14664 KB Output is correct
68 Correct 741 ms 14672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14288 KB Output is correct
2 Correct 7 ms 14288 KB Output is correct
3 Correct 7 ms 14352 KB Output is correct
4 Correct 6 ms 14416 KB Output is correct
5 Correct 6 ms 14416 KB Output is correct
6 Correct 6 ms 14416 KB Output is correct
7 Correct 6 ms 14416 KB Output is correct
8 Correct 6 ms 14416 KB Output is correct
9 Correct 5 ms 14288 KB Output is correct
10 Correct 6 ms 14416 KB Output is correct
11 Correct 7 ms 14416 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
13 Correct 6 ms 14372 KB Output is correct
14 Correct 6 ms 14416 KB Output is correct
15 Correct 6 ms 14416 KB Output is correct
16 Correct 6 ms 14416 KB Output is correct
17 Correct 6 ms 14416 KB Output is correct
18 Correct 6 ms 14672 KB Output is correct
19 Correct 7 ms 14580 KB Output is correct
20 Correct 7 ms 14428 KB Output is correct
21 Correct 7 ms 14416 KB Output is correct
22 Correct 6 ms 14416 KB Output is correct
23 Correct 6 ms 14416 KB Output is correct
24 Correct 6 ms 14416 KB Output is correct
25 Correct 6 ms 14416 KB Output is correct
26 Correct 7 ms 14416 KB Output is correct
27 Correct 6 ms 14416 KB Output is correct
28 Correct 7 ms 14416 KB Output is correct
29 Correct 6 ms 14416 KB Output is correct
30 Correct 6 ms 14416 KB Output is correct
31 Correct 6 ms 14544 KB Output is correct
32 Correct 6 ms 14472 KB Output is correct
33 Correct 6 ms 14416 KB Output is correct
34 Correct 7 ms 14416 KB Output is correct
35 Correct 6 ms 14416 KB Output is correct
36 Correct 6 ms 14672 KB Output is correct
37 Correct 7 ms 14672 KB Output is correct
38 Correct 7 ms 14688 KB Output is correct
39 Correct 6 ms 14448 KB Output is correct
40 Correct 6 ms 14416 KB Output is correct
41 Correct 7 ms 14372 KB Output is correct
42 Correct 6 ms 14416 KB Output is correct
43 Correct 579 ms 16936 KB Output is correct
44 Correct 776 ms 19400 KB Output is correct
45 Correct 850 ms 19400 KB Output is correct
46 Correct 764 ms 19504 KB Output is correct
47 Correct 565 ms 16932 KB Output is correct
48 Correct 797 ms 19528 KB Output is correct
49 Correct 776 ms 19500 KB Output is correct
50 Correct 730 ms 19500 KB Output is correct
51 Correct 413 ms 14544 KB Output is correct
52 Correct 601 ms 14640 KB Output is correct
53 Correct 759 ms 14640 KB Output is correct
54 Correct 604 ms 14620 KB Output is correct
55 Correct 956 ms 22072 KB Output is correct
56 Correct 671 ms 22188 KB Output is correct
57 Correct 927 ms 22216 KB Output is correct
58 Correct 651 ms 22172 KB Output is correct
59 Correct 891 ms 42440 KB Output is correct
60 Correct 713 ms 42440 KB Output is correct
61 Correct 492 ms 14556 KB Output is correct
62 Correct 759 ms 14632 KB Output is correct
63 Correct 730 ms 14504 KB Output is correct
64 Correct 715 ms 14760 KB Output is correct
65 Correct 714 ms 14772 KB Output is correct
66 Correct 735 ms 14672 KB Output is correct
67 Correct 792 ms 14772 KB Output is correct
68 Correct 703 ms 14692 KB Output is correct
69 Correct 604 ms 14524 KB Output is correct
70 Correct 802 ms 14512 KB Output is correct
71 Correct 778 ms 15664 KB Output is correct
72 Correct 778 ms 14772 KB Output is correct
73 Correct 670 ms 14672 KB Output is correct
74 Correct 750 ms 14628 KB Output is correct
75 Correct 685 ms 14516 KB Output is correct
76 Correct 814 ms 15800 KB Output is correct
77 Correct 723 ms 15776 KB Output is correct
78 Correct 671 ms 15824 KB Output is correct
79 Correct 808 ms 14768 KB Output is correct
80 Correct 627 ms 14520 KB Output is correct
81 Correct 637 ms 14544 KB Output is correct
82 Correct 715 ms 14512 KB Output is correct
83 Correct 335 ms 14544 KB Output is correct
84 Correct 737 ms 14632 KB Output is correct
85 Correct 740 ms 14664 KB Output is correct
86 Correct 741 ms 14672 KB Output is correct
87 Correct 7 ms 14288 KB Output is correct
88 Correct 497 ms 21424 KB Output is correct
89 Correct 845 ms 19684 KB Output is correct
90 Correct 706 ms 19400 KB Output is correct
91 Correct 857 ms 22324 KB Output is correct
92 Correct 817 ms 22304 KB Output is correct
93 Correct 745 ms 22312 KB Output is correct
94 Correct 754 ms 22304 KB Output is correct
95 Correct 748 ms 22212 KB Output is correct
96 Correct 654 ms 18368 KB Output is correct
97 Correct 759 ms 18336 KB Output is correct
98 Correct 792 ms 39800 KB Output is correct
99 Correct 713 ms 22212 KB Output is correct
100 Correct 728 ms 19632 KB Output is correct
101 Correct 828 ms 18976 KB Output is correct
102 Correct 711 ms 17608 KB Output is correct
103 Correct 784 ms 42440 KB Output is correct
104 Correct 794 ms 43692 KB Output is correct
105 Correct 824 ms 43720 KB Output is correct
106 Correct 665 ms 23880 KB Output is correct
107 Correct 809 ms 18264 KB Output is correct
108 Correct 840 ms 18088 KB Output is correct
109 Correct 830 ms 17736 KB Output is correct