Submission #1025274

# Submission time Handle Problem Language Result Execution time Memory
1025274 2024-07-16T19:00:45 Z Issa Digital Circuit (IOI22_circuit) C++17
100 / 100
821 ms 26220 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<int, int> pii;

const int MOD = 1000002022;
const int maxn = 2e5 + 100;

int n, k;
int p[maxn];
vector<int> g[maxn];
int a[maxn];
int t[maxn * 4];
ll sum[maxn];
ll d[2][maxn * 4];
ll dp[maxn];

void pre(int v){
	swap(d[0][v], d[1][v]);
	t[v] ^= 1;
}

void push(int v, int tl, int tr){
	if(tl == tr || !t[v]) return;
	t[v] = 0; pre(v<<1); pre(v<<1|1);
}

void build(int v = 1, int tl = k + 1, int tr = n){
	if(tl == tr){
		d[a[tl]][v] = dp[tl];
	} else{
		int mid = (tl + tr) >> 1;
		build(v<<1, tl, mid);
		build(v<<1|1, mid+1, tr);
		d[0][v] = (d[0][v<<1] + d[0][v<<1|1]) % MOD;
		d[1][v] = (d[1][v<<1] + d[1][v<<1|1]) % MOD;
	}
}

void upd(int l, int r, int v = 1, int tl = k + 1, int tr = n){
	push(v, tl, tr);
	if(tl > r || tr < l) return;
	if(l <= tl && tr <= r) pre(v);
	else{
		int mid = (tl + tr) >> 1;
		upd(l, r, v<<1, tl, mid);
		upd(l, r, v<<1|1, mid+1, tr);
		d[0][v] = (d[0][v<<1] + d[0][v<<1|1]) % MOD;
		d[1][v] = (d[1][v<<1] + d[1][v<<1|1]) % MOD;
	}
}

void init(int N, int M, std::vector<int> P, std::vector<int> A){
	n = N + M; k = N;
	for(int i = 1; i <= n; i++){
		p[i] = P[i-1]; p[i]++;
		g[p[i]].push_back(i);
		dp[i] = 1;
	}
	for(int v = n; v > 0; v--){
		sum[v] = 1;
		for(int to: g[v]){
			sum[v] = sum[v] * sum[to] % MOD;
		}
		if(v <= k) sum[v] = sum[v] * (ll)g[v].size() % MOD;
	}
	for(int i = k + 1; i <= n; i++){
		a[i] = A[i - k - 1];
	}
	for(int v = 1; v <= k; v++){
		ll d = 1;
		for(int to: g[v]){
			dp[to] = dp[v];
			dp[to] = dp[to] * d % MOD;
			d = d * sum[to] % MOD;
		}
		d = 1;
		reverse(g[v].begin(), g[v].end());
		for(int to: g[v]){
			dp[to] = dp[to] * d % MOD;
			d = d * sum[to] % MOD;
		}
	}
	build();
}

