Submission #966446

# Submission time Handle Problem Language Result Execution time Memory
966446 2024-04-19T22:02:45 Z ZeroCool Digital Circuit (IOI22_circuit) C++17
100 / 100
730 ms 37848 KB
#include "circuit.h"
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

using ll = long long;

const ll N = 3e5 + 10;
const ll MOD = 1e9 + 2022;

ll n, m;
bool A[N];

vector<ll> g[N];

ll sz[N];

void dfs1(ll x){
	sz[x] = g[x].size();
	
	for(auto u: g[x]){
		dfs1(u);
		sz[x] *= sz[u];
		sz[x] %= MOD;
	}
	if(!sz[x])sz[x] = 1;
}

ll X[N];

void dfs2(ll x,ll w){
	X[x] = w;
	
	ll k = g[x].size();
	ll pref[k], suff[k];
	
	for(ll i = 0;i<k;i++){
		pref[i] = sz[g[x][i]];
		if(i) pref[i] = (pref[i-1] * pref[i]) % MOD;
	}
	
	for(ll i = k - 1;i>=0;i--){
		suff[i] = sz[g[x][i]];
		if(i +1 < k)suff[i] = (suff[i] * suff[i+1]) % MOD;
	}
	
	for(ll i = 0;i<k;i++){
		ll prod = w;
		if(i)prod = (prod * pref[i-1]) % MOD;
		if(i + 1 < k)prod = (prod * suff[i+1]) % MOD;
		dfs2(g[x][i], prod);
	}
}

array<ll, 2> t[4 * N];
bool lazy[4 * N];

void build(ll k,ll tl,ll tr){
	if(tl == tr){
		t[k] = {X[tl], 0};
		if(A[tl])swap(t[k][0], t[k][1]);
		return;
	}
	ll tm = (tl + tr) / 2;
	
	build(k *2, tl, tm);
	build(k*2+1, tm + 1, tr);
	t[k][0] = (t[k*2][0] + t[k*2+1][0]) % MOD;
	t[k][1] = (t[k*2][1] + t[k*2+1][1]) % MOD;
}

void push(ll k, ll tl,ll tr){
	if(!lazy[k])return;
	swap(t[k][0], t[k][1]);
	if(tl != tr){
		lazy[k*2] ^= 1;
		lazy[k*2+1] ^= 1;
	}
	
	
	lazy[k] = 0;
}

void update(ll k,ll tl,ll tr,ll l,ll r){
	push(k,tl, tr);
	if(r < tl || tr < l)return;
	
	if(l <= tl && tr <= r){
		lazy[k] ^= 1;
		push(k,tl, tr);
		return;
	}
	
	
	ll tm = (tl + tr) / 2;
	
	update(k * 2, tl, tm, l, r);
	update(k*2+1, tm+1,tr, l, r);
	
	t[k][0] = (t[k*2][0] + t[k*2+1][0]) % MOD;
	t[k][1] = (t[k*2][1] + t[k*2+1][1]) % MOD;
}



void init(int nn, int mm, std::vector<int> P, std::vector<int> a) {
	n = nn;
	m = mm;
	
	for(ll i = 1;i < n + m;i++){
		g[P[i]].pb(i);
	}
	
	for(ll i = n;i<n + m;i++)A[i] = a[i - n];
	
	dfs1(0);
	dfs2(0, 1);
	
	build(1, n, n + m - 1);
}

