Submission #774367

# Submission time Handle Problem Language Result Execution time Memory
774367 2023-07-05T16:03:49 Z GusterGoose27 Digital Circuit (IOI22_circuit) C++17
100 / 100
970 ms 25344 KB
#include "circuit.h"

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MOD = 1000002022;
const int MAXN = 2e5;

bool init_active[MAXN];
int weight[MAXN];
vector<int> edges[MAXN];
int n, m;
int cur_mult;

class stree {
public:
	int lp, rp;
	stree *l = nullptr;
	stree *r = nullptr;
	int active;
	int tot;
	bool lz;
	stree(int lv, int rv) {
		lz = 0;
		lp = lv;
		rp = rv;
		if (lp < rp) {
			int mid = (lp+rp)/2;
			l = new stree(lp, mid);
			r = new stree(mid+1, rp);
			reupd();
		}
		else {
			tot = weight[lp];
			if (init_active[lp]) active = weight[lp];
			else active = 0;
		}
	}
	void reupd() {
		active = (l->active+r->active)%MOD;
		tot = (l->tot+r->tot)%MOD;
	}
	void setlz(bool nlz) {
		if (!nlz) return;
		lz ^= 1;
		active = (MOD+tot-active)%MOD;
	}
	void prop() {
		if (l) {
			l->setlz(lz);
			r->setlz(lz);
		}
		lz = 0;
	}
	void rev(int lv, int rv) {
		if (lp > rv || rp < lv) return;
		if (lp >= lv && rp <= rv) {
			setlz(1);
			return;
		}
		prop();
		l->rev(lv, rv);
		r->rev(lv, rv);
		reupd();
	}
};

void dfs(int cur, bool rev) {
	if (cur >= n-m) {
		// cout << cur_mult << "\n";
		weight[cur-n+m] = ((ll)weight[cur-n+m]*cur_mult)%MOD;
		return;
	}
	if (!rev) {
		for (int i = 0; i < edges[cur].size(); i++) {
			int nxt = edges[cur][i];
			dfs(nxt, rev);
		}
	}
	else {
		for (int i = edges[cur].size()-1; i >= 0; i--) {
			int nxt = edges[cur][i];
			dfs(nxt, rev);
		}
	}
	cur_mult = ((ll)cur_mult*edges[cur].size())%MOD;
	// cout << cur_mult << "\n";
}

stree *tree;

void init(int N, int M, vector<int> par, vector<int> act) {
	n = N+M;
	m = M;
	for (int i = 1; i < n; i++) {
		edges[par[i]].push_back(i);
	}
	for (int i = 0; i < m; i++) {
		init_active[i] = act[i];
		weight[i] = 1;
	}
	cur_mult = 1;
	dfs(0, 0);
	cur_mult = 1;
	dfs(0, 1);
	// for (int i = 0; i < m; i++) cout << weight[i] << ' ';
	// cout << "\n";
	tree = new stree(0, m-1);
}

int count_ways(int l, int r) {
	tree->rev(l-n+m, r-n+m);
	return tree->active;
}

Compilation message

