Submission #1059935

# Submission time Handle Problem Language Result Execution time Memory
1059935 2024-08-15T09:27:39 Z nvujica Digital Circuit (IOI22_circuit) C++17
100 / 100
762 ms 34752 KB
#include <bits/stdc++.h>
#include "circuit.h"

#define ll long long
#define fi first
#define se second

using namespace std;

const int maxn = 2e5 + 10, off = (1 << 17), mod = 1e9 + 2022;

int n, m;
int tour[2 * off][2];
int prop[2 * off];
int d[maxn];
//int pot[maxn];
vector <int> v[maxn];
//int stanje[maxn];
int fakt[maxn];
int umn[maxn];

int add(int x, int y){
	return (x + y) % mod;
}

int mul(int x, int y){
	return ((ll)x * y) % mod;
}

void push(int x){
	if(x >= off || !prop[x]) return;
	
	prop[x] = 0;
	swap(tour[x * 2][0], tour[x * 2][1]);
	swap(tour[x * 2 + 1][0], tour[x * 2 + 1][1]);
	prop[x * 2] ^= 1;
	prop[x * 2 + 1] ^= 1;
}

void update(int x, int lo, int hi, int l, int r){
	push(x);
	
	if(hi <= l || r <= lo) return;
	
	if(l <= lo && hi <= r){
		swap(tour[x][0], tour[x][1]);
		prop[x] = 1;
		return;
	}
	
	int mid = (lo + hi) / 2;
	update(x * 2, lo, mid, l, r);
	update(x * 2 + 1, mid, hi, l, r);
	tour[x][0] = add(tour[x * 2][0], tour[x * 2 + 1][0]);
	tour[x][1] = add(tour[x * 2][1], tour[x * 2 + 1][1]);
}

void dfs1(int x){
//	cout << x << endl;
	
	umn[x] = 1;
	
	for(int i = 0; i < v[x].size(); i++){
		int x2 = v[x][i];
		
//		d[x2] = d[x] + 1;
		dfs1(x2);
		umn[x] = mul(umn[x], umn[x2]);
	}
	
	if(x < n) umn[x] = mul(umn[x], v[x].size());
}

void dfs2(int x){
	int c = v[x].size();
	
	vector<int> pref(c + 2);
	vector<int> suff(c + 2);
	
	pref[0] = 1;
	
	for(int i = 0; i < c; i++){
		int x2 = v[x][i];
		
		pref[i + 1] = mul(pref[i], umn[x2]);
	}
	
	suff[c + 1] = 1;
	
	for(int i = c - 1; i >= 0; i--){
		int x2 = v[x][i];
		
		suff[i + 1] = mul(suff[i + 2], umn[x2]);
	}
	
	for(int i = 0; i < c; i++){
		int x2 = v[x][i];
		
		fakt[x2] = mul(fakt[x], mul(pref[i], suff[i + 2]));
		dfs2(x2);
	}
}

void init(int N, int M, vector<int> P, vector<int> A){
	n = N;
	m = M;
	
//	pot[0] = 1;
//	for(int i = 1; i < maxn; i++){
//		pot[i] = mul(pot[i - 1], 2);
//	}
	
	for(int i = 1; i < n + m; i++){
//		par[i] = P[i];
		v[P[i]].push_back(i);
	}
	
//	cout << "tu sam " << endl;
	
	fakt[0] = 1;
	dfs1(0);
	dfs2(0);
	
//	for(int i = 0; i < n + m; i++){
//		cout << umn[i] << ' ';
//	}
//	cout << endl;
//	
//	for(int i = 0; i < n + m; i++){
//		cout << fakt[i] << ' ';
//	}
//	cout << endl;
	
//	cout << "ovdje " << endl;
	
	for(int i = 0; i < m; i++){
		tour[off + i][A[i]] = fakt[n + i];
	}
	
	for(int x = off - 1; x >= 1; x--){
		tour[x][0] = add(tour[x * 2][0], tour[x * 2 + 1][0]);
		tour[x][1] = add(tour[x * 2][1], tour[x * 2 + 1][1]);
	}
}


