Submission #776575

# Submission time Handle Problem Language Result Execution time Memory
776575 2023-07-08T04:19:11 Z SanguineChameleon Digital Circuit (IOI22_circuit) C++17
46 / 100
3000 ms 5604 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

const long long mod = 1e9 + 2022;
const int maxN = 1e5 + 20;
long long cont[maxN * 2];
long long ways[maxN * 2];
vector<int> ch[maxN];
int A[maxN];
int N, M;

void dfs1(int u) {
	if (ch[u].empty()) {
		ways[u] = 1;
		return;
	}
	ways[u] = (int)ch[u].size();
	for (auto v: ch[u]) {
		dfs1(v);
		ways[u] = ways[u] * ways[v] % mod;
	}
}

void dfs2(int u) {
	if (ch[u].empty()) {
		return;
	}
	int sz = ch[u].size();
	vector<long long> pref(sz);
	vector<long long> suf(sz);
	pref[0] = ways[ch[u][0]];
	for (int i = 1; i < sz; i++) {
		pref[i] = pref[i - 1] * ways[ch[u][i]] % mod;
	}
	suf[sz - 1] = ways[ch[u][sz - 1]];
	for (int i = sz - 2; i >= 0; i--) {
		suf[i] = suf[i + 1] * ways[ch[u][i]] % mod;
	}
	for (int i = 0; i < sz; i++) {
		cont[ch[u][i]] = cont[u] * (i > 0 ? pref[i - 1] : 1) % mod * (i < sz - 1 ? suf[i + 1] : 1) % mod;
		dfs2(ch[u][i]);
	}
}

void init(int _N, int _M, vector<int> P, vector<int> _A) {
	N = _N;
	M = _M;
	for (int i = 2; i <= N + M; i++) {
		ch[P[i - 1] + 1].push_back(i);
	}
	for (int i = 1; i <= M; i++) {
		A[i] = _A[i - 1];
	}
	dfs1(1);
	cont[1] = 1;
	dfs2(1);
}

int count_ways(int L, int R) {
	L -= N - 1;
	R -= N - 1;
	for (int i = L; i <= R; i++) {
		A[i] ^= 1;
	}
	long long res = 0;
	for (int i = 1; i <= M; i++) {
		if (A[i]) {
			res += cont[i + N];
			res %= mod;
		}
	}
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 3 ms 2640 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 1 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 7 ms 2652 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 2 ms 2640 KB Output is correct
3 Correct 1 ms 2640 KB Output is correct
4 Correct 2 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 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2896 KB Output is correct
11 Correct 2 ms 2896 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 3 ms 2640 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 1 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 7 ms 2652 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 1 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 1 ms 2640 KB Output is correct
12 Correct 2 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 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 2 ms 2896 KB Output is correct
19 Correct 2 ms 2896 KB Output is correct
20 Correct 2 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 2640 KB Output is correct
25 Correct 2 ms 2640 KB Output is correct
26 Correct 2 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 2 ms 2640 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 2 ms 2896 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2640 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 1 ms 2640 KB Output is correct
36 Correct 2 ms 2896 KB Output is correct
37 Correct 2 ms 2896 KB Output is correct
38 Correct 2 ms 2896 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 Execution timed out 3055 ms 5604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3055 ms 5604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 1 ms 2640 KB Output is correct
4 Correct 2 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 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2896 KB Output is correct
11 Correct 2 ms 2896 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Execution timed out 3055 ms 5604 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 3 ms 2640 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 1 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 7 ms 2652 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 1 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 1 ms 2640 KB Output is correct
12 Correct 2 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 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 2 ms 2896 KB Output is correct
19 Correct 2 ms 2896 KB Output is correct
20 Correct 2 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 2640 KB Output is correct
25 Correct 2 ms 2640 KB Output is correct
26 Correct 2 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 2 ms 2640 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 2 ms 2896 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2640 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 1 ms 2640 KB Output is correct
36 Correct 2 ms 2896 KB Output is correct
37 Correct 2 ms 2896 KB Output is correct
38 Correct 2 ms 2896 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 877 ms 2908 KB Output is correct
44 Correct 1390 ms 2916 KB Output is correct
45 Correct 1529 ms 2896 KB Output is correct
46 Correct 1879 ms 3024 KB Output is correct
47 Correct 2210 ms 3024 KB Output is correct
48 Correct 2326 ms 3040 KB Output is correct
49 Correct 2341 ms 3036 KB Output is correct
50 Correct 1858 ms 3024 KB Output is correct
51 Correct 2629 ms 2952 KB Output is correct
52 Correct 2345 ms 2944 KB Output is correct
53 Correct 747 ms 3936 KB Output is correct
54 Correct 2345 ms 3044 KB Output is correct
55 Correct 2313 ms 2896 KB Output is correct
56 Correct 2369 ms 2912 KB Output is correct
57 Correct 2536 ms 2768 KB Output is correct
58 Correct 2578 ms 4060 KB Output is correct
59 Correct 2492 ms 4192 KB Output is correct
60 Correct 2711 ms 4176 KB Output is correct
61 Correct 1355 ms 3168 KB Output is correct
62 Correct 1804 ms 2896 KB Output is correct
63 Correct 1975 ms 2768 KB Output is correct
64 Correct 2460 ms 2896 KB Output is correct
65 Correct 669 ms 2768 KB Output is correct
66 Correct 2129 ms 2960 KB Output is correct
67 Correct 1976 ms 2912 KB Output is correct
68 Correct 2036 ms 3024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 3 ms 2640 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 1 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 7 ms 2652 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 1 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 1 ms 2640 KB Output is correct
12 Correct 2 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 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 2 ms 2896 KB Output is correct
19 Correct 2 ms 2896 KB Output is correct
20 Correct 2 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 2640 KB Output is correct
25 Correct 2 ms 2640 KB Output is correct
26 Correct 2 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 2 ms 2640 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 2 ms 2896 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2640 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 1 ms 2640 KB Output is correct
36 Correct 2 ms 2896 KB Output is correct
37 Correct 2 ms 2896 KB Output is correct
38 Correct 2 ms 2896 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 Execution timed out 3055 ms 5604 KB Time limit exceeded
44 Halted 0 ms 0 KB -