int count_ways(int L, int R){
	upd(L + 1, R + 1);
	return d[1][1];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 10580 KB Output is correct
5 Correct 2 ms 10584 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 2 ms 10584 KB Output is correct
8 Correct 2 ms 12764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 10584 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 1 ms 10684 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 ms 12632 KB Output is correct
9 Correct 2 ms 12632 KB Output is correct
10 Correct 2 ms 12632 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 2 ms 10756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 10580 KB Output is correct
5 Correct 2 ms 10584 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 2 ms 10584 KB Output is correct
8 Correct 2 ms 12764 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 12632 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 1 ms 10684 KB Output is correct
14 Correct 2 ms 10584 KB Output is correct
15 Correct 2 ms 12632 KB Output is correct
16 Correct 2 ms 12632 KB Output is correct
17 Correct 2 ms 12632 KB Output is correct
18 Correct 2 ms 12632 KB Output is correct
19 Correct 2 ms 10584 KB Output is correct
20 Correct 2 ms 10756 KB Output is correct
21 Correct 2 ms 10580 KB Output is correct
22 Correct 2 ms 12632 KB Output is correct
23 Correct 2 ms 12632 KB Output is correct
24 Correct 3 ms 12804 KB Output is correct
25 Correct 2 ms 10584 KB Output is correct
26 Correct 2 ms 10584 KB Output is correct
27 Correct 2 ms 10584 KB Output is correct
28 Correct 3 ms 12724 KB Output is correct
29 Correct 2 ms 12632 KB Output is correct
30 Correct 2 ms 12632 KB Output is correct
31 Correct 2 ms 12632 KB Output is correct
32 Correct 2 ms 10584 KB Output is correct
33 Correct 2 ms 10584 KB Output is correct
34 Correct 2 ms 10584 KB Output is correct
35 Correct 2 ms 10584 KB Output is correct
36 Correct 2 ms 10584 KB Output is correct
37 Correct 2 ms 10584 KB Output is correct
38 Correct 3 ms 12632 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 2 ms 12632 KB Output is correct
41 Correct 2 ms 12632 KB Output is correct
42 Correct 1 ms 10584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 478 ms 15192 KB Output is correct
2 Correct 663 ms 22616 KB Output is correct
3 Correct 621 ms 20568 KB Output is correct
4 Correct 695 ms 18844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 478 ms 15192 KB Output is correct
2 Correct 663 ms 22616 KB Output is correct
3 Correct 621 ms 20568 KB Output is correct
4 Correct 695 ms 18844 KB Output is correct
5 Correct 538 ms 16720 KB Output is correct
6 Correct 682 ms 22616 KB Output is correct
7 Correct 716 ms 22616 KB Output is correct
8 Correct 650 ms 21132 KB Output is correct
9 Correct 291 ms 10840 KB Output is correct
10 Correct 600 ms 11096 KB Output is correct
11 Correct 600 ms 12888 KB Output is correct
12 Correct 666 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 10584 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 1 ms 10684 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 ms 12632 KB Output is correct
9 Correct 2 ms 12632 KB Output is correct
10 Correct 2 ms 12632 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 2 ms 10756 KB Output is correct
13 Correct 478 ms 15192 KB Output is correct
14 Correct 663 ms 22616 KB Output is correct
15 Correct 621 ms 20568 KB Output is correct
16 Correct 695 ms 18844 KB Output is correct
17 Correct 538 ms 16720 KB Output is correct
18 Correct 682 ms 22616 KB Output is correct
19 Correct 716 ms 22616 KB Output is correct
20 Correct 650 ms 21132 KB Output is correct
21 Correct 291 ms 10840 KB Output is correct
22 Correct 600 ms 11096 KB Output is correct
23 Correct 600 ms 12888 KB Output is correct
24 Correct 666 ms 10840 KB Output is correct
25 Correct 761 ms 25056 KB Output is correct
26 Correct 755 ms 25036 KB Output is correct
27 Correct 786 ms 25692 KB Output is correct
28 Correct 548 ms 25688 KB Output is correct
29 Correct 763 ms 25144 KB Output is correct
30 Correct 661 ms 25692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 10580 KB Output is correct
5 Correct 2 ms 10584 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 2 ms 10584 KB Output is correct
8 Correct 2 ms 12764 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 12632 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 1 ms 10684 KB Output is correct
14 Correct 2 ms 10584 KB Output is correct
15 Correct 2 ms 12632 KB Output is correct
16 Correct 2 ms 12632 KB Output is correct
17 Correct 2 ms 12632 KB Output is correct
18 Correct 2 ms 12632 KB Output is correct
19 Correct 2 ms 10584 KB Output is correct
20 Correct 2 ms 10756 KB Output is correct
21 Correct 2 ms 10580 KB Output is correct
22 Correct 2 ms 12632 KB Output is correct
23 Correct 2 ms 12632 KB Output is correct
24 Correct 3 ms 12804 KB Output is correct
25 Correct 2 ms 10584 KB Output is correct
26 Correct 2 ms 10584 KB Output is correct
27 Correct 2 ms 10584 KB Output is correct
28 Correct 3 ms 12724 KB Output is correct
29 Correct 2 ms 12632 KB Output is correct
30 Correct 2 ms 12632 KB Output is correct
31 Correct 2 ms 12632 KB Output is correct
32 Correct 2 ms 10584 KB Output is correct
33 Correct 2 ms 10584 KB Output is correct
34 Correct 2 ms 10584 KB Output is correct
35 Correct 2 ms 10584 KB Output is correct
36 Correct 2 ms 10584 KB Output is correct
37 Correct 2 ms 10584 KB Output is correct
38 Correct 3 ms 12632 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 2 ms 12632 KB Output is correct
41 Correct 2 ms 12632 KB Output is correct
42 Correct 1 ms 10584 KB Output is correct
43 Correct 522 ms 10840 KB Output is correct
44 Correct 665 ms 12888 KB Output is correct
45 Correct 658 ms 12888 KB Output is correct
46 Correct 547 ms 11096 KB Output is correct
47 Correct 679 ms 11264 KB Output is correct
48 Correct 655 ms 7256 KB Output is correct
49 Correct 674 ms 6744 KB Output is correct
50 Correct 685 ms 11096 KB Output is correct
51 Correct 611 ms 10840 KB Output is correct
52 Correct 632 ms 10840 KB Output is correct
53 Correct 552 ms 12888 KB Output is correct
54 Correct 698 ms 11096 KB Output is correct
55 Correct 650 ms 9048 KB Output is correct
56 Correct 705 ms 12888 KB Output is correct
57 Correct 630 ms 12888 KB Output is correct
58 Correct 601 ms 11096 KB Output is correct
59 Correct 622 ms 6924 KB Output is correct
60 Correct 587 ms 6884 KB Output is correct
61 Correct 632 ms 12888 KB Output is correct
62 Correct 604 ms 12888 KB Output is correct
63 Correct 564 ms 10840 KB Output is correct
64 Correct 602 ms 5720 KB Output is correct
65 Correct 360 ms 5208 KB Output is correct
66 Correct 628 ms 6488 KB Output is correct
67 Correct 612 ms 12888 KB Output is correct
68 Correct 590 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 10580 KB Output is correct
5 Correct 2 ms 10584 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 2 ms 10584 KB Output is correct
8 Correct 2 ms 12764 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 12632 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 1 ms 10684 KB Output is correct
14 Correct 2 ms 10584 KB Output is correct
15 Correct 2 ms 12632 KB Output is correct
16 Correct 2 ms 12632 KB Output is correct
17 Correct 2 ms 12632 KB Output is correct
18 Correct 2 ms 12632 KB Output is correct
19 Correct 2 ms 10584 KB Output is correct
20 Correct 2 ms 10756 KB Output is correct
21 Correct 2 ms 10580 KB Output is correct
22 Correct 2 ms 12632 KB Output is correct
23 Correct 2 ms 12632 KB Output is correct
24 Correct 3 ms 12804 KB Output is correct
25 Correct 2 ms 10584 KB Output is correct
26 Correct 2 ms 10584 KB Output is correct
27 Correct 2 ms 10584 KB Output is correct
28 Correct 3 ms 12724 KB Output is correct
29 Correct 2 ms 12632 KB Output is correct
30 Correct 2 ms 12632 KB Output is correct
31 Correct 2 ms 12632 KB Output is correct
32 Correct 2 ms 10584 KB Output is correct
33 Correct 2 ms 10584 KB Output is correct
34 Correct 2 ms 10584 KB Output is correct
35 Correct 2 ms 10584 KB Output is correct
36 Correct 2 ms 10584 KB Output is correct
37 Correct 2 ms 10584 KB Output is correct
38 Correct 3 ms 12632 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 2 ms 12632 KB Output is correct
41 Correct 2 ms 12632 KB Output is correct
42 Correct 1 ms 10584 KB Output is correct
43 Correct 478 ms 15192 KB Output is correct
44 Correct 663 ms 22616 KB Output is correct
45 Correct 621 ms 20568 KB Output is correct
46 Correct 695 ms 18844 KB Output is correct
47 Correct 538 ms 16720 KB Output is correct
48 Correct 682 ms 22616 KB Output is correct
49 Correct 716 ms 22616 KB Output is correct
50 Correct 650 ms 21132 KB Output is correct
51 Correct 291 ms 10840 KB Output is correct
52 Correct 600 ms 11096 KB Output is correct
53 Correct 600 ms 12888 KB Output is correct
54 Correct 666 ms 10840 KB Output is correct
55 Correct 761 ms 25056 KB Output is correct
56 Correct 755 ms 25036 KB Output is correct
57 Correct 786 ms 25692 KB Output is correct
58 Correct 548 ms 25688 KB Output is correct
59 Correct 763 ms 25144 KB Output is correct
60 Correct 661 ms 25692 KB Output is correct
61 Correct 522 ms 10840 KB Output is correct
62 Correct 665 ms 12888 KB Output is correct
63 Correct 658 ms 12888 KB Output is correct
64 Correct 547 ms 11096 KB Output is correct
65 Correct 679 ms 11264 KB Output is correct
66 Correct 655 ms 7256 KB Output is correct
67 Correct 674 ms 6744 KB Output is correct
68 Correct 685 ms 11096 KB Output is correct
69 Correct 611 ms 10840 KB Output is correct
70 Correct 632 ms 10840 KB Output is correct
71 Correct 552 ms 12888 KB Output is correct
72 Correct 698 ms 11096 KB Output is correct
73 Correct 650 ms 9048 KB Output is correct
74 Correct 705 ms 12888 KB Output is correct
75 Correct 630 ms 12888 KB Output is correct
76 Correct 601 ms 11096 KB Output is correct
77 Correct 622 ms 6924 KB Output is correct
78 Correct 587 ms 6884 KB Output is correct
79 Correct 632 ms 12888 KB Output is correct
80 Correct 604 ms 12888 KB Output is correct
81 Correct 564 ms 10840 KB Output is correct
82 Correct 602 ms 5720 KB Output is correct
83 Correct 360 ms 5208 KB Output is correct
84 Correct 628 ms 6488 KB Output is correct
85 Correct 612 ms 12888 KB Output is correct
86 Correct 590 ms 10840 KB Output is correct
87 Correct 2 ms 12632 KB Output is correct
88 Correct 429 ms 25304 KB Output is correct
89 Correct 720 ms 22864 KB Output is correct
90 Correct 817 ms 20824 KB Output is correct
91 Correct 669 ms 25152 KB Output is correct
92 Correct 821 ms 25152 KB Output is correct
93 Correct 800 ms 25252 KB Output is correct
94 Correct 776 ms 25148 KB Output is correct
95 Correct 716 ms 24912 KB Output is correct
96 Correct 603 ms 21876 KB Output is correct
97 Correct 682 ms 21772 KB Output is correct
98 Correct 608 ms 16720 KB Output is correct
99 Correct 729 ms 25148 KB Output is correct
100 Correct 700 ms 23092 KB Output is correct
101 Correct 702 ms 23296 KB Output is correct
102 Correct 657 ms 22404 KB Output is correct
103 Correct 750 ms 25044 KB Output is correct
104 Correct 759 ms 26220 KB Output is correct
105 Correct 615 ms 25568 KB Output is correct
106 Correct 669 ms 22616 KB Output is correct
107 Correct 678 ms 23216 KB Output is correct
108 Correct 641 ms 22908 KB Output is correct
109 Correct 652 ms 22484 KB Output is correct