Submission #802184

# Submission time Handle Problem Language Result Execution time Memory
802184 2023-08-02T10:49:19 Z MadokaMagicaFan Digital Circuit (IOI22_circuit) C++17
100 / 100
990 ms 24000 KB
#include "bits/stdc++.h"
#include "circuit.h"
using namespace std;
using ll = long long;
#define sz(v) ((int)(v).size())
#define pb push_back

const int N = 1e5;

ll md = 1e9+2022;
ll ans;
vector<int> adj[N+5];
vector<ll> t, st, c;
int n, m;

struct aint_lenes {
	int n;
	vector<ll> f;
	vector<int> lz;

	aint_lenes(int _n, vector<int> &a) {
		n = _n;
		f.assign(4*n, 0);
		lz.assign(4*n, 0);
		build(1, 0, n-1, a);
	}

	void build(int i, int l, int r, vector<int> &a) {
		if (l == r) {
			f[i] = a[l] % md;
			return;
		}
		int m = (l + r) >> 1;
		build(i<<1, l, m, a);
		build(i<<1|1, m+1, r, a);
		f[i] = (f[i<<1] + f[i<<1|1]) % md;
	}

	ll qry(int l, int r) {
		setl(1, 0, n-1, l, r);
		return qry(1, 0, n-1, l, r);
	}

	void setl(int i, int l, int r, int tl, int tr) {
		if (r < tl || l > tr) return;
		if (tl <= l && r <= tr) {
			lz[i] ^= 1;
			return;
		}

		int m = (l+r)>>1;
		setl(i<<1, l, m, tl, tr);
		setl(i<<1|1, m+1, r, tl, tr);

		f[i] = 0ll;
		if (lz[i<<1])
			f[i] = md - f[i<<1];
		else
			f[i] = f[i<<1];

		if (lz[i<<1|1])
			f[i] = f[i] + md - f[i<<1|1];
		else
			f[i] = f[i] + f[i<<1|1];
		f[i] %= md;
	}

	ll qry(int i, int l, int r, int tl, int tr) {
		if (r < tl || l > tr) return 0ll;
		if (lz[i]) {
			lz[i] = 0;
			f[i] = (md-f[i])%md;
			if (l != r) {
				lz[i<<1] ^= 1;
				lz[i<<1|1] ^= 1;
			}
		}
		if (tl <= l && r <= tr)
			return f[i];

		int m = (l+r) >> 1;
		return (qry(i<<1, l, m, tl, tr) +
				qry(i<<1|1, m+1, r, tl, tr)) % md;
	}
};

aint_lenes *tr;

void
dfs1(int x) {
	if (x >= n) return;

	st[x] = 0;
	t[x] = sz(adj[x]);
	for (auto u : adj[x]) {
		dfs1(u);
		st[x] = (st[x] + t[u]) % md;
		t[x] = (t[x] * t[u]) % md;
	}
}

void
dfs2(int x, ll v) {
	if (x>=n) {
		c[x-n] = (c[x-n]*v) % md;
		return;
	}

	for (auto u : adj[x]) {
		dfs2(u, v);
		v = (v * t[u]) % md;
	}
}

void
init(int _n, int _m, vector<int> p, vector<int> a)
{
	n = _n; m = _m;
	t.assign(n+m, 1);
	st.assign(n+m, 1);
	c.assign(m, 1);
	for (int i = 1; i < n+m; ++i) {
		adj[p[i]].pb(i);
	}

	dfs1(0);
	dfs2(0, 1ll);
	for (int i = 0; i < n; ++i)
		reverse(adj[i].begin(), adj[i].end());
	dfs2(0, 1ll);

	vector<int> chn(m);

	for (int i = 0; i < m; ++i) {
		if (a[i]) {
			ans = (ans + c[i]) % md;
			chn[i] = c[i];
		} else {
			chn[i] = (md - c[i]) % md;
		}
	}

	tr = new aint_lenes(m, chn);
}

