Submission #834707

# Submission time Handle Problem Language Result Execution time Memory
834707 2023-08-22T17:31:47 Z IBory Digital Circuit (IOI22_circuit) C++17
100 / 100
961 ms 34952 KB
#include "circuit.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const ll SZ = 1 << 18, MOD = 1'000'002'022;
vector<int> G[SZ];
ll N, M, S[SZ], A[SZ], ans;

ll DFS(int cur) {
	ll& ret = S[cur] = G[cur].size();
	if (G[cur].empty()) ret = 1;
	for (int next : G[cur]) {
		ll c = DFS(next);
		ret = ret * c % MOD;
	}
	return ret;
}

void DFS2(int cur, ll n) {
	if (G[cur].empty()) {
		A[cur] = n;
		return;
	}
	vector<ll> D;
	for (int next : G[cur]) D.push_back(S[next]);
	for (int i = (int)D.size() - 2; i >= 0; --i) D[i] = D[i] * D[i + 1] % MOD;
	ll pref = 1;
	for (int i = 0; i < G[cur].size(); ++i) {
		ll t = n * pref % MOD;
		if (i != (int)G[cur].size() - 1) t = t * D[i + 1] % MOD;
		DFS2(G[cur][i], t);
		pref = pref * S[G[cur][i]] % MOD;
	}
}

struct Seg {
	ll T[SZ << 1], P[SZ << 1], Z[SZ << 1];
	void Build(int N, int M) {
		for (int i = SZ; i < SZ + M; ++i) P[i] = A[i - SZ + N];
		for (int i = SZ - 1; i >= 0; --i) P[i] = P[i * 2] + P[i * 2 + 1];
	}
	void Push(int n) {
		if (n < SZ) {
			Z[n * 2] += Z[n];
			Z[n * 2 + 1] += Z[n];
		}
		if (Z[n] & 1) T[n] = P[n] - T[n];
		Z[n] = 0;
	}
	void Update(int L, int R, int sL = 1, int sR = SZ, int n = 1) {
		Push(n);
		if (R < sL || sR < L) return;
		if (L <= sL && sR <= R) {
			ans += P[n] - 2LL * T[n];
			Z[n]++;
			Push(n);
			return;
		}
		int mid = (sL + sR) >> 1;
		Update(L, R, sL, mid, n * 2);
		Update(L, R, mid + 1, sR, n * 2 + 1);
		T[n] = T[n * 2] + T[n * 2 + 1];
	}
} T;

void init(int _N, int _M, vector<int> P, vector<int> Q) {
	N = _N, M = _M;
	for (int i = 1; i < N + M; ++i) G[P[i]].push_back(i);
	DFS(0);
	DFS2(0, 1);
	T.Build(N, M);
	for (int i = 0; i < M; ++i) if (Q[i]) T.Update(i + 1, i + 1);
}

int count_ways(int L, int R) {
	T.Update(L - N + 1, R - N + 1);
	ll ret = ans % MOD;
	return ret;
}

Compilation message