int count_ways(int L, int R){
	update(1, 0, off, L - n, R - n + 1);
	
	return tour[1][1];
}

Compilation message

circuit.cpp: In function 'void dfs1(int)':
circuit.cpp:63:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |  for(int i = 0; i < v[x].size(); i++){
      |                 ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9304 KB Output is correct
2 Correct 2 ms 9304 KB Output is correct
3 Correct 2 ms 9396 KB Output is correct
4 Correct 2 ms 9304 KB Output is correct
5 Correct 2 ms 9304 KB Output is correct
6 Correct 2 ms 9304 KB Output is correct
7 Correct 2 ms 9304 KB Output is correct
8 Correct 2 ms 9304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9304 KB Output is correct
2 Correct 2 ms 9304 KB Output is correct
3 Correct 2 ms 9304 KB Output is correct
4 Correct 2 ms 9304 KB Output is correct
5 Correct 2 ms 9304 KB Output is correct
6 Correct 2 ms 9304 KB Output is correct
7 Correct 2 ms 9304 KB Output is correct
8 Correct 2 ms 9204 KB Output is correct
9 Correct 3 ms 9304 KB Output is correct
10 Correct 2 ms 9560 KB Output is correct
11 Correct 2 ms 9560 KB Output is correct
12 Correct 2 ms 9304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9304 KB Output is correct
2 Correct 2 ms 9304 KB Output is correct
3 Correct 2 ms 9396 KB Output is correct
4 Correct 2 ms 9304 KB Output is correct
5 Correct 2 ms 9304 KB Output is correct
6 Correct 2 ms 9304 KB Output is correct
7 Correct 2 ms 9304 KB Output is correct
8 Correct 2 ms 9304 KB Output is correct
9 Correct 2 ms 9304 KB Output is correct
10 Correct 2 ms 9304 KB Output is correct
11 Correct 2 ms 9304 KB Output is correct
12 Correct 2 ms 9304 KB Output is correct
13 Correct 2 ms 9304 KB Output is correct
14 Correct 2 ms 9304 KB Output is correct
15 Correct 2 ms 9304 KB Output is correct
16 Correct 2 ms 9204 KB Output is correct
17 Correct 3 ms 9304 KB Output is correct
18 Correct 2 ms 9560 KB Output is correct
19 Correct 2 ms 9560 KB Output is correct
20 Correct 2 ms 9304 KB Output is correct
21 Correct 2 ms 9304 KB Output is correct
22 Correct 2 ms 9404 KB Output is correct
23 Correct 3 ms 9304 KB Output is correct
24 Correct 3 ms 9392 KB Output is correct
25 Correct 2 ms 9304 KB Output is correct
26 Correct 2 ms 9304 KB Output is correct
27 Correct 2 ms 9304 KB Output is correct
28 Correct 2 ms 9304 KB Output is correct
29 Correct 3 ms 9304 KB Output is correct
30 Correct 2 ms 9304 KB Output is correct
31 Correct 2 ms 9560 KB Output is correct
32 Correct 2 ms 9304 KB Output is correct
33 Correct 2 ms 9304 KB Output is correct
34 Correct 3 ms 9304 KB Output is correct
35 Correct 2 ms 9304 KB Output is correct
36 Correct 2 ms 9560 KB Output is correct
37 Correct 2 ms 9468 KB Output is correct
38 Correct 2 ms 9560 KB Output is correct
39 Correct 2 ms 9304 KB Output is correct
40 Correct 2 ms 9304 KB Output is correct
41 Correct 2 ms 9304 KB Output is correct
42 Correct 2 ms 9304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 428 ms 11400 KB Output is correct
2 Correct 657 ms 13392 KB Output is correct
3 Correct 734 ms 13400 KB Output is correct
4 Correct 679 ms 13444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 428 ms 11400 KB Output is correct
2 Correct 657 ms 13392 KB Output is correct
3 Correct 734 ms 13400 KB Output is correct
4 Correct 679 ms 13444 KB Output is correct
5 Correct 599 ms 11352 KB Output is correct
6 Correct 724 ms 13392 KB Output is correct
7 Correct 681 ms 13656 KB Output is correct
8 Correct 673 ms 13656 KB Output is correct
9 Correct 360 ms 9304 KB Output is correct
10 Correct 682 ms 9560 KB Output is correct
11 Correct 663 ms 9560 KB Output is correct
12 Correct 638 ms 9560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9304 KB Output is correct
2 Correct 2 ms 9304 KB Output is correct
3 Correct 2 ms 9304 KB Output is correct
4 Correct 2 ms 9304 KB Output is correct
5 Correct 2 ms 9304 KB Output is correct
6 Correct 2 ms 9304 KB Output is correct
7 Correct 2 ms 9304 KB Output is correct
8 Correct 2 ms 9204 KB Output is correct
9 Correct 3 ms 9304 KB Output is correct
10 Correct 2 ms 9560 KB Output is correct
11 Correct 2 ms 9560 KB Output is correct
12 Correct 2 ms 9304 KB Output is correct
13 Correct 428 ms 11400 KB Output is correct
14 Correct 657 ms 13392 KB Output is correct
15 Correct 734 ms 13400 KB Output is correct
16 Correct 679 ms 13444 KB Output is correct
17 Correct 599 ms 11352 KB Output is correct
18 Correct 724 ms 13392 KB Output is correct
19 Correct 681 ms 13656 KB Output is correct
20 Correct 673 ms 13656 KB Output is correct
21 Correct 360 ms 9304 KB Output is correct
22 Correct 682 ms 9560 KB Output is correct
23 Correct 663 ms 9560 KB Output is correct
24 Correct 638 ms 9560 KB Output is correct
25 Correct 713 ms 15676 KB Output is correct
26 Correct 755 ms 15692 KB Output is correct
27 Correct 762 ms 15696 KB Output is correct
28 Correct 619 ms 15572 KB Output is correct
29 Correct 759 ms 34396 KB Output is correct
30 Correct 707 ms 34384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9304 KB Output is correct
2 Correct 2 ms 9304 KB Output is correct
3 Correct 2 ms 9396 KB Output is correct
4 Correct 2 ms 9304 KB Output is correct
5 Correct 2 ms 9304 KB Output is correct
6 Correct 2 ms 9304 KB Output is correct
7 Correct 2 ms 9304 KB Output is correct
8 Correct 2 ms 9304 KB Output is correct
9 Correct 2 ms 9304 KB Output is correct
10 Correct 2 ms 9304 KB Output is correct
11 Correct 2 ms 9304 KB Output is correct
12 Correct 2 ms 9304 KB Output is correct
13 Correct 2 ms 9304 KB Output is correct
14 Correct 2 ms 9304 KB Output is correct
15 Correct 2 ms 9304 KB Output is correct
16 Correct 2 ms 9204 KB Output is correct
17 Correct 3 ms 9304 KB Output is correct
18 Correct 2 ms 9560 KB Output is correct
19 Correct 2 ms 9560 KB Output is correct
20 Correct 2 ms 9304 KB Output is correct
21 Correct 2 ms 9304 KB Output is correct
22 Correct 2 ms 9404 KB Output is correct
23 Correct 3 ms 9304 KB Output is correct
24 Correct 3 ms 9392 KB Output is correct
25 Correct 2 ms 9304 KB Output is correct
26 Correct 2 ms 9304 KB Output is correct
27 Correct 2 ms 9304 KB Output is correct
28 Correct 2 ms 9304 KB Output is correct
29 Correct 3 ms 9304 KB Output is correct
30 Correct 2 ms 9304 KB Output is correct
31 Correct 2 ms 9560 KB Output is correct
32 Correct 2 ms 9304 KB Output is correct
33 Correct 2 ms 9304 KB Output is correct
34 Correct 3 ms 9304 KB Output is correct
35 Correct 2 ms 9304 KB Output is correct
36 Correct 2 ms 9560 KB Output is correct
37 Correct 2 ms 9468 KB Output is correct
38 Correct 2 ms 9560 KB Output is correct
39 Correct 2 ms 9304 KB Output is correct
40 Correct 2 ms 9304 KB Output is correct
41 Correct 2 ms 9304 KB Output is correct
42 Correct 2 ms 9304 KB Output is correct
43 Correct 431 ms 9560 KB Output is correct
44 Correct 652 ms 9560 KB Output is correct
45 Correct 676 ms 9560 KB Output is correct
46 Correct 609 ms 9560 KB Output is correct
47 Correct 721 ms 9560 KB Output is correct
48 Correct 644 ms 9560 KB Output is correct
49 Correct 678 ms 9560 KB Output is correct
50 Correct 673 ms 9560 KB Output is correct
51 Correct 654 ms 9560 KB Output is correct
52 Correct 667 ms 9560 KB Output is correct
53 Correct 672 ms 10328 KB Output is correct
54 Correct 662 ms 9560 KB Output is correct
55 Correct 657 ms 9560 KB Output is correct
56 Correct 636 ms 9560 KB Output is correct
57 Correct 673 ms 9304 KB Output is correct
58 Correct 712 ms 10584 KB Output is correct
59 Correct 697 ms 10584 KB Output is correct
60 Correct 676 ms 10584 KB Output is correct
61 Correct 694 ms 9560 KB Output is correct
62 Correct 728 ms 9304 KB Output is correct
63 Correct 643 ms 9304 KB Output is correct
64 Correct 661 ms 9304 KB Output is correct
65 Correct 319 ms 9304 KB Output is correct
66 Correct 634 ms 9560 KB Output is correct
67 Correct 683 ms 9560 KB Output is correct
68 Correct 610 ms 9560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9304 KB Output is correct
2 Correct 2 ms 9304 KB Output is correct
3 Correct 2 ms 9396 KB Output is correct
4 Correct 2 ms 9304 KB Output is correct
5 Correct 2 ms 9304 KB Output is correct
6 Correct 2 ms 9304 KB Output is correct
7 Correct 2 ms 9304 KB Output is correct
8 Correct 2 ms 9304 KB Output is correct
9 Correct 2 ms 9304 KB Output is correct
10 Correct 2 ms 9304 KB Output is correct
11 Correct 2 ms 9304 KB Output is correct
12 Correct 2 ms 9304 KB Output is correct
13 Correct 2 ms 9304 KB Output is correct
14 Correct 2 ms 9304 KB Output is correct
15 Correct 2 ms 9304 KB Output is correct
16 Correct 2 ms 9204 KB Output is correct
17 Correct 3 ms 9304 KB Output is correct
18 Correct 2 ms 9560 KB Output is correct
19 Correct 2 ms 9560 KB Output is correct
20 Correct 2 ms 9304 KB Output is correct
21 Correct 2 ms 9304 KB Output is correct
22 Correct 2 ms 9404 KB Output is correct
23 Correct 3 ms 9304 KB Output is correct
24 Correct 3 ms 9392 KB Output is correct
25 Correct 2 ms 9304 KB Output is correct
26 Correct 2 ms 9304 KB Output is correct
27 Correct 2 ms 9304 KB Output is correct
28 Correct 2 ms 9304 KB Output is correct
29 Correct 3 ms 9304 KB Output is correct
30 Correct 2 ms 9304 KB Output is correct
31 Correct 2 ms 9560 KB Output is correct
32 Correct 2 ms 9304 KB Output is correct
33 Correct 2 ms 9304 KB Output is correct
34 Correct 3 ms 9304 KB Output is correct
35 Correct 2 ms 9304 KB Output is correct
36 Correct 2 ms 9560 KB Output is correct
37 Correct 2 ms 9468 KB Output is correct
38 Correct 2 ms 9560 KB Output is correct
39 Correct 2 ms 9304 KB Output is correct
40 Correct 2 ms 9304 KB Output is correct
41 Correct 2 ms 9304 KB Output is correct
42 Correct 2 ms 9304 KB Output is correct
43 Correct 428 ms 11400 KB Output is correct
44 Correct 657 ms 13392 KB Output is correct
45 Correct 734 ms 13400 KB Output is correct
46 Correct 679 ms 13444 KB Output is correct
47 Correct 599 ms 11352 KB Output is correct
48 Correct 724 ms 13392 KB Output is correct
49 Correct 681 ms 13656 KB Output is correct
50 Correct 673 ms 13656 KB Output is correct
51 Correct 360 ms 9304 KB Output is correct
52 Correct 682 ms 9560 KB Output is correct
53 Correct 663 ms 9560 KB Output is correct
54 Correct 638 ms 9560 KB Output is correct
55 Correct 713 ms 15676 KB Output is correct
56 Correct 755 ms 15692 KB Output is correct
57 Correct 762 ms 15696 KB Output is correct
58 Correct 619 ms 15572 KB Output is correct
59 Correct 759 ms 34396 KB Output is correct
60 Correct 707 ms 34384 KB Output is correct
61 Correct 431 ms 9560 KB Output is correct
62 Correct 652 ms 9560 KB Output is correct
63 Correct 676 ms 9560 KB Output is correct
64 Correct 609 ms 9560 KB Output is correct
65 Correct 721 ms 9560 KB Output is correct
66 Correct 644 ms 9560 KB Output is correct
67 Correct 678 ms 9560 KB Output is correct
68 Correct 673 ms 9560 KB Output is correct
69 Correct 654 ms 9560 KB Output is correct
70 Correct 667 ms 9560 KB Output is correct
71 Correct 672 ms 10328 KB Output is correct
72 Correct 662 ms 9560 KB Output is correct
73 Correct 657 ms 9560 KB Output is correct
74 Correct 636 ms 9560 KB Output is correct
75 Correct 673 ms 9304 KB Output is correct
76 Correct 712 ms 10584 KB Output is correct
77 Correct 697 ms 10584 KB Output is correct
78 Correct 676 ms 10584 KB Output is correct
79 Correct 694 ms 9560 KB Output is correct
80 Correct 728 ms 9304 KB Output is correct
81 Correct 643 ms 9304 KB Output is correct
82 Correct 661 ms 9304 KB Output is correct
83 Correct 319 ms 9304 KB Output is correct
84 Correct 634 ms 9560 KB Output is correct
85 Correct 683 ms 9560 KB Output is correct
86 Correct 610 ms 9560 KB Output is correct
87 Correct 3 ms 9304 KB Output is correct
88 Correct 413 ms 15012 KB Output is correct
89 Correct 707 ms 13688 KB Output is correct
90 Correct 758 ms 13392 KB Output is correct
91 Correct 669 ms 15696 KB Output is correct
92 Correct 748 ms 15696 KB Output is correct
93 Correct 734 ms 15696 KB Output is correct
94 Correct 745 ms 15696 KB Output is correct
95 Correct 700 ms 15708 KB Output is correct
96 Correct 704 ms 12216 KB Output is correct
97 Correct 693 ms 12224 KB Output is correct
98 Correct 687 ms 32080 KB Output is correct
99 Correct 741 ms 15696 KB Output is correct
100 Correct 659 ms 13652 KB Output is correct
101 Correct 704 ms 13136 KB Output is correct
102 Correct 667 ms 12368 KB Output is correct
103 Correct 757 ms 34540 KB Output is correct
104 Correct 734 ms 34752 KB Output is correct
105 Correct 602 ms 34752 KB Output is correct
106 Correct 646 ms 17496 KB Output is correct
107 Correct 573 ms 12632 KB Output is correct
108 Correct 675 ms 12604 KB Output is correct
109 Correct 643 ms 12368 KB Output is correct