답안 #1030714

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030714 2024-07-22T09:00:59 Z 42kangaroo 디지털 회로 (IOI22_circuit) C++17
100 / 100
771 ms 36032 KB
#include "circuit.h"

#include <vector>

using namespace std;

vector<int> a;
using g_t = vector<vector<int>>;
g_t g;

using ll = long long;

constexpr ll mod = 1000002022;

struct SVal {
	ll pos, fpos;
};

SVal comb(SVal l, SVal r) {
	return SVal{(l.pos + r.pos)%mod, (l.fpos + r.fpos)%mod};
}

struct SegTe {
	vector<SVal> a;
	vector<bool> lazy;

	void push(int i) {
		if (lazy[i]) {
			swap(a[i].pos, a[i].fpos);
			if (2 * i + 2 < a.size()) {
				lazy[2 * i + 1] = !lazy[2 * i + 1];
				lazy[2 * i + 2] = !lazy[2 * i + 2];
			}
			lazy[i] = false;
		}
	}

	SVal toggle(int l, int r, int i, int lq, int rq) {
		push(i);
		if (rq <= l || r <= lq) return a[i];
		if (lq <= l && r <= rq) {
			lazy[i] = true;
			push(i);
			return a[i];
		}
		int m = (l + r) / 2;
		return a[i] = comb(toggle(l, m, 2 * i + 1, lq, rq), toggle(m, r, 2 * i + 2, lq, rq));
	}

	SVal set(int l, int r, int i, int k, int pos, int fpos) {
		if (k < l || k >= r) return a[i];
		if (l + 1 == r) {
			return a[i] = {pos, fpos};
		}
		int m = (l + r)/2;
		return a[i] = comb(set(l, m, 2*i + 1, k, pos, fpos), set(m, r, 2*i + 2, k, pos, fpos));
	}
};

SegTe se;
int n, m;

ll dfs(int t, vector<vector<ll>>& re) {
	if (t >= n) return 1;
	re[t].resize(g[t].size());
	ll tot = g[t].size();
	for (int i = 0; i < g[t].size(); ++i) {
		re[t][i] = dfs(g[t][i], re);
		tot = (tot*re[t][i])%mod;
	}
	return tot;
}

void dfs2(int t, ll to, vector<vector<ll>>& re, vector<ll>& st) {
	if (t >= n) {
		st[t - n] = to;
		return;
	}
	vector<ll> suffMu(re[t].size() + 1, 1);
	for (int i = re[t].size() - 1; i >= 0; --i) {
		suffMu[i] = (suffMu[i + 1]*re[t][i])%mod;
	}
	ll mu = 1;
	for (int i = 0; i < re[t].size(); ++i) {
		dfs2(g[t][i], (((to*mu)%mod)*suffMu[i + 1])%mod, re, st);
		mu = (mu*re[t][i])%mod;
	}
}

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
	n = N; m = M;
	g = g_t(N);
	for (int i = 1; i < N + M; ++i) {
		g[P[i]].push_back(i);
	}
	vector<vector<ll>> re(N);
	dfs(0, re);
	vector<ll> res(M);
	dfs2(0, 1, re, res);
	se = SegTe{vector<SVal>(4*M), vector<bool>(4*M, false)};
	for (int i = 0; i < M; ++i) {
		if (A[i] == 1) {
			se.set(0, M, 0, i, res[i], 0);
		} else {
			se.set(0, M, 0, i, 0, res[i]);
		}
	}
}

int count_ways(int L, int R) {
	L -= n;
	R -= n;
	return se.toggle(0, m, 0, L, R + 1).pos;
}

Compilation message