circuit.cpp: In function 'void DFS2(int, ll)':
circuit.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for (int i = 0; i < G[cur].size(); ++i) {
      |                  ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8528 KB Output is correct
2 Correct 4 ms 8528 KB Output is correct
3 Correct 4 ms 8656 KB Output is correct
4 Correct 4 ms 8632 KB Output is correct
5 Correct 4 ms 8656 KB Output is correct
6 Correct 4 ms 8656 KB Output is correct
7 Correct 4 ms 8656 KB Output is correct
8 Correct 4 ms 8656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8528 KB Output is correct
2 Correct 4 ms 8656 KB Output is correct
3 Correct 4 ms 8656 KB Output is correct
4 Correct 4 ms 8656 KB Output is correct
5 Correct 4 ms 8656 KB Output is correct
6 Correct 4 ms 8656 KB Output is correct
7 Correct 6 ms 8656 KB Output is correct
8 Correct 4 ms 8620 KB Output is correct
9 Correct 5 ms 8656 KB Output is correct
10 Correct 4 ms 8784 KB Output is correct
11 Correct 4 ms 8784 KB Output is correct
12 Correct 4 ms 8640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8528 KB Output is correct
2 Correct 4 ms 8528 KB Output is correct
3 Correct 4 ms 8656 KB Output is correct
4 Correct 4 ms 8632 KB Output is correct
5 Correct 4 ms 8656 KB Output is correct
6 Correct 4 ms 8656 KB Output is correct
7 Correct 4 ms 8656 KB Output is correct
8 Correct 4 ms 8656 KB Output is correct
9 Correct 4 ms 8528 KB Output is correct
10 Correct 4 ms 8656 KB Output is correct
11 Correct 4 ms 8656 KB Output is correct
12 Correct 4 ms 8656 KB Output is correct
13 Correct 4 ms 8656 KB Output is correct
14 Correct 4 ms 8656 KB Output is correct
15 Correct 6 ms 8656 KB Output is correct
16 Correct 4 ms 8620 KB Output is correct
17 Correct 5 ms 8656 KB Output is correct
18 Correct 4 ms 8784 KB Output is correct
19 Correct 4 ms 8784 KB Output is correct
20 Correct 4 ms 8640 KB Output is correct
21 Correct 4 ms 8656 KB Output is correct
22 Correct 4 ms 8656 KB Output is correct
23 Correct 4 ms 8656 KB Output is correct
24 Correct 4 ms 8656 KB Output is correct
25 Correct 4 ms 8656 KB Output is correct
26 Correct 5 ms 8656 KB Output is correct
27 Correct 5 ms 8736 KB Output is correct
28 Correct 5 ms 8656 KB Output is correct
29 Correct 4 ms 8664 KB Output is correct
30 Correct 4 ms 8656 KB Output is correct
31 Correct 5 ms 8784 KB Output is correct
32 Correct 5 ms 8656 KB Output is correct
33 Correct 5 ms 8656 KB Output is correct
34 Correct 4 ms 8656 KB Output is correct
35 Correct 4 ms 8656 KB Output is correct
36 Correct 4 ms 8784 KB Output is correct
37 Correct 5 ms 8784 KB Output is correct
38 Correct 4 ms 8900 KB Output is correct
39 Correct 4 ms 8656 KB Output is correct
40 Correct 4 ms 8656 KB Output is correct
41 Correct 4 ms 8656 KB Output is correct
42 Correct 4 ms 8656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 487 ms 12476 KB Output is correct
2 Correct 742 ms 16236 KB Output is correct
3 Correct 704 ms 16200 KB Output is correct
4 Correct 670 ms 15548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 487 ms 12476 KB Output is correct
2 Correct 742 ms 16236 KB Output is correct
3 Correct 704 ms 16200 KB Output is correct
4 Correct 670 ms 15548 KB Output is correct
5 Correct 498 ms 12488 KB Output is correct
6 Correct 559 ms 16248 KB Output is correct
7 Correct 958 ms 16316 KB Output is correct
8 Correct 692 ms 16328 KB Output is correct
9 Correct 287 ms 8784 KB Output is correct
10 Correct 729 ms 9040 KB Output is correct
11 Correct 827 ms 9040 KB Output is correct
12 Correct 709 ms 9040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8528 KB Output is correct
2 Correct 4 ms 8656 KB Output is correct
3 Correct 4 ms 8656 KB Output is correct
4 Correct 4 ms 8656 KB Output is correct
5 Correct 4 ms 8656 KB Output is correct
6 Correct 4 ms 8656 KB Output is correct
7 Correct 6 ms 8656 KB Output is correct
8 Correct 4 ms 8620 KB Output is correct
9 Correct 5 ms 8656 KB Output is correct
10 Correct 4 ms 8784 KB Output is correct
11 Correct 4 ms 8784 KB Output is correct
12 Correct 4 ms 8640 KB Output is correct
13 Correct 487 ms 12476 KB Output is correct
14 Correct 742 ms 16236 KB Output is correct
15 Correct 704 ms 16200 KB Output is correct
16 Correct 670 ms 15548 KB Output is correct
17 Correct 498 ms 12488 KB Output is correct
18 Correct 559 ms 16248 KB Output is correct
19 Correct 958 ms 16316 KB Output is correct
20 Correct 692 ms 16328 KB Output is correct
21 Correct 287 ms 8784 KB Output is correct
22 Correct 729 ms 9040 KB Output is correct
23 Correct 827 ms 9040 KB Output is correct
24 Correct 709 ms 9040 KB Output is correct
25 Correct 781 ms 20164 KB Output is correct
26 Correct 792 ms 20396 KB Output is correct
27 Correct 869 ms 20288 KB Output is correct
28 Correct 644 ms 20304 KB Output is correct
29 Correct 737 ms 34372 KB Output is correct
30 Correct 703 ms 34420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8528 KB Output is correct
2 Correct 4 ms 8528 KB Output is correct
3 Correct 4 ms 8656 KB Output is correct
4 Correct 4 ms 8632 KB Output is correct
5 Correct 4 ms 8656 KB Output is correct
6 Correct 4 ms 8656 KB Output is correct
7 Correct 4 ms 8656 KB Output is correct
8 Correct 4 ms 8656 KB Output is correct
9 Correct 4 ms 8528 KB Output is correct
10 Correct 4 ms 8656 KB Output is correct
11 Correct 4 ms 8656 KB Output is correct
12 Correct 4 ms 8656 KB Output is correct
13 Correct 4 ms 8656 KB Output is correct
14 Correct 4 ms 8656 KB Output is correct
15 Correct 6 ms 8656 KB Output is correct
16 Correct 4 ms 8620 KB Output is correct
17 Correct 5 ms 8656 KB Output is correct
18 Correct 4 ms 8784 KB Output is correct
19 Correct 4 ms 8784 KB Output is correct
20 Correct 4 ms 8640 KB Output is correct
21 Correct 4 ms 8656 KB Output is correct
22 Correct 4 ms 8656 KB Output is correct
23 Correct 4 ms 8656 KB Output is correct
24 Correct 4 ms 8656 KB Output is correct
25 Correct 4 ms 8656 KB Output is correct
26 Correct 5 ms 8656 KB Output is correct
27 Correct 5 ms 8736 KB Output is correct
28 Correct 5 ms 8656 KB Output is correct
29 Correct 4 ms 8664 KB Output is correct
30 Correct 4 ms 8656 KB Output is correct
31 Correct 5 ms 8784 KB Output is correct
32 Correct 5 ms 8656 KB Output is correct
33 Correct 5 ms 8656 KB Output is correct
34 Correct 4 ms 8656 KB Output is correct
35 Correct 4 ms 8656 KB Output is correct
36 Correct 4 ms 8784 KB Output is correct
37 Correct 5 ms 8784 KB Output is correct
38 Correct 4 ms 8900 KB Output is correct
39 Correct 4 ms 8656 KB Output is correct
40 Correct 4 ms 8656 KB Output is correct
41 Correct 4 ms 8656 KB Output is correct
42 Correct 4 ms 8656 KB Output is correct
43 Correct 595 ms 8912 KB Output is correct
44 Correct 609 ms 8912 KB Output is correct
45 Correct 619 ms 8888 KB Output is correct
46 Correct 615 ms 9140 KB Output is correct
47 Correct 723 ms 9168 KB Output is correct
48 Correct 750 ms 9144 KB Output is correct
49 Correct 652 ms 9168 KB Output is correct
50 Correct 615 ms 9204 KB Output is correct
51 Correct 663 ms 9080 KB Output is correct
52 Correct 602 ms 9088 KB Output is correct
53 Correct 781 ms 9504 KB Output is correct
54 Correct 759 ms 9168 KB Output is correct
55 Correct 685 ms 9040 KB Output is correct
56 Correct 627 ms 9040 KB Output is correct
57 Correct 762 ms 8912 KB Output is correct
58 Correct 639 ms 9808 KB Output is correct
59 Correct 727 ms 9936 KB Output is correct
60 Correct 724 ms 9936 KB Output is correct
61 Correct 674 ms 9040 KB Output is correct
62 Correct 665 ms 8944 KB Output is correct
63 Correct 614 ms 8912 KB Output is correct
64 Correct 713 ms 8916 KB Output is correct
65 Correct 351 ms 8784 KB Output is correct
66 Correct 749 ms 9040 KB Output is correct
67 Correct 558 ms 9040 KB Output is correct
68 Correct 594 ms 9016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8528 KB Output is correct
2 Correct 4 ms 8528 KB Output is correct
3 Correct 4 ms 8656 KB Output is correct
4 Correct 4 ms 8632 KB Output is correct
5 Correct 4 ms 8656 KB Output is correct
6 Correct 4 ms 8656 KB Output is correct
7 Correct 4 ms 8656 KB Output is correct
8 Correct 4 ms 8656 KB Output is correct
9 Correct 4 ms 8528 KB Output is correct
10 Correct 4 ms 8656 KB Output is correct
11 Correct 4 ms 8656 KB Output is correct
12 Correct 4 ms 8656 KB Output is correct
13 Correct 4 ms 8656 KB Output is correct
14 Correct 4 ms 8656 KB Output is correct
15 Correct 6 ms 8656 KB Output is correct
16 Correct 4 ms 8620 KB Output is correct
17 Correct 5 ms 8656 KB Output is correct
18 Correct 4 ms 8784 KB Output is correct
19 Correct 4 ms 8784 KB Output is correct
20 Correct 4 ms 8640 KB Output is correct
21 Correct 4 ms 8656 KB Output is correct
22 Correct 4 ms 8656 KB Output is correct
23 Correct 4 ms 8656 KB Output is correct
24 Correct 4 ms 8656 KB Output is correct
25 Correct 4 ms 8656 KB Output is correct
26 Correct 5 ms 8656 KB Output is correct
27 Correct 5 ms 8736 KB Output is correct
28 Correct 5 ms 8656 KB Output is correct
29 Correct 4 ms 8664 KB Output is correct
30 Correct 4 ms 8656 KB Output is correct
31 Correct 5 ms 8784 KB Output is correct
32 Correct 5 ms 8656 KB Output is correct
33 Correct 5 ms 8656 KB Output is correct
34 Correct 4 ms 8656 KB Output is correct
35 Correct 4 ms 8656 KB Output is correct
36 Correct 4 ms 8784 KB Output is correct
37 Correct 5 ms 8784 KB Output is correct
38 Correct 4 ms 8900 KB Output is correct
39 Correct 4 ms 8656 KB Output is correct
40 Correct 4 ms 8656 KB Output is correct
41 Correct 4 ms 8656 KB Output is correct
42 Correct 4 ms 8656 KB Output is correct
43 Correct 487 ms 12476 KB Output is correct
44 Correct 742 ms 16236 KB Output is correct
45 Correct 704 ms 16200 KB Output is correct
46 Correct 670 ms 15548 KB Output is correct
47 Correct 498 ms 12488 KB Output is correct
48 Correct 559 ms 16248 KB Output is correct
49 Correct 958 ms 16316 KB Output is correct
50 Correct 692 ms 16328 KB Output is correct
51 Correct 287 ms 8784 KB Output is correct
52 Correct 729 ms 9040 KB Output is correct
53 Correct 827 ms 9040 KB Output is correct
54 Correct 709 ms 9040 KB Output is correct
55 Correct 781 ms 20164 KB Output is correct
56 Correct 792 ms 20396 KB Output is correct
57 Correct 869 ms 20288 KB Output is correct
58 Correct 644 ms 20304 KB Output is correct
59 Correct 737 ms 34372 KB Output is correct
60 Correct 703 ms 34420 KB Output is correct
61 Correct 595 ms 8912 KB Output is correct
62 Correct 609 ms 8912 KB Output is correct
63 Correct 619 ms 8888 KB Output is correct
64 Correct 615 ms 9140 KB Output is correct
65 Correct 723 ms 9168 KB Output is correct
66 Correct 750 ms 9144 KB Output is correct
67 Correct 652 ms 9168 KB Output is correct
68 Correct 615 ms 9204 KB Output is correct
69 Correct 663 ms 9080 KB Output is correct
70 Correct 602 ms 9088 KB Output is correct
71 Correct 781 ms 9504 KB Output is correct
72 Correct 759 ms 9168 KB Output is correct
73 Correct 685 ms 9040 KB Output is correct
74 Correct 627 ms 9040 KB Output is correct
75 Correct 762 ms 8912 KB Output is correct
76 Correct 639 ms 9808 KB Output is correct
77 Correct 727 ms 9936 KB Output is correct
78 Correct 724 ms 9936 KB Output is correct
79 Correct 674 ms 9040 KB Output is correct
80 Correct 665 ms 8944 KB Output is correct
81 Correct 614 ms 8912 KB Output is correct
82 Correct 713 ms 8916 KB Output is correct
83 Correct 351 ms 8784 KB Output is correct
84 Correct 749 ms 9040 KB Output is correct
85 Correct 558 ms 9040 KB Output is correct
86 Correct 594 ms 9016 KB Output is correct
87 Correct 4 ms 8528 KB Output is correct
88 Correct 512 ms 18876 KB Output is correct
89 Correct 678 ms 15664 KB Output is correct
90 Correct 625 ms 15688 KB Output is correct
91 Correct 861 ms 20400 KB Output is correct
92 Correct 945 ms 20428 KB Output is correct
93 Correct 961 ms 19356 KB Output is correct
94 Correct 737 ms 20404 KB Output is correct
95 Correct 658 ms 20424 KB Output is correct
96 Correct 621 ms 16168 KB Output is correct
97 Correct 728 ms 16152 KB Output is correct
98 Correct 621 ms 27204 KB Output is correct
99 Correct 940 ms 20304 KB Output is correct
100 Correct 948 ms 17964 KB Output is correct
101 Correct 863 ms 17224 KB Output is correct
102 Correct 860 ms 16116 KB Output is correct
103 Correct 672 ms 34376 KB Output is correct
104 Correct 880 ms 34868 KB Output is correct
105 Correct 620 ms 34952 KB Output is correct
106 Correct 751 ms 18228 KB Output is correct
107 Correct 668 ms 15156 KB Output is correct
108 Correct 698 ms 15528 KB Output is correct
109 Correct 775 ms 16168 KB Output is correct