답안 #779722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779722 2023-07-11T17:33:18 Z IBory 디지털 회로 (IOI22_circuit) C++17
62 / 100
909 ms 17904 KB
#include "circuit.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const ll SZ = 1 << 17, 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) {
      |                  ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 2 ms 4560 KB Output is correct
4 Correct 2 ms 4568 KB Output is correct
5 Correct 2 ms 4560 KB Output is correct
6 Correct 2 ms 4560 KB Output is correct
7 Correct 3 ms 4560 KB Output is correct
8 Correct 3 ms 4552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 2 ms 4560 KB Output is correct
4 Correct 3 ms 4560 KB Output is correct
5 Correct 2 ms 4560 KB Output is correct
6 Correct 3 ms 4560 KB Output is correct
7 Correct 3 ms 4560 KB Output is correct
8 Correct 3 ms 4560 KB Output is correct
9 Correct 2 ms 4560 KB Output is correct
10 Correct 3 ms 4688 KB Output is correct
11 Correct 3 ms 4688 KB Output is correct
12 Correct 2 ms 4560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 2 ms 4560 KB Output is correct
4 Correct 2 ms 4568 KB Output is correct
5 Correct 2 ms 4560 KB Output is correct
6 Correct 2 ms 4560 KB Output is correct
7 Correct 3 ms 4560 KB Output is correct
8 Correct 3 ms 4552 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Correct 2 ms 4432 KB Output is correct
11 Correct 2 ms 4560 KB Output is correct
12 Correct 3 ms 4560 KB Output is correct
13 Correct 2 ms 4560 KB Output is correct
14 Correct 3 ms 4560 KB Output is correct
15 Correct 3 ms 4560 KB Output is correct
16 Correct 3 ms 4560 KB Output is correct
17 Correct 2 ms 4560 KB Output is correct
18 Correct 3 ms 4688 KB Output is correct
19 Correct 3 ms 4688 KB Output is correct
20 Correct 2 ms 4560 KB Output is correct
21 Correct 3 ms 4560 KB Output is correct
22 Correct 3 ms 4560 KB Output is correct
23 Correct 2 ms 4560 KB Output is correct
24 Correct 3 ms 4560 KB Output is correct
25 Correct 3 ms 4560 KB Output is correct
26 Correct 2 ms 4560 KB Output is correct
27 Correct 4 ms 4560 KB Output is correct
28 Correct 2 ms 4616 KB Output is correct
29 Correct 2 ms 4560 KB Output is correct
30 Correct 2 ms 4560 KB Output is correct
31 Correct 2 ms 4688 KB Output is correct
32 Correct 3 ms 4560 KB Output is correct
33 Correct 3 ms 4560 KB Output is correct
34 Correct 3 ms 4560 KB Output is correct
35 Correct 3 ms 4560 KB Output is correct
36 Correct 3 ms 4688 KB Output is correct
37 Correct 3 ms 4688 KB Output is correct
38 Correct 3 ms 4688 KB Output is correct
39 Correct 2 ms 4560 KB Output is correct
40 Correct 3 ms 4560 KB Output is correct
41 Correct 4 ms 4560 KB Output is correct
42 Correct 3 ms 4564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 625 ms 8264 KB Output is correct
2 Correct 808 ms 12108 KB Output is correct
3 Correct 897 ms 12116 KB Output is correct
4 Correct 909 ms 11420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 625 ms 8264 KB Output is correct
2 Correct 808 ms 12108 KB Output is correct
3 Correct 897 ms 12116 KB Output is correct
4 Correct 909 ms 11420 KB Output is correct
5 Correct 628 ms 8264 KB Output is correct
6 Correct 746 ms 12060 KB Output is correct
7 Correct 891 ms 12080 KB Output is correct
8 Correct 720 ms 12104 KB Output is correct
9 Correct 470 ms 4656 KB Output is correct
10 Correct 722 ms 4892 KB Output is correct
11 Correct 625 ms 4944 KB Output is correct
12 Correct 735 ms 4944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 2 ms 4560 KB Output is correct
4 Correct 3 ms 4560 KB Output is correct
5 Correct 2 ms 4560 KB Output is correct
6 Correct 3 ms 4560 KB Output is correct
7 Correct 3 ms 4560 KB Output is correct
8 Correct 3 ms 4560 KB Output is correct
9 Correct 2 ms 4560 KB Output is correct
10 Correct 3 ms 4688 KB Output is correct
11 Correct 3 ms 4688 KB Output is correct
12 Correct 2 ms 4560 KB Output is correct
13 Correct 625 ms 8264 KB Output is correct
14 Correct 808 ms 12108 KB Output is correct
15 Correct 897 ms 12116 KB Output is correct
16 Correct 909 ms 11420 KB Output is correct
17 Correct 628 ms 8264 KB Output is correct
18 Correct 746 ms 12060 KB Output is correct
19 Correct 891 ms 12080 KB Output is correct
20 Correct 720 ms 12104 KB Output is correct
21 Correct 470 ms 4656 KB Output is correct
22 Correct 722 ms 4892 KB Output is correct
23 Correct 625 ms 4944 KB Output is correct
24 Correct 735 ms 4944 KB Output is correct
25 Runtime error 52 ms 17904 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 2 ms 4560 KB Output is correct
4 Correct 2 ms 4568 KB Output is correct
5 Correct 2 ms 4560 KB Output is correct
6 Correct 2 ms 4560 KB Output is correct
7 Correct 3 ms 4560 KB Output is correct
8 Correct 3 ms 4552 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Correct 2 ms 4432 KB Output is correct
11 Correct 2 ms 4560 KB Output is correct
12 Correct 3 ms 4560 KB Output is correct
13 Correct 2 ms 4560 KB Output is correct
14 Correct 3 ms 4560 KB Output is correct
15 Correct 3 ms 4560 KB Output is correct
16 Correct 3 ms 4560 KB Output is correct
17 Correct 2 ms 4560 KB Output is correct
18 Correct 3 ms 4688 KB Output is correct
19 Correct 3 ms 4688 KB Output is correct
20 Correct 2 ms 4560 KB Output is correct
21 Correct 3 ms 4560 KB Output is correct
22 Correct 3 ms 4560 KB Output is correct
23 Correct 2 ms 4560 KB Output is correct
24 Correct 3 ms 4560 KB Output is correct
25 Correct 3 ms 4560 KB Output is correct
26 Correct 2 ms 4560 KB Output is correct
27 Correct 4 ms 4560 KB Output is correct
28 Correct 2 ms 4616 KB Output is correct
29 Correct 2 ms 4560 KB Output is correct
30 Correct 2 ms 4560 KB Output is correct
31 Correct 2 ms 4688 KB Output is correct
32 Correct 3 ms 4560 KB Output is correct
33 Correct 3 ms 4560 KB Output is correct
34 Correct 3 ms 4560 KB Output is correct
35 Correct 3 ms 4560 KB Output is correct
36 Correct 3 ms 4688 KB Output is correct
37 Correct 3 ms 4688 KB Output is correct
38 Correct 3 ms 4688 KB Output is correct
39 Correct 2 ms 4560 KB Output is correct
40 Correct 3 ms 4560 KB Output is correct
41 Correct 4 ms 4560 KB Output is correct
42 Correct 3 ms 4564 KB Output is correct
43 Correct 395 ms 4768 KB Output is correct
44 Correct 663 ms 4788 KB Output is correct
45 Correct 697 ms 4816 KB Output is correct
46 Correct 849 ms 5044 KB Output is correct
47 Correct 620 ms 5044 KB Output is correct
48 Correct 731 ms 5028 KB Output is correct
49 Correct 759 ms 5072 KB Output is correct
50 Correct 723 ms 5024 KB Output is correct
51 Correct 756 ms 4960 KB Output is correct
52 Correct 809 ms 4956 KB Output is correct
53 Correct 635 ms 5328 KB Output is correct
54 Correct 622 ms 5032 KB Output is correct
55 Correct 603 ms 4916 KB Output is correct
56 Correct 759 ms 4908 KB Output is correct
57 Correct 749 ms 4816 KB Output is correct
58 Correct 820 ms 5680 KB Output is correct
59 Correct 777 ms 5840 KB Output is correct
60 Correct 860 ms 5808 KB Output is correct
61 Correct 647 ms 4912 KB Output is correct
62 Correct 730 ms 4816 KB Output is correct
63 Correct 727 ms 4712 KB Output is correct
64 Correct 806 ms 4808 KB Output is correct
65 Correct 409 ms 4660 KB Output is correct
66 Correct 691 ms 4944 KB Output is correct
67 Correct 656 ms 4912 KB Output is correct
68 Correct 779 ms 4916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 2 ms 4560 KB Output is correct
4 Correct 2 ms 4568 KB Output is correct
5 Correct 2 ms 4560 KB Output is correct
6 Correct 2 ms 4560 KB Output is correct
7 Correct 3 ms 4560 KB Output is correct
8 Correct 3 ms 4552 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Correct 2 ms 4432 KB Output is correct
11 Correct 2 ms 4560 KB Output is correct
12 Correct 3 ms 4560 KB Output is correct
13 Correct 2 ms 4560 KB Output is correct
14 Correct 3 ms 4560 KB Output is correct
15 Correct 3 ms 4560 KB Output is correct
16 Correct 3 ms 4560 KB Output is correct
17 Correct 2 ms 4560 KB Output is correct
18 Correct 3 ms 4688 KB Output is correct
19 Correct 3 ms 4688 KB Output is correct
20 Correct 2 ms 4560 KB Output is correct
21 Correct 3 ms 4560 KB Output is correct
22 Correct 3 ms 4560 KB Output is correct
23 Correct 2 ms 4560 KB Output is correct
24 Correct 3 ms 4560 KB Output is correct
25 Correct 3 ms 4560 KB Output is correct
26 Correct 2 ms 4560 KB Output is correct
27 Correct 4 ms 4560 KB Output is correct
28 Correct 2 ms 4616 KB Output is correct
29 Correct 2 ms 4560 KB Output is correct
30 Correct 2 ms 4560 KB Output is correct
31 Correct 2 ms 4688 KB Output is correct
32 Correct 3 ms 4560 KB Output is correct
33 Correct 3 ms 4560 KB Output is correct
34 Correct 3 ms 4560 KB Output is correct
35 Correct 3 ms 4560 KB Output is correct
36 Correct 3 ms 4688 KB Output is correct
37 Correct 3 ms 4688 KB Output is correct
38 Correct 3 ms 4688 KB Output is correct
39 Correct 2 ms 4560 KB Output is correct
40 Correct 3 ms 4560 KB Output is correct
41 Correct 4 ms 4560 KB Output is correct
42 Correct 3 ms 4564 KB Output is correct
43 Correct 625 ms 8264 KB Output is correct
44 Correct 808 ms 12108 KB Output is correct
45 Correct 897 ms 12116 KB Output is correct
46 Correct 909 ms 11420 KB Output is correct
47 Correct 628 ms 8264 KB Output is correct
48 Correct 746 ms 12060 KB Output is correct
49 Correct 891 ms 12080 KB Output is correct
50 Correct 720 ms 12104 KB Output is correct
51 Correct 470 ms 4656 KB Output is correct
52 Correct 722 ms 4892 KB Output is correct
53 Correct 625 ms 4944 KB Output is correct
54 Correct 735 ms 4944 KB Output is correct
55 Runtime error 52 ms 17904 KB Execution killed with signal 11
56 Halted 0 ms 0 KB -