circuit.cpp: In function 'void dfs(int, bool)':
circuit.cpp:78:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |   for (int i = 0; i < edges[cur].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 3 ms 5188 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5132 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 4 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 2 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 3 ms 5188 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5132 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5072 KB Output is correct
19 Correct 4 ms 5072 KB Output is correct
20 Correct 2 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 2 ms 5080 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5144 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5144 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 2 ms 5072 KB Output is correct
31 Correct 2 ms 5072 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5092 KB Output is correct
35 Correct 2 ms 5072 KB Output is correct
36 Correct 3 ms 5072 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 2 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 2 ms 4996 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 575 ms 9984 KB Output is correct
2 Correct 671 ms 15048 KB Output is correct
3 Correct 871 ms 14976 KB Output is correct
4 Correct 728 ms 15048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 575 ms 9984 KB Output is correct
2 Correct 671 ms 15048 KB Output is correct
3 Correct 871 ms 14976 KB Output is correct
4 Correct 728 ms 15048 KB Output is correct
5 Correct 582 ms 9976 KB Output is correct
6 Correct 797 ms 14980 KB Output is correct
7 Correct 645 ms 15048 KB Output is correct
8 Correct 632 ms 14968 KB Output is correct
9 Correct 337 ms 5328 KB Output is correct
10 Correct 637 ms 5712 KB Output is correct
11 Correct 826 ms 5584 KB Output is correct
12 Correct 677 ms 5508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 3 ms 5188 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5132 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 4 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 575 ms 9984 KB Output is correct
14 Correct 671 ms 15048 KB Output is correct
15 Correct 871 ms 14976 KB Output is correct
16 Correct 728 ms 15048 KB Output is correct
17 Correct 582 ms 9976 KB Output is correct
18 Correct 797 ms 14980 KB Output is correct
19 Correct 645 ms 15048 KB Output is correct
20 Correct 632 ms 14968 KB Output is correct
21 Correct 337 ms 5328 KB Output is correct
22 Correct 637 ms 5712 KB Output is correct
23 Correct 826 ms 5584 KB Output is correct
24 Correct 677 ms 5508 KB Output is correct
25 Correct 910 ms 19964 KB Output is correct
26 Correct 824 ms 20336 KB Output is correct
27 Correct 819 ms 20336 KB Output is correct
28 Correct 704 ms 20336 KB Output is correct
29 Correct 784 ms 24984 KB Output is correct
30 Correct 838 ms 25032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 2 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 3 ms 5188 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5132 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5072 KB Output is correct
19 Correct 4 ms 5072 KB Output is correct
20 Correct 2 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 2 ms 5080 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5144 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5144 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 2 ms 5072 KB Output is correct
31 Correct 2 ms 5072 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5092 KB Output is correct
35 Correct 2 ms 5072 KB Output is correct
36 Correct 3 ms 5072 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 2 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 2 ms 4996 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 393 ms 5376 KB Output is correct
44 Correct 719 ms 5380 KB Output is correct
45 Correct 686 ms 5456 KB Output is correct
46 Correct 691 ms 5712 KB Output is correct
47 Correct 612 ms 5768 KB Output is correct
48 Correct 791 ms 5712 KB Output is correct
49 Correct 688 ms 5764 KB Output is correct
50 Correct 717 ms 5712 KB Output is correct
51 Correct 771 ms 5584 KB Output is correct
52 Correct 696 ms 5584 KB Output is correct
53 Correct 622 ms 5328 KB Output is correct
54 Correct 664 ms 5764 KB Output is correct
55 Correct 592 ms 5632 KB Output is correct
56 Correct 808 ms 5712 KB Output is correct
57 Correct 779 ms 5532 KB Output is correct
58 Correct 801 ms 5968 KB Output is correct
59 Correct 779 ms 6016 KB Output is correct
60 Correct 711 ms 5968 KB Output is correct
61 Correct 720 ms 5380 KB Output is correct
62 Correct 681 ms 5384 KB Output is correct
63 Correct 689 ms 5456 KB Output is correct
64 Correct 733 ms 5508 KB Output is correct
65 Correct 252 ms 5200 KB Output is correct
66 Correct 797 ms 5584 KB Output is correct
67 Correct 708 ms 5584 KB Output is correct
68 Correct 577 ms 5584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 2 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 3 ms 5188 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5132 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5072 KB Output is correct
19 Correct 4 ms 5072 KB Output is correct
20 Correct 2 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 2 ms 5080 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5144 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5144 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 2 ms 5072 KB Output is correct
31 Correct 2 ms 5072 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5092 KB Output is correct
35 Correct 2 ms 5072 KB Output is correct
36 Correct 3 ms 5072 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 2 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 2 ms 4996 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 575 ms 9984 KB Output is correct
44 Correct 671 ms 15048 KB Output is correct
45 Correct 871 ms 14976 KB Output is correct
46 Correct 728 ms 15048 KB Output is correct
47 Correct 582 ms 9976 KB Output is correct
48 Correct 797 ms 14980 KB Output is correct
49 Correct 645 ms 15048 KB Output is correct
50 Correct 632 ms 14968 KB Output is correct
51 Correct 337 ms 5328 KB Output is correct
52 Correct 637 ms 5712 KB Output is correct
53 Correct 826 ms 5584 KB Output is correct
54 Correct 677 ms 5508 KB Output is correct
55 Correct 910 ms 19964 KB Output is correct
56 Correct 824 ms 20336 KB Output is correct
57 Correct 819 ms 20336 KB Output is correct
58 Correct 704 ms 20336 KB Output is correct
59 Correct 784 ms 24984 KB Output is correct
60 Correct 838 ms 25032 KB Output is correct
61 Correct 393 ms 5376 KB Output is correct
62 Correct 719 ms 5380 KB Output is correct
63 Correct 686 ms 5456 KB Output is correct
64 Correct 691 ms 5712 KB Output is correct
65 Correct 612 ms 5768 KB Output is correct
66 Correct 791 ms 5712 KB Output is correct
67 Correct 688 ms 5764 KB Output is correct
68 Correct 717 ms 5712 KB Output is correct
69 Correct 771 ms 5584 KB Output is correct
70 Correct 696 ms 5584 KB Output is correct
71 Correct 622 ms 5328 KB Output is correct
72 Correct 664 ms 5764 KB Output is correct
73 Correct 592 ms 5632 KB Output is correct
74 Correct 808 ms 5712 KB Output is correct
75 Correct 779 ms 5532 KB Output is correct
76 Correct 801 ms 5968 KB Output is correct
77 Correct 779 ms 6016 KB Output is correct
78 Correct 711 ms 5968 KB Output is correct
79 Correct 720 ms 5380 KB Output is correct
80 Correct 681 ms 5384 KB Output is correct
81 Correct 689 ms 5456 KB Output is correct
82 Correct 733 ms 5508 KB Output is correct
83 Correct 252 ms 5200 KB Output is correct
84 Correct 797 ms 5584 KB Output is correct
85 Correct 708 ms 5584 KB Output is correct
86 Correct 577 ms 5584 KB Output is correct
87 Correct 2 ms 4944 KB Output is correct
88 Correct 486 ms 18044 KB Output is correct
89 Correct 700 ms 13620 KB Output is correct
90 Correct 688 ms 14076 KB Output is correct
91 Correct 757 ms 20384 KB Output is correct
92 Correct 830 ms 20344 KB Output is correct
93 Correct 813 ms 20424 KB Output is correct
94 Correct 677 ms 20376 KB Output is correct
95 Correct 696 ms 20348 KB Output is correct
96 Correct 728 ms 16752 KB Output is correct
97 Correct 859 ms 16752 KB Output is correct
98 Correct 630 ms 13588 KB Output is correct
99 Correct 673 ms 20248 KB Output is correct
100 Correct 820 ms 18304 KB Output is correct
101 Correct 970 ms 17904 KB Output is correct
102 Correct 757 ms 16896 KB Output is correct
103 Correct 795 ms 24940 KB Output is correct
104 Correct 738 ms 25344 KB Output is correct
105 Correct 692 ms 25324 KB Output is correct
106 Correct 854 ms 13692 KB Output is correct
107 Correct 575 ms 14192 KB Output is correct
108 Correct 755 ms 15048 KB Output is correct
109 Correct 649 ms 16908 KB Output is correct