circuit.cpp: In member function 'void SegTe::push(int)':
circuit.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<SVal>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |    if (2 * i + 2 < a.size()) {
      |        ~~~~~~~~~~^~~~~~~~~~
circuit.cpp: In function 'll dfs(int, std::vector<std::vector<long long int> >&)':
circuit.cpp:67:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for (int i = 0; i < g[t].size(); ++i) {
      |                  ~~^~~~~~~~~~~~~
circuit.cpp: In function 'void dfs2(int, ll, std::vector<std::vector<long long int> >&, std::vector<long long int>&)':
circuit.cpp:84:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |  for (int i = 0; i < re[t].size(); ++i) {
      |                  ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 600 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 1 ms 612 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 624 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 459 ms 7000 KB Output is correct
2 Correct 703 ms 13652 KB Output is correct
3 Correct 622 ms 13572 KB Output is correct
4 Correct 665 ms 13656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 459 ms 7000 KB Output is correct
2 Correct 703 ms 13652 KB Output is correct
3 Correct 622 ms 13572 KB Output is correct
4 Correct 665 ms 13656 KB Output is correct
5 Correct 541 ms 7060 KB Output is correct
6 Correct 733 ms 13744 KB Output is correct
7 Correct 705 ms 13656 KB Output is correct
8 Correct 570 ms 13724 KB Output is correct
9 Correct 285 ms 600 KB Output is correct
10 Correct 603 ms 1112 KB Output is correct
11 Correct 634 ms 1112 KB Output is correct
12 Correct 621 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 459 ms 7000 KB Output is correct
14 Correct 703 ms 13652 KB Output is correct
15 Correct 622 ms 13572 KB Output is correct
16 Correct 665 ms 13656 KB Output is correct
17 Correct 541 ms 7060 KB Output is correct
18 Correct 733 ms 13744 KB Output is correct
19 Correct 705 ms 13656 KB Output is correct
20 Correct 570 ms 13724 KB Output is correct
21 Correct 285 ms 600 KB Output is correct
22 Correct 603 ms 1112 KB Output is correct
23 Correct 634 ms 1112 KB Output is correct
24 Correct 621 ms 1112 KB Output is correct
25 Correct 597 ms 20376 KB Output is correct
26 Correct 647 ms 20816 KB Output is correct
27 Correct 601 ms 20612 KB Output is correct
28 Correct 507 ms 20616 KB Output is correct
29 Correct 676 ms 34640 KB Output is correct
30 Correct 635 ms 34836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 600 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 1 ms 612 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 624 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 400 ms 856 KB Output is correct
44 Correct 626 ms 1112 KB Output is correct
45 Correct 667 ms 856 KB Output is correct
46 Correct 601 ms 1368 KB Output is correct
47 Correct 666 ms 1368 KB Output is correct
48 Correct 606 ms 1620 KB Output is correct
49 Correct 616 ms 1368 KB Output is correct
50 Correct 602 ms 1368 KB Output is correct
51 Correct 575 ms 852 KB Output is correct
52 Correct 591 ms 856 KB Output is correct
53 Correct 564 ms 1624 KB Output is correct
54 Correct 629 ms 1368 KB Output is correct
55 Correct 581 ms 1112 KB Output is correct
56 Correct 621 ms 856 KB Output is correct
57 Correct 632 ms 856 KB Output is correct
58 Correct 679 ms 2136 KB Output is correct
59 Correct 683 ms 2136 KB Output is correct
60 Correct 607 ms 2136 KB Output is correct
61 Correct 649 ms 1112 KB Output is correct
62 Correct 675 ms 856 KB Output is correct
63 Correct 656 ms 856 KB Output is correct
64 Correct 611 ms 856 KB Output is correct
65 Correct 351 ms 600 KB Output is correct
66 Correct 685 ms 1112 KB Output is correct
67 Correct 627 ms 1112 KB Output is correct
68 Correct 575 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 600 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 1 ms 612 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 624 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 459 ms 7000 KB Output is correct
44 Correct 703 ms 13652 KB Output is correct
45 Correct 622 ms 13572 KB Output is correct
46 Correct 665 ms 13656 KB Output is correct
47 Correct 541 ms 7060 KB Output is correct
48 Correct 733 ms 13744 KB Output is correct
49 Correct 705 ms 13656 KB Output is correct
50 Correct 570 ms 13724 KB Output is correct
51 Correct 285 ms 600 KB Output is correct
52 Correct 603 ms 1112 KB Output is correct
53 Correct 634 ms 1112 KB Output is correct
54 Correct 621 ms 1112 KB Output is correct
55 Correct 597 ms 20376 KB Output is correct
56 Correct 647 ms 20816 KB Output is correct
57 Correct 601 ms 20612 KB Output is correct
58 Correct 507 ms 20616 KB Output is correct
59 Correct 676 ms 34640 KB Output is correct
60 Correct 635 ms 34836 KB Output is correct
61 Correct 400 ms 856 KB Output is correct
62 Correct 626 ms 1112 KB Output is correct
63 Correct 667 ms 856 KB Output is correct
64 Correct 601 ms 1368 KB Output is correct
65 Correct 666 ms 1368 KB Output is correct
66 Correct 606 ms 1620 KB Output is correct
67 Correct 616 ms 1368 KB Output is correct
68 Correct 602 ms 1368 KB Output is correct
69 Correct 575 ms 852 KB Output is correct
70 Correct 591 ms 856 KB Output is correct
71 Correct 564 ms 1624 KB Output is correct
72 Correct 629 ms 1368 KB Output is correct
73 Correct 581 ms 1112 KB Output is correct
74 Correct 621 ms 856 KB Output is correct
75 Correct 632 ms 856 KB Output is correct
76 Correct 679 ms 2136 KB Output is correct
77 Correct 683 ms 2136 KB Output is correct
78 Correct 607 ms 2136 KB Output is correct
79 Correct 649 ms 1112 KB Output is correct
80 Correct 675 ms 856 KB Output is correct
81 Correct 656 ms 856 KB Output is correct
82 Correct 611 ms 856 KB Output is correct
83 Correct 351 ms 600 KB Output is correct
84 Correct 685 ms 1112 KB Output is correct
85 Correct 627 ms 1112 KB Output is correct
86 Correct 575 ms 1112 KB Output is correct
87 Correct 0 ms 344 KB Output is correct
88 Correct 490 ms 18556 KB Output is correct
89 Correct 767 ms 13648 KB Output is correct
90 Correct 753 ms 13136 KB Output is correct
91 Correct 675 ms 21324 KB Output is correct
92 Correct 725 ms 21072 KB Output is correct
93 Correct 735 ms 21048 KB Output is correct
94 Correct 761 ms 21072 KB Output is correct
95 Correct 724 ms 21052 KB Output is correct
96 Correct 679 ms 10176 KB Output is correct
97 Correct 681 ms 10176 KB Output is correct
98 Correct 591 ms 26108 KB Output is correct
99 Correct 742 ms 20572 KB Output is correct
100 Correct 771 ms 14932 KB Output is correct
101 Correct 643 ms 12888 KB Output is correct
102 Correct 643 ms 10328 KB Output is correct
103 Correct 669 ms 34640 KB Output is correct
104 Correct 707 ms 35920 KB Output is correct
105 Correct 620 ms 36032 KB Output is correct
106 Correct 730 ms 16208 KB Output is correct
107 Correct 600 ms 11096 KB Output is correct
108 Correct 633 ms 10832 KB Output is correct
109 Correct 622 ms 10328 KB Output is correct