Submission #1058044

# Submission time Handle Problem Language Result Execution time Memory
1058044 2024-08-14T08:06:01 Z fuad27 Digital Circuit (IOI22_circuit) C++17
100 / 100
703 ms 37568 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
const long long mod=1'000'002'022; // ????? 
const int N = 2e5+10;
vector<int> child[N];
long long total[N];
long long contrib[N];
 
void dfs(int at) {
	total[at] = max(1, (int)child[at].size());
	for(int to:child[at]) {
		dfs(to);
		total[at] = (total[at] * total[to])%mod;
	}
}
void dfs2(int at) {
	if(!child[at].size())return;
	long long sumtot = 0;
	for(int to:child[at]) {
		sumtot+=total[to];
		sumtot%=mod;
	}
	int c = child[at].size();
	vector<long long> pref(c);
	pref[0] = 1;
	for(int i = 1;i<c;i++) {
		pref[i] = (pref[i-1] * total[child[at][i-1]])%mod;
	}
	long long suff = 1;
	for(int i = c-1;i>=0;i--) {
		contrib[child[at][i]] = (((suff*pref[i])%mod)*contrib[at])%mod;
		dfs2(child[at][i]);
		suff = (suff*total[child[at][i]])%mod;
	}
}
vector<int> A;
int nn;

pair<long long, long long> T[4*N];
int lz[4*N];
void build(vector<int> &a, int tl = 0, int tr = N-1, int v = 1) {
	if(tl == tr) {
		if((int)a.size() > tl)T[v] = {a[tl], 0};
		else T[v] = {0, 0};
		return;
	}
	int tm = (tl+tr)/2;
	build(a, tl, tm, 2*v);
	build(a, tm+1, tr, 2*v+1);
	T[v].first = (T[2*v].first + T[2*v+1].first)%mod;
	T[v].second = (T[2*v].second + T[2*v+1].second)%mod;
}
void push(int v) {
	if(lz[v]) {
		lz[v] = 0;
		lz[2*v]^=1;
		lz[2*v+1]^=1;
		swap(T[2*v].first, T[2*v].second);
		swap(T[2*v+1].first, T[2*v+1].second);
	}
}
void update(int l, int r, int tl = 0, int tr = N-1, int v = 1) {
	if(r < tl or tr < l)return;
	if(l<=tl and tr<=r) {
		lz[v] ^= 1;
		swap(T[v].first, T[v].second);
		return;
	}
	push(v);
	int tm = (tl+tr)/2;
	update(l, r, tl, tm, 2*v);
	update(l, r, tm+1, tr, 2*v+1);
	T[v].first = (T[2*v].first + T[2*v+1].first)%mod;
	T[v].second = (T[2*v].second + T[2*v+1].second)%mod;
}

void init(int n, int m, std::vector<int> p, std::vector<int> a) {
	nn=n;
	A = a;
	for(int i = 1;i<m+n;i++) {
		child[p[i]].push_back(i);
	}
	for(int i= 0;i<m+n;i++)contrib[i] = 1;
	dfs(0);
	dfs2(0);
	vector<int> cont(m);
	for(int i = 0;i<m;i++) {
		cont[i] = contrib[i+n];
	}
	build(cont);
	for(int i = 0;i<m;i++) {
		if(A[i]) {
			update(i, i);
		}
	}
}
 