int count_ways(int L, int R) {
	update(1, n, n + m - 1, L, R);
	push(1, n, n + m - 1);
  return t[1][1];
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 15448 KB Output is correct
2 Correct 3 ms 15700 KB Output is correct
3 Correct 3 ms 15448 KB Output is correct
4 Correct 3 ms 15448 KB Output is correct
5 Correct 3 ms 15448 KB Output is correct
6 Correct 3 ms 15448 KB Output is correct
7 Correct 4 ms 15448 KB Output is correct
8 Correct 3 ms 15448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15448 KB Output is correct
2 Correct 3 ms 15448 KB Output is correct
3 Correct 3 ms 15448 KB Output is correct
4 Correct 3 ms 15448 KB Output is correct
5 Correct 3 ms 15448 KB Output is correct
6 Correct 3 ms 15700 KB Output is correct
7 Correct 3 ms 15448 KB Output is correct
8 Correct 3 ms 15444 KB Output is correct
9 Correct 3 ms 15448 KB Output is correct
10 Correct 3 ms 15700 KB Output is correct
11 Correct 3 ms 15704 KB Output is correct
12 Correct 3 ms 15448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 15448 KB Output is correct
2 Correct 3 ms 15700 KB Output is correct
3 Correct 3 ms 15448 KB Output is correct
4 Correct 3 ms 15448 KB Output is correct
5 Correct 3 ms 15448 KB Output is correct
6 Correct 3 ms 15448 KB Output is correct
7 Correct 4 ms 15448 KB Output is correct
8 Correct 3 ms 15448 KB Output is correct
9 Correct 3 ms 15448 KB Output is correct
10 Correct 3 ms 15448 KB Output is correct
11 Correct 3 ms 15448 KB Output is correct
12 Correct 3 ms 15448 KB Output is correct
13 Correct 3 ms 15448 KB Output is correct
14 Correct 3 ms 15700 KB Output is correct
15 Correct 3 ms 15448 KB Output is correct
16 Correct 3 ms 15444 KB Output is correct
17 Correct 3 ms 15448 KB Output is correct
18 Correct 3 ms 15700 KB Output is correct
19 Correct 3 ms 15704 KB Output is correct
20 Correct 3 ms 15448 KB Output is correct
21 Correct 3 ms 15448 KB Output is correct
22 Correct 3 ms 15448 KB Output is correct
23 Correct 3 ms 15448 KB Output is correct
24 Correct 3 ms 15448 KB Output is correct
25 Correct 3 ms 15448 KB Output is correct
26 Correct 3 ms 15448 KB Output is correct
27 Correct 3 ms 15540 KB Output is correct
28 Correct 3 ms 15448 KB Output is correct
29 Correct 3 ms 15444 KB Output is correct
30 Correct 3 ms 15448 KB Output is correct
31 Correct 4 ms 15448 KB Output is correct
32 Correct 3 ms 15448 KB Output is correct
33 Correct 3 ms 15448 KB Output is correct
34 Correct 3 ms 15448 KB Output is correct
35 Correct 3 ms 15448 KB Output is correct
36 Correct 3 ms 15704 KB Output is correct
37 Correct 3 ms 15448 KB Output is correct
38 Correct 3 ms 15448 KB Output is correct
39 Correct 3 ms 15448 KB Output is correct
40 Correct 3 ms 15448 KB Output is correct
41 Correct 3 ms 15592 KB Output is correct
42 Correct 3 ms 15448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 410 ms 17220 KB Output is correct
2 Correct 571 ms 21080 KB Output is correct
3 Correct 650 ms 21080 KB Output is correct
4 Correct 600 ms 21080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 410 ms 17220 KB Output is correct
2 Correct 571 ms 21080 KB Output is correct
3 Correct 650 ms 21080 KB Output is correct
4 Correct 600 ms 21080 KB Output is correct
5 Correct 528 ms 17220 KB Output is correct
6 Correct 622 ms 21188 KB Output is correct
7 Correct 649 ms 21180 KB Output is correct
8 Correct 578 ms 21276 KB Output is correct
9 Correct 269 ms 15448 KB Output is correct
10 Correct 604 ms 15704 KB Output is correct
11 Correct 562 ms 15704 KB Output is correct
12 Correct 538 ms 15704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15448 KB Output is correct
2 Correct 3 ms 15448 KB Output is correct
3 Correct 3 ms 15448 KB Output is correct
4 Correct 3 ms 15448 KB Output is correct
5 Correct 3 ms 15448 KB Output is correct
6 Correct 3 ms 15700 KB Output is correct
7 Correct 3 ms 15448 KB Output is correct
8 Correct 3 ms 15444 KB Output is correct
9 Correct 3 ms 15448 KB Output is correct
10 Correct 3 ms 15700 KB Output is correct
11 Correct 3 ms 15704 KB Output is correct
12 Correct 3 ms 15448 KB Output is correct
13 Correct 410 ms 17220 KB Output is correct
14 Correct 571 ms 21080 KB Output is correct
15 Correct 650 ms 21080 KB Output is correct
16 Correct 600 ms 21080 KB Output is correct
17 Correct 528 ms 17220 KB Output is correct
18 Correct 622 ms 21188 KB Output is correct
19 Correct 649 ms 21180 KB Output is correct
20 Correct 578 ms 21276 KB Output is correct
21 Correct 269 ms 15448 KB Output is correct
22 Correct 604 ms 15704 KB Output is correct
23 Correct 562 ms 15704 KB Output is correct
24 Correct 538 ms 15704 KB Output is correct
25 Correct 658 ms 25040 KB Output is correct
26 Correct 702 ms 25156 KB Output is correct
27 Correct 730 ms 25148 KB Output is correct
28 Correct 505 ms 25168 KB Output is correct
29 Correct 693 ms 37692 KB Output is correct
30 Correct 579 ms 37848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 15448 KB Output is correct
2 Correct 3 ms 15700 KB Output is correct
3 Correct 3 ms 15448 KB Output is correct
4 Correct 3 ms 15448 KB Output is correct
5 Correct 3 ms 15448 KB Output is correct
6 Correct 3 ms 15448 KB Output is correct
7 Correct 4 ms 15448 KB Output is correct
8 Correct 3 ms 15448 KB Output is correct
9 Correct 3 ms 15448 KB Output is correct
10 Correct 3 ms 15448 KB Output is correct
11 Correct 3 ms 15448 KB Output is correct
12 Correct 3 ms 15448 KB Output is correct
13 Correct 3 ms 15448 KB Output is correct
14 Correct 3 ms 15700 KB Output is correct
15 Correct 3 ms 15448 KB Output is correct
16 Correct 3 ms 15444 KB Output is correct
17 Correct 3 ms 15448 KB Output is correct
18 Correct 3 ms 15700 KB Output is correct
19 Correct 3 ms 15704 KB Output is correct
20 Correct 3 ms 15448 KB Output is correct
21 Correct 3 ms 15448 KB Output is correct
22 Correct 3 ms 15448 KB Output is correct
23 Correct 3 ms 15448 KB Output is correct
24 Correct 3 ms 15448 KB Output is correct
25 Correct 3 ms 15448 KB Output is correct
26 Correct 3 ms 15448 KB Output is correct
27 Correct 3 ms 15540 KB Output is correct
28 Correct 3 ms 15448 KB Output is correct
29 Correct 3 ms 15444 KB Output is correct
30 Correct 3 ms 15448 KB Output is correct
31 Correct 4 ms 15448 KB Output is correct
32 Correct 3 ms 15448 KB Output is correct
33 Correct 3 ms 15448 KB Output is correct
34 Correct 3 ms 15448 KB Output is correct
35 Correct 3 ms 15448 KB Output is correct
36 Correct 3 ms 15704 KB Output is correct
37 Correct 3 ms 15448 KB Output is correct
38 Correct 3 ms 15448 KB Output is correct
39 Correct 3 ms 15448 KB Output is correct
40 Correct 3 ms 15448 KB Output is correct
41 Correct 3 ms 15592 KB Output is correct
42 Correct 3 ms 15448 KB Output is correct
43 Correct 429 ms 15700 KB Output is correct
44 Correct 583 ms 15704 KB Output is correct
45 Correct 557 ms 15704 KB Output is correct
46 Correct 520 ms 15704 KB Output is correct
47 Correct 589 ms 15704 KB Output is correct
48 Correct 541 ms 15704 KB Output is correct
49 Correct 614 ms 15704 KB Output is correct
50 Correct 586 ms 15704 KB Output is correct
51 Correct 550 ms 15808 KB Output is correct
52 Correct 577 ms 15812 KB Output is correct
53 Correct 520 ms 15960 KB Output is correct
54 Correct 601 ms 15704 KB Output is correct
55 Correct 590 ms 15704 KB Output is correct
56 Correct 544 ms 15704 KB Output is correct
57 Correct 618 ms 15704 KB Output is correct
58 Correct 598 ms 16216 KB Output is correct
59 Correct 596 ms 16240 KB Output is correct
60 Correct 548 ms 16240 KB Output is correct
61 Correct 563 ms 15704 KB Output is correct
62 Correct 578 ms 15704 KB Output is correct
63 Correct 580 ms 15704 KB Output is correct
64 Correct 593 ms 15704 KB Output is correct
65 Correct 299 ms 15448 KB Output is correct
66 Correct 589 ms 15704 KB Output is correct
67 Correct 575 ms 15704 KB Output is correct
68 Correct 610 ms 15704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 15448 KB Output is correct
2 Correct 3 ms 15700 KB Output is correct
3 Correct 3 ms 15448 KB Output is correct
4 Correct 3 ms 15448 KB Output is correct
5 Correct 3 ms 15448 KB Output is correct
6 Correct 3 ms 15448 KB Output is correct
7 Correct 4 ms 15448 KB Output is correct
8 Correct 3 ms 15448 KB Output is correct
9 Correct 3 ms 15448 KB Output is correct
10 Correct 3 ms 15448 KB Output is correct
11 Correct 3 ms 15448 KB Output is correct
12 Correct 3 ms 15448 KB Output is correct
13 Correct 3 ms 15448 KB Output is correct
14 Correct 3 ms 15700 KB Output is correct
15 Correct 3 ms 15448 KB Output is correct
16 Correct 3 ms 15444 KB Output is correct
17 Correct 3 ms 15448 KB Output is correct
18 Correct 3 ms 15700 KB Output is correct
19 Correct 3 ms 15704 KB Output is correct
20 Correct 3 ms 15448 KB Output is correct
21 Correct 3 ms 15448 KB Output is correct
22 Correct 3 ms 15448 KB Output is correct
23 Correct 3 ms 15448 KB Output is correct
24 Correct 3 ms 15448 KB Output is correct
25 Correct 3 ms 15448 KB Output is correct
26 Correct 3 ms 15448 KB Output is correct
27 Correct 3 ms 15540 KB Output is correct
28 Correct 3 ms 15448 KB Output is correct
29 Correct 3 ms 15444 KB Output is correct
30 Correct 3 ms 15448 KB Output is correct
31 Correct 4 ms 15448 KB Output is correct
32 Correct 3 ms 15448 KB Output is correct
33 Correct 3 ms 15448 KB Output is correct
34 Correct 3 ms 15448 KB Output is correct
35 Correct 3 ms 15448 KB Output is correct
36 Correct 3 ms 15704 KB Output is correct
37 Correct 3 ms 15448 KB Output is correct
38 Correct 3 ms 15448 KB Output is correct
39 Correct 3 ms 15448 KB Output is correct
40 Correct 3 ms 15448 KB Output is correct
41 Correct 3 ms 15592 KB Output is correct
42 Correct 3 ms 15448 KB Output is correct
43 Correct 410 ms 17220 KB Output is correct
44 Correct 571 ms 21080 KB Output is correct
45 Correct 650 ms 21080 KB Output is correct
46 Correct 600 ms 21080 KB Output is correct
47 Correct 528 ms 17220 KB Output is correct
48 Correct 622 ms 21188 KB Output is correct
49 Correct 649 ms 21180 KB Output is correct
50 Correct 578 ms 21276 KB Output is correct
51 Correct 269 ms 15448 KB Output is correct
52 Correct 604 ms 15704 KB Output is correct
53 Correct 562 ms 15704 KB Output is correct
54 Correct 538 ms 15704 KB Output is correct
55 Correct 658 ms 25040 KB Output is correct
56 Correct 702 ms 25156 KB Output is correct
57 Correct 730 ms 25148 KB Output is correct
58 Correct 505 ms 25168 KB Output is correct
59 Correct 693 ms 37692 KB Output is correct
60 Correct 579 ms 37848 KB Output is correct
61 Correct 429 ms 15700 KB Output is correct
62 Correct 583 ms 15704 KB Output is correct
63 Correct 557 ms 15704 KB Output is correct
64 Correct 520 ms 15704 KB Output is correct
65 Correct 589 ms 15704 KB Output is correct
66 Correct 541 ms 15704 KB Output is correct
67 Correct 614 ms 15704 KB Output is correct
68 Correct 586 ms 15704 KB Output is correct
69 Correct 550 ms 15808 KB Output is correct
70 Correct 577 ms 15812 KB Output is correct
71 Correct 520 ms 15960 KB Output is correct
72 Correct 601 ms 15704 KB Output is correct
73 Correct 590 ms 15704 KB Output is correct
74 Correct 544 ms 15704 KB Output is correct
75 Correct 618 ms 15704 KB Output is correct
76 Correct 598 ms 16216 KB Output is correct
77 Correct 596 ms 16240 KB Output is correct
78 Correct 548 ms 16240 KB Output is correct
79 Correct 563 ms 15704 KB Output is correct
80 Correct 578 ms 15704 KB Output is correct
81 Correct 580 ms 15704 KB Output is correct
82 Correct 593 ms 15704 KB Output is correct
83 Correct 299 ms 15448 KB Output is correct
84 Correct 589 ms 15704 KB Output is correct
85 Correct 575 ms 15704 KB Output is correct
86 Correct 610 ms 15704 KB Output is correct
87 Correct 3 ms 15448 KB Output is correct
88 Correct 421 ms 24996 KB Output is correct
89 Correct 622 ms 21360 KB Output is correct
90 Correct 651 ms 21780 KB Output is correct
91 Correct 618 ms 25664 KB Output is correct
92 Correct 651 ms 25656 KB Output is correct
93 Correct 669 ms 25680 KB Output is correct
94 Correct 677 ms 25596 KB Output is correct
95 Correct 624 ms 25680 KB Output is correct
96 Correct 593 ms 23756 KB Output is correct
97 Correct 664 ms 23756 KB Output is correct
98 Correct 503 ms 25660 KB Output is correct
99 Correct 658 ms 25224 KB Output is correct
100 Correct 605 ms 24152 KB Output is correct
101 Correct 661 ms 23640 KB Output is correct
102 Correct 634 ms 22104 KB Output is correct
103 Correct 679 ms 37492 KB Output is correct
104 Correct 645 ms 32472 KB Output is correct
105 Correct 616 ms 32408 KB Output is correct
106 Correct 677 ms 23096 KB Output is correct
107 Correct 624 ms 22952 KB Output is correct
108 Correct 643 ms 23104 KB Output is correct
109 Correct 653 ms 22480 KB Output is correct