int
count_ways(int l, int r)
{
	l -= n; r -= n;
	ans = (ans + tr->qry(l, r)) % md;
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 2 ms 2548 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 3 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 1 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 1 ms 2640 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2768 KB Output is correct
8 Correct 2 ms 2768 KB Output is correct
9 Correct 2 ms 2768 KB Output is correct
10 Correct 2 ms 2768 KB Output is correct
11 Correct 2 ms 2768 KB Output is correct
12 Correct 3 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 2 ms 2548 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 3 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 1 ms 2640 KB Output is correct
10 Correct 1 ms 2640 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 1 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2768 KB Output is correct
16 Correct 2 ms 2768 KB Output is correct
17 Correct 2 ms 2768 KB Output is correct
18 Correct 2 ms 2768 KB Output is correct
19 Correct 2 ms 2768 KB Output is correct
20 Correct 3 ms 2640 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2768 KB Output is correct
25 Correct 2 ms 2768 KB Output is correct
26 Correct 2 ms 2768 KB Output is correct
27 Correct 2 ms 2768 KB Output is correct
28 Correct 2 ms 2768 KB Output is correct
29 Correct 2 ms 2640 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 1 ms 2640 KB Output is correct
32 Correct 2 ms 2768 KB Output is correct
33 Correct 3 ms 2640 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 2 ms 2768 KB Output is correct
37 Correct 2 ms 2768 KB Output is correct
38 Correct 2 ms 2768 KB Output is correct
39 Correct 2 ms 2640 KB Output is correct
40 Correct 2 ms 2640 KB Output is correct
41 Correct 2 ms 2640 KB Output is correct
42 Correct 2 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 539 ms 7428 KB Output is correct
2 Correct 784 ms 12204 KB Output is correct
3 Correct 763 ms 12124 KB Output is correct
4 Correct 825 ms 12108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 539 ms 7428 KB Output is correct
2 Correct 784 ms 12204 KB Output is correct
3 Correct 763 ms 12124 KB Output is correct
4 Correct 825 ms 12108 KB Output is correct
5 Correct 646 ms 7404 KB Output is correct
6 Correct 878 ms 12128 KB Output is correct
7 Correct 809 ms 12108 KB Output is correct
8 Correct 748 ms 12108 KB Output is correct
9 Correct 362 ms 2896 KB Output is correct
10 Correct 824 ms 3152 KB Output is correct
11 Correct 771 ms 3152 KB Output is correct
12 Correct 690 ms 3156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 1 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 1 ms 2640 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2768 KB Output is correct
8 Correct 2 ms 2768 KB Output is correct
9 Correct 2 ms 2768 KB Output is correct
10 Correct 2 ms 2768 KB Output is correct
11 Correct 2 ms 2768 KB Output is correct
12 Correct 3 ms 2640 KB Output is correct
13 Correct 539 ms 7428 KB Output is correct
14 Correct 784 ms 12204 KB Output is correct
15 Correct 763 ms 12124 KB Output is correct
16 Correct 825 ms 12108 KB Output is correct
17 Correct 646 ms 7404 KB Output is correct
18 Correct 878 ms 12128 KB Output is correct
19 Correct 809 ms 12108 KB Output is correct
20 Correct 748 ms 12108 KB Output is correct
21 Correct 362 ms 2896 KB Output is correct
22 Correct 824 ms 3152 KB Output is correct
23 Correct 771 ms 3152 KB Output is correct
24 Correct 690 ms 3156 KB Output is correct
25 Correct 837 ms 16844 KB Output is correct
26 Correct 777 ms 17092 KB Output is correct
27 Correct 888 ms 17096 KB Output is correct
28 Correct 690 ms 17028 KB Output is correct
29 Correct 810 ms 23368 KB Output is correct
30 Correct 805 ms 23304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 2 ms 2548 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 3 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 1 ms 2640 KB Output is correct
10 Correct 1 ms 2640 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 1 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2768 KB Output is correct
16 Correct 2 ms 2768 KB Output is correct
17 Correct 2 ms 2768 KB Output is correct
18 Correct 2 ms 2768 KB Output is correct
19 Correct 2 ms 2768 KB Output is correct
20 Correct 3 ms 2640 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2768 KB Output is correct
25 Correct 2 ms 2768 KB Output is correct
26 Correct 2 ms 2768 KB Output is correct
27 Correct 2 ms 2768 KB Output is correct
28 Correct 2 ms 2768 KB Output is correct
29 Correct 2 ms 2640 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 1 ms 2640 KB Output is correct
32 Correct 2 ms 2768 KB Output is correct
33 Correct 3 ms 2640 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 2 ms 2768 KB Output is correct
37 Correct 2 ms 2768 KB Output is correct
38 Correct 2 ms 2768 KB Output is correct
39 Correct 2 ms 2640 KB Output is correct
40 Correct 2 ms 2640 KB Output is correct
41 Correct 2 ms 2640 KB Output is correct
42 Correct 2 ms 2640 KB Output is correct
43 Correct 500 ms 3024 KB Output is correct
44 Correct 762 ms 3024 KB Output is correct
45 Correct 593 ms 3024 KB Output is correct
46 Correct 524 ms 3280 KB Output is correct
47 Correct 679 ms 3280 KB Output is correct
48 Correct 772 ms 3280 KB Output is correct
49 Correct 634 ms 3280 KB Output is correct
50 Correct 783 ms 3284 KB Output is correct
51 Correct 745 ms 3024 KB Output is correct
52 Correct 709 ms 3024 KB Output is correct
53 Correct 810 ms 3152 KB Output is correct
54 Correct 686 ms 3276 KB Output is correct
55 Correct 866 ms 3152 KB Output is correct
56 Correct 729 ms 3152 KB Output is correct
57 Correct 663 ms 3016 KB Output is correct
58 Correct 818 ms 3604 KB Output is correct
59 Correct 718 ms 3664 KB Output is correct
60 Correct 682 ms 3664 KB Output is correct
61 Correct 611 ms 3152 KB Output is correct
62 Correct 814 ms 3032 KB Output is correct
63 Correct 867 ms 3152 KB Output is correct
64 Correct 844 ms 3100 KB Output is correct
65 Correct 333 ms 2900 KB Output is correct
66 Correct 905 ms 3152 KB Output is correct
67 Correct 717 ms 3156 KB Output is correct
68 Correct 741 ms 3148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 2 ms 2548 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 3 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 1 ms 2640 KB Output is correct
10 Correct 1 ms 2640 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 1 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2768 KB Output is correct
16 Correct 2 ms 2768 KB Output is correct
17 Correct 2 ms 2768 KB Output is correct
18 Correct 2 ms 2768 KB Output is correct
19 Correct 2 ms 2768 KB Output is correct
20 Correct 3 ms 2640 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2768 KB Output is correct
25 Correct 2 ms 2768 KB Output is correct
26 Correct 2 ms 2768 KB Output is correct
27 Correct 2 ms 2768 KB Output is correct
28 Correct 2 ms 2768 KB Output is correct
29 Correct 2 ms 2640 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 1 ms 2640 KB Output is correct
32 Correct 2 ms 2768 KB Output is correct
33 Correct 3 ms 2640 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 2 ms 2768 KB Output is correct
37 Correct 2 ms 2768 KB Output is correct
38 Correct 2 ms 2768 KB Output is correct
39 Correct 2 ms 2640 KB Output is correct
40 Correct 2 ms 2640 KB Output is correct
41 Correct 2 ms 2640 KB Output is correct
42 Correct 2 ms 2640 KB Output is correct
43 Correct 539 ms 7428 KB Output is correct
44 Correct 784 ms 12204 KB Output is correct
45 Correct 763 ms 12124 KB Output is correct
46 Correct 825 ms 12108 KB Output is correct
47 Correct 646 ms 7404 KB Output is correct
48 Correct 878 ms 12128 KB Output is correct
49 Correct 809 ms 12108 KB Output is correct
50 Correct 748 ms 12108 KB Output is correct
51 Correct 362 ms 2896 KB Output is correct
52 Correct 824 ms 3152 KB Output is correct
53 Correct 771 ms 3152 KB Output is correct
54 Correct 690 ms 3156 KB Output is correct
55 Correct 837 ms 16844 KB Output is correct
56 Correct 777 ms 17092 KB Output is correct
57 Correct 888 ms 17096 KB Output is correct
58 Correct 690 ms 17028 KB Output is correct
59 Correct 810 ms 23368 KB Output is correct
60 Correct 805 ms 23304 KB Output is correct
61 Correct 500 ms 3024 KB Output is correct
62 Correct 762 ms 3024 KB Output is correct
63 Correct 593 ms 3024 KB Output is correct
64 Correct 524 ms 3280 KB Output is correct
65 Correct 679 ms 3280 KB Output is correct
66 Correct 772 ms 3280 KB Output is correct
67 Correct 634 ms 3280 KB Output is correct
68 Correct 783 ms 3284 KB Output is correct
69 Correct 745 ms 3024 KB Output is correct
70 Correct 709 ms 3024 KB Output is correct
71 Correct 810 ms 3152 KB Output is correct
72 Correct 686 ms 3276 KB Output is correct
73 Correct 866 ms 3152 KB Output is correct
74 Correct 729 ms 3152 KB Output is correct
75 Correct 663 ms 3016 KB Output is correct
76 Correct 818 ms 3604 KB Output is correct
77 Correct 718 ms 3664 KB Output is correct
78 Correct 682 ms 3664 KB Output is correct
79 Correct 611 ms 3152 KB Output is correct
80 Correct 814 ms 3032 KB Output is correct
81 Correct 867 ms 3152 KB Output is correct
82 Correct 844 ms 3100 KB Output is correct
83 Correct 333 ms 2900 KB Output is correct
84 Correct 905 ms 3152 KB Output is correct
85 Correct 717 ms 3156 KB Output is correct
86 Correct 741 ms 3148 KB Output is correct
87 Correct 2 ms 2640 KB Output is correct
88 Correct 612 ms 15160 KB Output is correct
89 Correct 906 ms 11312 KB Output is correct
90 Correct 930 ms 11432 KB Output is correct
91 Correct 742 ms 17256 KB Output is correct
92 Correct 822 ms 17148 KB Output is correct
93 Correct 925 ms 17224 KB Output is correct
94 Correct 882 ms 17216 KB Output is correct
95 Correct 880 ms 17200 KB Output is correct
96 Correct 812 ms 12108 KB Output is correct
97 Correct 940 ms 12100 KB Output is correct
98 Correct 792 ms 14292 KB Output is correct
99 Correct 926 ms 17124 KB Output is correct
100 Correct 728 ms 14372 KB Output is correct
101 Correct 858 ms 13500 KB Output is correct
102 Correct 932 ms 12100 KB Output is correct
103 Correct 763 ms 23368 KB Output is correct
104 Correct 875 ms 23908 KB Output is correct
105 Correct 753 ms 24000 KB Output is correct
106 Correct 649 ms 11976 KB Output is correct
107 Correct 876 ms 10824 KB Output is correct
108 Correct 887 ms 11312 KB Output is correct
109 Correct 990 ms 12136 KB Output is correct