int count_ways(int L, int R) {
	L-=nn, R-=nn;
	update(L, R);
	long long ans = (total[0] - T[1].first)%mod;
	ans+=mod;
	ans%=mod;
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19544 KB Output is correct
2 Correct 5 ms 19544 KB Output is correct
3 Correct 5 ms 19544 KB Output is correct
4 Correct 5 ms 19544 KB Output is correct
5 Correct 5 ms 19544 KB Output is correct
6 Correct 6 ms 19544 KB Output is correct
7 Correct 5 ms 19540 KB Output is correct
8 Correct 5 ms 19544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 19544 KB Output is correct
2 Correct 5 ms 19544 KB Output is correct
3 Correct 4 ms 19544 KB Output is correct
4 Correct 5 ms 19544 KB Output is correct
5 Correct 5 ms 19700 KB Output is correct
6 Correct 5 ms 19684 KB Output is correct
7 Correct 4 ms 19544 KB Output is correct
8 Correct 4 ms 19544 KB Output is correct
9 Correct 5 ms 19544 KB Output is correct
10 Correct 5 ms 19800 KB Output is correct
11 Correct 5 ms 19792 KB Output is correct
12 Correct 4 ms 19544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19544 KB Output is correct
2 Correct 5 ms 19544 KB Output is correct
3 Correct 5 ms 19544 KB Output is correct
4 Correct 5 ms 19544 KB Output is correct
5 Correct 5 ms 19544 KB Output is correct
6 Correct 6 ms 19544 KB Output is correct
7 Correct 5 ms 19540 KB Output is correct
8 Correct 5 ms 19544 KB Output is correct
9 Correct 5 ms 19544 KB Output is correct
10 Correct 5 ms 19544 KB Output is correct
11 Correct 4 ms 19544 KB Output is correct
12 Correct 5 ms 19544 KB Output is correct
13 Correct 5 ms 19700 KB Output is correct
14 Correct 5 ms 19684 KB Output is correct
15 Correct 4 ms 19544 KB Output is correct
16 Correct 4 ms 19544 KB Output is correct
17 Correct 5 ms 19544 KB Output is correct
18 Correct 5 ms 19800 KB Output is correct
19 Correct 5 ms 19792 KB Output is correct
20 Correct 4 ms 19544 KB Output is correct
21 Correct 4 ms 19544 KB Output is correct
22 Correct 5 ms 19544 KB Output is correct
23 Correct 5 ms 19544 KB Output is correct
24 Correct 4 ms 19544 KB Output is correct
25 Correct 4 ms 19704 KB Output is correct
26 Correct 4 ms 19544 KB Output is correct
27 Correct 4 ms 19544 KB Output is correct
28 Correct 5 ms 19544 KB Output is correct
29 Correct 5 ms 19544 KB Output is correct
30 Correct 4 ms 19544 KB Output is correct
31 Correct 3 ms 19544 KB Output is correct
32 Correct 5 ms 19700 KB Output is correct
33 Correct 5 ms 19544 KB Output is correct
34 Correct 5 ms 19624 KB Output is correct
35 Correct 3 ms 19544 KB Output is correct
36 Correct 6 ms 19800 KB Output is correct
37 Correct 5 ms 19812 KB Output is correct
38 Correct 4 ms 19800 KB Output is correct
39 Correct 3 ms 19544 KB Output is correct
40 Correct 5 ms 19708 KB Output is correct
41 Correct 5 ms 19544 KB Output is correct
42 Correct 5 ms 19528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 416 ms 21848 KB Output is correct
2 Correct 580 ms 24240 KB Output is correct
3 Correct 507 ms 24104 KB Output is correct
4 Correct 582 ms 23736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 416 ms 21848 KB Output is correct
2 Correct 580 ms 24240 KB Output is correct
3 Correct 507 ms 24104 KB Output is correct
4 Correct 582 ms 23736 KB Output is correct
5 Correct 472 ms 21848 KB Output is correct
6 Correct 598 ms 24264 KB Output is correct
7 Correct 586 ms 24152 KB Output is correct
8 Correct 532 ms 24232 KB Output is correct
9 Correct 215 ms 19800 KB Output is correct
10 Correct 592 ms 19800 KB Output is correct
11 Correct 587 ms 19800 KB Output is correct
12 Correct 489 ms 19800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 19544 KB Output is correct
2 Correct 5 ms 19544 KB Output is correct
3 Correct 4 ms 19544 KB Output is correct
4 Correct 5 ms 19544 KB Output is correct
5 Correct 5 ms 19700 KB Output is correct
6 Correct 5 ms 19684 KB Output is correct
7 Correct 4 ms 19544 KB Output is correct
8 Correct 4 ms 19544 KB Output is correct
9 Correct 5 ms 19544 KB Output is correct
10 Correct 5 ms 19800 KB Output is correct
11 Correct 5 ms 19792 KB Output is correct
12 Correct 4 ms 19544 KB Output is correct
13 Correct 416 ms 21848 KB Output is correct
14 Correct 580 ms 24240 KB Output is correct
15 Correct 507 ms 24104 KB Output is correct
16 Correct 582 ms 23736 KB Output is correct
17 Correct 472 ms 21848 KB Output is correct
18 Correct 598 ms 24264 KB Output is correct
19 Correct 586 ms 24152 KB Output is correct
20 Correct 532 ms 24232 KB Output is correct
21 Correct 215 ms 19800 KB Output is correct
22 Correct 592 ms 19800 KB Output is correct
23 Correct 587 ms 19800 KB Output is correct
24 Correct 489 ms 19800 KB Output is correct
25 Correct 638 ms 26348 KB Output is correct
26 Correct 672 ms 26448 KB Output is correct
27 Correct 655 ms 26448 KB Output is correct
28 Correct 497 ms 26516 KB Output is correct
29 Correct 592 ms 37176 KB Output is correct
30 Correct 558 ms 37200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19544 KB Output is correct
2 Correct 5 ms 19544 KB Output is correct
3 Correct 5 ms 19544 KB Output is correct
4 Correct 5 ms 19544 KB Output is correct
5 Correct 5 ms 19544 KB Output is correct
6 Correct 6 ms 19544 KB Output is correct
7 Correct 5 ms 19540 KB Output is correct
8 Correct 5 ms 19544 KB Output is correct
9 Correct 5 ms 19544 KB Output is correct
10 Correct 5 ms 19544 KB Output is correct
11 Correct 4 ms 19544 KB Output is correct
12 Correct 5 ms 19544 KB Output is correct
13 Correct 5 ms 19700 KB Output is correct
14 Correct 5 ms 19684 KB Output is correct
15 Correct 4 ms 19544 KB Output is correct
16 Correct 4 ms 19544 KB Output is correct
17 Correct 5 ms 19544 KB Output is correct
18 Correct 5 ms 19800 KB Output is correct
19 Correct 5 ms 19792 KB Output is correct
20 Correct 4 ms 19544 KB Output is correct
21 Correct 4 ms 19544 KB Output is correct
22 Correct 5 ms 19544 KB Output is correct
23 Correct 5 ms 19544 KB Output is correct
24 Correct 4 ms 19544 KB Output is correct
25 Correct 4 ms 19704 KB Output is correct
26 Correct 4 ms 19544 KB Output is correct
27 Correct 4 ms 19544 KB Output is correct
28 Correct 5 ms 19544 KB Output is correct
29 Correct 5 ms 19544 KB Output is correct
30 Correct 4 ms 19544 KB Output is correct
31 Correct 3 ms 19544 KB Output is correct
32 Correct 5 ms 19700 KB Output is correct
33 Correct 5 ms 19544 KB Output is correct
34 Correct 5 ms 19624 KB Output is correct
35 Correct 3 ms 19544 KB Output is correct
36 Correct 6 ms 19800 KB Output is correct
37 Correct 5 ms 19812 KB Output is correct
38 Correct 4 ms 19800 KB Output is correct
39 Correct 3 ms 19544 KB Output is correct
40 Correct 5 ms 19708 KB Output is correct
41 Correct 5 ms 19544 KB Output is correct
42 Correct 5 ms 19528 KB Output is correct
43 Correct 391 ms 19800 KB Output is correct
44 Correct 524 ms 19800 KB Output is correct
45 Correct 580 ms 19800 KB Output is correct
46 Correct 503 ms 19800 KB Output is correct
47 Correct 482 ms 19892 KB Output is correct
48 Correct 479 ms 19952 KB Output is correct
49 Correct 524 ms 19800 KB Output is correct
50 Correct 509 ms 19800 KB Output is correct
51 Correct 516 ms 19900 KB Output is correct
52 Correct 578 ms 19896 KB Output is correct
53 Correct 454 ms 20312 KB Output is correct
54 Correct 458 ms 19800 KB Output is correct
55 Correct 473 ms 19800 KB Output is correct
56 Correct 499 ms 19800 KB Output is correct
57 Correct 490 ms 19800 KB Output is correct
58 Correct 575 ms 20312 KB Output is correct
59 Correct 531 ms 20568 KB Output is correct
60 Correct 586 ms 20568 KB Output is correct
61 Correct 512 ms 19800 KB Output is correct
62 Correct 590 ms 19800 KB Output is correct
63 Correct 563 ms 19800 KB Output is correct
64 Correct 585 ms 19800 KB Output is correct
65 Correct 269 ms 19800 KB Output is correct
66 Correct 597 ms 19800 KB Output is correct
67 Correct 526 ms 19800 KB Output is correct
68 Correct 515 ms 19800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19544 KB Output is correct
2 Correct 5 ms 19544 KB Output is correct
3 Correct 5 ms 19544 KB Output is correct
4 Correct 5 ms 19544 KB Output is correct
5 Correct 5 ms 19544 KB Output is correct
6 Correct 6 ms 19544 KB Output is correct
7 Correct 5 ms 19540 KB Output is correct
8 Correct 5 ms 19544 KB Output is correct
9 Correct 5 ms 19544 KB Output is correct
10 Correct 5 ms 19544 KB Output is correct
11 Correct 4 ms 19544 KB Output is correct
12 Correct 5 ms 19544 KB Output is correct
13 Correct 5 ms 19700 KB Output is correct
14 Correct 5 ms 19684 KB Output is correct
15 Correct 4 ms 19544 KB Output is correct
16 Correct 4 ms 19544 KB Output is correct
17 Correct 5 ms 19544 KB Output is correct
18 Correct 5 ms 19800 KB Output is correct
19 Correct 5 ms 19792 KB Output is correct
20 Correct 4 ms 19544 KB Output is correct
21 Correct 4 ms 19544 KB Output is correct
22 Correct 5 ms 19544 KB Output is correct
23 Correct 5 ms 19544 KB Output is correct
24 Correct 4 ms 19544 KB Output is correct
25 Correct 4 ms 19704 KB Output is correct
26 Correct 4 ms 19544 KB Output is correct
27 Correct 4 ms 19544 KB Output is correct
28 Correct 5 ms 19544 KB Output is correct
29 Correct 5 ms 19544 KB Output is correct
30 Correct 4 ms 19544 KB Output is correct
31 Correct 3 ms 19544 KB Output is correct
32 Correct 5 ms 19700 KB Output is correct
33 Correct 5 ms 19544 KB Output is correct
34 Correct 5 ms 19624 KB Output is correct
35 Correct 3 ms 19544 KB Output is correct
36 Correct 6 ms 19800 KB Output is correct
37 Correct 5 ms 19812 KB Output is correct
38 Correct 4 ms 19800 KB Output is correct
39 Correct 3 ms 19544 KB Output is correct
40 Correct 5 ms 19708 KB Output is correct
41 Correct 5 ms 19544 KB Output is correct
42 Correct 5 ms 19528 KB Output is correct
43 Correct 416 ms 21848 KB Output is correct
44 Correct 580 ms 24240 KB Output is correct
45 Correct 507 ms 24104 KB Output is correct
46 Correct 582 ms 23736 KB Output is correct
47 Correct 472 ms 21848 KB Output is correct
48 Correct 598 ms 24264 KB Output is correct
49 Correct 586 ms 24152 KB Output is correct
50 Correct 532 ms 24232 KB Output is correct
51 Correct 215 ms 19800 KB Output is correct
52 Correct 592 ms 19800 KB Output is correct
53 Correct 587 ms 19800 KB Output is correct
54 Correct 489 ms 19800 KB Output is correct
55 Correct 638 ms 26348 KB Output is correct
56 Correct 672 ms 26448 KB Output is correct
57 Correct 655 ms 26448 KB Output is correct
58 Correct 497 ms 26516 KB Output is correct
59 Correct 592 ms 37176 KB Output is correct
60 Correct 558 ms 37200 KB Output is correct
61 Correct 391 ms 19800 KB Output is correct
62 Correct 524 ms 19800 KB Output is correct
63 Correct 580 ms 19800 KB Output is correct
64 Correct 503 ms 19800 KB Output is correct
65 Correct 482 ms 19892 KB Output is correct
66 Correct 479 ms 19952 KB Output is correct
67 Correct 524 ms 19800 KB Output is correct
68 Correct 509 ms 19800 KB Output is correct
69 Correct 516 ms 19900 KB Output is correct
70 Correct 578 ms 19896 KB Output is correct
71 Correct 454 ms 20312 KB Output is correct
72 Correct 458 ms 19800 KB Output is correct
73 Correct 473 ms 19800 KB Output is correct
74 Correct 499 ms 19800 KB Output is correct
75 Correct 490 ms 19800 KB Output is correct
76 Correct 575 ms 20312 KB Output is correct
77 Correct 531 ms 20568 KB Output is correct
78 Correct 586 ms 20568 KB Output is correct
79 Correct 512 ms 19800 KB Output is correct
80 Correct 590 ms 19800 KB Output is correct
81 Correct 563 ms 19800 KB Output is correct
82 Correct 585 ms 19800 KB Output is correct
83 Correct 269 ms 19800 KB Output is correct
84 Correct 597 ms 19800 KB Output is correct
85 Correct 526 ms 19800 KB Output is correct
86 Correct 515 ms 19800 KB Output is correct
87 Correct 4 ms 19544 KB Output is correct
88 Correct 380 ms 25936 KB Output is correct
89 Correct 629 ms 24152 KB Output is correct
90 Correct 613 ms 23888 KB Output is correct
91 Correct 600 ms 26704 KB Output is correct
92 Correct 703 ms 26680 KB Output is correct
93 Correct 618 ms 25776 KB Output is correct
94 Correct 596 ms 26760 KB Output is correct
95 Correct 631 ms 26560 KB Output is correct
96 Correct 426 ms 23116 KB Output is correct
97 Correct 490 ms 23144 KB Output is correct
98 Correct 419 ms 34388 KB Output is correct
99 Correct 571 ms 26448 KB Output is correct
100 Correct 570 ms 24656 KB Output is correct
101 Correct 565 ms 24088 KB Output is correct
102 Correct 486 ms 23128 KB Output is correct
103 Correct 577 ms 37176 KB Output is correct
104 Correct 554 ms 37568 KB Output is correct
105 Correct 533 ms 37568 KB Output is correct
106 Correct 511 ms 26192 KB Output is correct
107 Correct 556 ms 23168 KB Output is correct
108 Correct 591 ms 23120 KB Output is correct
109 Correct 517 ms 23376 KB Output is correct