Submission #990659

# Submission time Handle Problem Language Result Execution time Memory
990659 2024-05-30T23:22:32 Z aaaaaarroz Digital Circuit (IOI22_circuit) C++17
100 / 100
754 ms 42320 KB
#include "circuit.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
const ll MOD = 1e9 + 2022;
const int mxN = 1e5 + 10;
vector<int> adj[2 * mxN];
int n, m;
bool state[2 * mxN];
ll contrib[2 * mxN];
void dfs1(int u = 0) {
	if (u >= n) {
		contrib[u] = 1; return;
	}
	contrib[u] = adj[u].size();
	for (int v : adj[u]) {
		dfs1(v);
		contrib[u] = (contrib[u] * contrib[v]) % MOD;
	}
}
void dfs2(int u = 0, ll pass = 1) {
	if (u >= n) {
		contrib[u] = pass; return;
	}
	int sz = adj[u].size();
	vector<ll> pref(sz + 2), suff(sz + 2);
	pref[0] = 1;
	for (int i = 1; i <= sz; i++) {
		pref[i] = (pref[i - 1] * contrib[adj[u][i - 1]]) % MOD;
	}
	suff[sz + 1] = 1;
	for (int i = sz; i >= 1; i--) {
		suff[i] = (suff[i + 1] * contrib[adj[u][i - 1]]) % MOD;
	}
	for (int i = 1; i <= sz; i++) {
		ll nxt = pass;
		nxt = (nxt * pref[i - 1]) % MOD;
		nxt = (nxt * suff[i + 1]) % MOD;
		dfs2(adj[u][i - 1], nxt);
	}
}
ll seg[4 * mxN], tot[4 * mxN];
bool lazy[4 * mxN];
void pushdown(int idx) {
	if (!lazy[idx]) return;
	seg[(idx << 1)] = (tot[(idx << 1)] - seg[(idx << 1)] + MOD) % MOD;
	seg[(idx << 1) | 1] = (tot[(idx << 1) | 1] - seg[(idx << 1) | 1] + MOD) % MOD;
	lazy[(idx << 1)] ^= 1; lazy[(idx << 1) | 1] ^= 1;
	lazy[idx] = false;
}
void build(int l = n, int r = n + m - 1, int idx = 1) {
	if (l == r) {
		seg[idx] = (state[l] ? contrib[l] : 0LL);
		tot[idx] = contrib[l];
		return;
	}
	int mid = (l + r) >> 1;
	build(l, mid, (idx << 1));
	build(mid + 1, r, (idx << 1) | 1);
	seg[idx] = (seg[(idx << 1)] + seg[(idx << 1) | 1]) % MOD;
	tot[idx] = (tot[(idx << 1)] + tot[(idx << 1) | 1]) % MOD;
}
void update(int tl, int tr, int l = n, int r = n + m - 1, int idx = 1) {
	if (tl <= l && r <= tr) {
		seg[idx] = (tot[idx] - seg[idx] + MOD) % MOD;
		lazy[idx] ^= 1;
		return;
	}
	pushdown(idx);
	int mid = (l + r) >> 1;
	if (tl <= mid) update(tl, tr, l, mid, (idx << 1));
	if (tr > mid) update(tl, tr, mid + 1, r, (idx << 1) | 1);
	seg[idx] = (seg[(idx << 1)] + seg[(idx << 1) | 1]) % MOD;
}
ll query() {
	return seg[1];
}
void init(int N, int M, vector<int> P, vector<int> A) {
	n = N; m = M;
	for (int i = 1; i < (int)(P.size()); i++) adj[P[i]].pb(i);
	for (int i = 0; i < (int)(A.size()); i++) state[n + i] = A[i];
 
	dfs1(); dfs2();
	build();
}
int count_ways(int L, int R) {
	update(L, R);
	return (int)(query());
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Correct 2 ms 11096 KB Output is correct
3 Correct 2 ms 11352 KB Output is correct
4 Correct 2 ms 11352 KB Output is correct
5 Correct 2 ms 11352 KB Output is correct
6 Correct 2 ms 11352 KB Output is correct
7 Correct 2 ms 11352 KB Output is correct
8 Correct 2 ms 11352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Correct 2 ms 11096 KB Output is correct
3 Correct 2 ms 11352 KB Output is correct
4 Correct 2 ms 11096 KB Output is correct
5 Correct 2 ms 11352 KB Output is correct
6 Correct 2 ms 11352 KB Output is correct
7 Correct 2 ms 11352 KB Output is correct
8 Correct 2 ms 11348 KB Output is correct
9 Correct 2 ms 11352 KB Output is correct
10 Correct 2 ms 11352 KB Output is correct
11 Correct 3 ms 11352 KB Output is correct
12 Correct 2 ms 11352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Correct 2 ms 11096 KB Output is correct
3 Correct 2 ms 11352 KB Output is correct
4 Correct 2 ms 11352 KB Output is correct
5 Correct 2 ms 11352 KB Output is correct
6 Correct 2 ms 11352 KB Output is correct
7 Correct 2 ms 11352 KB Output is correct
8 Correct 2 ms 11352 KB Output is correct
9 Correct 2 ms 11096 KB Output is correct
10 Correct 2 ms 11096 KB Output is correct
11 Correct 2 ms 11352 KB Output is correct
12 Correct 2 ms 11096 KB Output is correct
13 Correct 2 ms 11352 KB Output is correct
14 Correct 2 ms 11352 KB Output is correct
15 Correct 2 ms 11352 KB Output is correct
16 Correct 2 ms 11348 KB Output is correct
17 Correct 2 ms 11352 KB Output is correct
18 Correct 2 ms 11352 KB Output is correct
19 Correct 3 ms 11352 KB Output is correct
20 Correct 2 ms 11352 KB Output is correct
21 Correct 2 ms 11352 KB Output is correct
22 Correct 2 ms 11352 KB Output is correct
23 Correct 2 ms 11352 KB Output is correct
24 Correct 2 ms 11352 KB Output is correct
25 Correct 2 ms 11352 KB Output is correct
26 Correct 2 ms 11352 KB Output is correct
27 Correct 2 ms 11352 KB Output is correct
28 Correct 2 ms 11352 KB Output is correct
29 Correct 2 ms 11352 KB Output is correct
30 Correct 2 ms 11352 KB Output is correct
31 Correct 2 ms 11352 KB Output is correct
32 Correct 2 ms 11352 KB Output is correct
33 Correct 2 ms 11352 KB Output is correct
34 Correct 2 ms 11352 KB Output is correct
35 Correct 2 ms 11352 KB Output is correct
36 Correct 2 ms 11608 KB Output is correct
37 Correct 2 ms 11352 KB Output is correct
38 Correct 2 ms 11352 KB Output is correct
39 Correct 2 ms 11348 KB Output is correct
40 Correct 3 ms 11096 KB Output is correct
41 Correct 2 ms 11352 KB Output is correct
42 Correct 2 ms 11096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 476 ms 12888 KB Output is correct
2 Correct 631 ms 16720 KB Output is correct
3 Correct 701 ms 16728 KB Output is correct
4 Correct 644 ms 16984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 476 ms 12888 KB Output is correct
2 Correct 631 ms 16720 KB Output is correct
3 Correct 701 ms 16728 KB Output is correct
4 Correct 644 ms 16984 KB Output is correct
5 Correct 541 ms 13144 KB Output is correct
6 Correct 694 ms 16984 KB Output is correct
7 Correct 673 ms 16980 KB Output is correct
8 Correct 655 ms 16988 KB Output is correct
9 Correct 318 ms 11352 KB Output is correct
10 Correct 605 ms 11352 KB Output is correct
11 Correct 696 ms 11352 KB Output is correct
12 Correct 616 ms 11352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Correct 2 ms 11096 KB Output is correct
3 Correct 2 ms 11352 KB Output is correct
4 Correct 2 ms 11096 KB Output is correct
5 Correct 2 ms 11352 KB Output is correct
6 Correct 2 ms 11352 KB Output is correct
7 Correct 2 ms 11352 KB Output is correct
8 Correct 2 ms 11348 KB Output is correct
9 Correct 2 ms 11352 KB Output is correct
10 Correct 2 ms 11352 KB Output is correct
11 Correct 3 ms 11352 KB Output is correct
12 Correct 2 ms 11352 KB Output is correct
13 Correct 476 ms 12888 KB Output is correct
14 Correct 631 ms 16720 KB Output is correct
15 Correct 701 ms 16728 KB Output is correct
16 Correct 644 ms 16984 KB Output is correct
17 Correct 541 ms 13144 KB Output is correct
18 Correct 694 ms 16984 KB Output is correct
19 Correct 673 ms 16980 KB Output is correct
20 Correct 655 ms 16988 KB Output is correct
21 Correct 318 ms 11352 KB Output is correct
22 Correct 605 ms 11352 KB Output is correct
23 Correct 696 ms 11352 KB Output is correct
24 Correct 616 ms 11352 KB Output is correct
25 Correct 695 ms 18512 KB Output is correct
26 Correct 727 ms 18768 KB Output is correct
27 Correct 697 ms 18628 KB Output is correct
28 Correct 567 ms 18768 KB Output is correct
29 Correct 713 ms 42184 KB Output is correct
30 Correct 673 ms 42280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Correct 2 ms 11096 KB Output is correct
3 Correct 2 ms 11352 KB Output is correct
4 Correct 2 ms 11352 KB Output is correct
5 Correct 2 ms 11352 KB Output is correct
6 Correct 2 ms 11352 KB Output is correct
7 Correct 2 ms 11352 KB Output is correct
8 Correct 2 ms 11352 KB Output is correct
9 Correct 2 ms 11096 KB Output is correct
10 Correct 2 ms 11096 KB Output is correct
11 Correct 2 ms 11352 KB Output is correct
12 Correct 2 ms 11096 KB Output is correct
13 Correct 2 ms 11352 KB Output is correct
14 Correct 2 ms 11352 KB Output is correct
15 Correct 2 ms 11352 KB Output is correct
16 Correct 2 ms 11348 KB Output is correct
17 Correct 2 ms 11352 KB Output is correct
18 Correct 2 ms 11352 KB Output is correct
19 Correct 3 ms 11352 KB Output is correct
20 Correct 2 ms 11352 KB Output is correct
21 Correct 2 ms 11352 KB Output is correct
22 Correct 2 ms 11352 KB Output is correct
23 Correct 2 ms 11352 KB Output is correct
24 Correct 2 ms 11352 KB Output is correct
25 Correct 2 ms 11352 KB Output is correct
26 Correct 2 ms 11352 KB Output is correct
27 Correct 2 ms 11352 KB Output is correct
28 Correct 2 ms 11352 KB Output is correct
29 Correct 2 ms 11352 KB Output is correct
30 Correct 2 ms 11352 KB Output is correct
31 Correct 2 ms 11352 KB Output is correct
32 Correct 2 ms 11352 KB Output is correct
33 Correct 2 ms 11352 KB Output is correct
34 Correct 2 ms 11352 KB Output is correct
35 Correct 2 ms 11352 KB Output is correct
36 Correct 2 ms 11608 KB Output is correct
37 Correct 2 ms 11352 KB Output is correct
38 Correct 2 ms 11352 KB Output is correct
39 Correct 2 ms 11348 KB Output is correct
40 Correct 3 ms 11096 KB Output is correct
41 Correct 2 ms 11352 KB Output is correct
42 Correct 2 ms 11096 KB Output is correct
43 Correct 443 ms 11352 KB Output is correct
44 Correct 669 ms 11352 KB Output is correct
45 Correct 638 ms 11352 KB Output is correct
46 Correct 654 ms 11608 KB Output is correct
47 Correct 637 ms 11608 KB Output is correct
48 Correct 623 ms 11860 KB Output is correct
49 Correct 629 ms 11608 KB Output is correct
50 Correct 681 ms 11608 KB Output is correct
51 Correct 608 ms 11520 KB Output is correct
52 Correct 657 ms 11532 KB Output is correct
53 Correct 519 ms 12376 KB Output is correct
54 Correct 667 ms 11608 KB Output is correct
55 Correct 640 ms 11352 KB Output is correct
56 Correct 612 ms 11352 KB Output is correct
57 Correct 612 ms 11348 KB Output is correct
58 Correct 646 ms 12632 KB Output is correct
59 Correct 651 ms 12632 KB Output is correct
60 Correct 623 ms 12632 KB Output is correct
61 Correct 628 ms 11608 KB Output is correct
62 Correct 598 ms 11352 KB Output is correct
63 Correct 645 ms 11352 KB Output is correct
64 Correct 605 ms 11352 KB Output is correct
65 Correct 321 ms 11352 KB Output is correct
66 Correct 627 ms 11352 KB Output is correct
67 Correct 633 ms 11352 KB Output is correct
68 Correct 668 ms 11352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Correct 2 ms 11096 KB Output is correct
3 Correct 2 ms 11352 KB Output is correct
4 Correct 2 ms 11352 KB Output is correct
5 Correct 2 ms 11352 KB Output is correct
6 Correct 2 ms 11352 KB Output is correct
7 Correct 2 ms 11352 KB Output is correct
8 Correct 2 ms 11352 KB Output is correct
9 Correct 2 ms 11096 KB Output is correct
10 Correct 2 ms 11096 KB Output is correct
11 Correct 2 ms 11352 KB Output is correct
12 Correct 2 ms 11096 KB Output is correct
13 Correct 2 ms 11352 KB Output is correct
14 Correct 2 ms 11352 KB Output is correct
15 Correct 2 ms 11352 KB Output is correct
16 Correct 2 ms 11348 KB Output is correct
17 Correct 2 ms 11352 KB Output is correct
18 Correct 2 ms 11352 KB Output is correct
19 Correct 3 ms 11352 KB Output is correct
20 Correct 2 ms 11352 KB Output is correct
21 Correct 2 ms 11352 KB Output is correct
22 Correct 2 ms 11352 KB Output is correct
23 Correct 2 ms 11352 KB Output is correct
24 Correct 2 ms 11352 KB Output is correct
25 Correct 2 ms 11352 KB Output is correct
26 Correct 2 ms 11352 KB Output is correct
27 Correct 2 ms 11352 KB Output is correct
28 Correct 2 ms 11352 KB Output is correct
29 Correct 2 ms 11352 KB Output is correct
30 Correct 2 ms 11352 KB Output is correct
31 Correct 2 ms 11352 KB Output is correct
32 Correct 2 ms 11352 KB Output is correct
33 Correct 2 ms 11352 KB Output is correct
34 Correct 2 ms 11352 KB Output is correct
35 Correct 2 ms 11352 KB Output is correct
36 Correct 2 ms 11608 KB Output is correct
37 Correct 2 ms 11352 KB Output is correct
38 Correct 2 ms 11352 KB Output is correct
39 Correct 2 ms 11348 KB Output is correct
40 Correct 3 ms 11096 KB Output is correct
41 Correct 2 ms 11352 KB Output is correct
42 Correct 2 ms 11096 KB Output is correct
43 Correct 476 ms 12888 KB Output is correct
44 Correct 631 ms 16720 KB Output is correct
45 Correct 701 ms 16728 KB Output is correct
46 Correct 644 ms 16984 KB Output is correct
47 Correct 541 ms 13144 KB Output is correct
48 Correct 694 ms 16984 KB Output is correct
49 Correct 673 ms 16980 KB Output is correct
50 Correct 655 ms 16988 KB Output is correct
51 Correct 318 ms 11352 KB Output is correct
52 Correct 605 ms 11352 KB Output is correct
53 Correct 696 ms 11352 KB Output is correct
54 Correct 616 ms 11352 KB Output is correct
55 Correct 695 ms 18512 KB Output is correct
56 Correct 727 ms 18768 KB Output is correct
57 Correct 697 ms 18628 KB Output is correct
58 Correct 567 ms 18768 KB Output is correct
59 Correct 713 ms 42184 KB Output is correct
60 Correct 673 ms 42280 KB Output is correct
61 Correct 443 ms 11352 KB Output is correct
62 Correct 669 ms 11352 KB Output is correct
63 Correct 638 ms 11352 KB Output is correct
64 Correct 654 ms 11608 KB Output is correct
65 Correct 637 ms 11608 KB Output is correct
66 Correct 623 ms 11860 KB Output is correct
67 Correct 629 ms 11608 KB Output is correct
68 Correct 681 ms 11608 KB Output is correct
69 Correct 608 ms 11520 KB Output is correct
70 Correct 657 ms 11532 KB Output is correct
71 Correct 519 ms 12376 KB Output is correct
72 Correct 667 ms 11608 KB Output is correct
73 Correct 640 ms 11352 KB Output is correct
74 Correct 612 ms 11352 KB Output is correct
75 Correct 612 ms 11348 KB Output is correct
76 Correct 646 ms 12632 KB Output is correct
77 Correct 651 ms 12632 KB Output is correct
78 Correct 623 ms 12632 KB Output is correct
79 Correct 628 ms 11608 KB Output is correct
80 Correct 598 ms 11352 KB Output is correct
81 Correct 645 ms 11352 KB Output is correct
82 Correct 605 ms 11352 KB Output is correct
83 Correct 321 ms 11352 KB Output is correct
84 Correct 627 ms 11352 KB Output is correct
85 Correct 633 ms 11352 KB Output is correct
86 Correct 668 ms 11352 KB Output is correct
87 Correct 2 ms 11096 KB Output is correct
88 Correct 402 ms 18204 KB Output is correct
89 Correct 742 ms 17124 KB Output is correct
90 Correct 694 ms 16720 KB Output is correct
91 Correct 702 ms 18896 KB Output is correct
92 Correct 727 ms 18768 KB Output is correct
93 Correct 672 ms 18720 KB Output is correct
94 Correct 754 ms 18768 KB Output is correct
95 Correct 673 ms 18764 KB Output is correct
96 Correct 621 ms 15280 KB Output is correct
97 Correct 744 ms 15272 KB Output is correct
98 Correct 557 ms 35408 KB Output is correct
99 Correct 703 ms 18612 KB Output is correct
100 Correct 702 ms 16728 KB Output is correct
101 Correct 701 ms 16208 KB Output is correct
102 Correct 671 ms 15448 KB Output is correct
103 Correct 702 ms 42320 KB Output is correct
104 Correct 716 ms 39344 KB Output is correct
105 Correct 679 ms 39344 KB Output is correct
106 Correct 680 ms 21840 KB Output is correct
107 Correct 622 ms 15800 KB Output is correct
108 Correct 705 ms 15696 KB Output is correct
109 Correct 642 ms 15448 KB Output is correct