답안 #637192

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637192 2022-08-31T22:20:31 Z blue 디지털 회로 (IOI22_circuit) C++17
100 / 100
1154 ms 46092 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define sz(x) int(x.size())

const ll mod = 1'000'002'022;

ll ad(ll a, ll b)
{
	return (a+b)%mod;
}

ll mul(ll a, ll b)
{
	return (a*b)%mod;
}

const int mx = 200'000;

vll Z(1 + mx, 0);
vll Zprod(1 + mx, 1);

vll coeff(1 + mx, 0);


vi children[1 + mx];
int N, M;

vi A;

ll res = 0;

void dfs(int u)
{
	for(int v : children[u])
	{
		Z[u]++;
		dfs(v);

		if(Z[v] != 0)
			Zprod[u] = mul(Zprod[u], Zprod[v]);
	}

	if(Z[u] != 0)
		Zprod[u] = mul(Zprod[u], Z[u]);

	// cerr << u << " : " << Z[u] << " | " << Zprod[u] << '\n';
}

void dfs2(int u, ll curr)
{
	coeff[u] = curr;
	// cerr << u << " -> " << curr << '\n';

	ll fwd[1 + sz(children[u]) + 1];
	ll bwd[1 + sz(children[u]) + 1];

	fwd[0] = 1;
	for(int e = 1; e <= sz(children[u]); e++)
		fwd[e] = mul(fwd[e-1], Zprod[ children[u][e - 1] ]);

	bwd[sz(children[u]) + 1] = 1;
	for(int e = sz(children[u]); e >= 1; e--)
		bwd[e] = mul(bwd[e+1], Zprod[ children[u][e - 1] ]);

	for(int e = 1; e <= sz(children[u]); e++)
	{
		// cerr << e << " : " << curr << ' ' << fwd[e-1] << ' ' << bwd[e+1] << '\n';
		dfs2(children[u][e - 1], mul(curr, mul(fwd[e-1], bwd[e+1])));
	}
}

struct segtree
{
	int l;
	int r;
	ll v[2];

	int lp = 0; //1 -> flip 0 and 1

	segtree* left = NULL;
	segtree* right = NULL;

	segtree()
	{
		;
	}

	segtree(int L, int R)
	{
		l = L;
		r = R;
		if(l == r)
		{
			if(A[l])
			{
				v[0] = coeff[l];
				v[1] = 0;
			}
			else
			{
				v[0] = 0;
				v[1] = coeff[l];
			}
		}
		else
		{
			int m = (l+r)/2;
			left = new segtree(l, m);
			right = new segtree(m+1, r);

			v[0] = ad(left->v[0], right->v[0]);
			v[1] = ad(left->v[1], right->v[1]);
		}	
	}

	void flip(int L, int R)
	{
		if(R < l || r < L) return;
		else if(L <= l && r <= R)
		{
			lp = !lp;
			swap(v[0], v[1]);
		}
		else
		{
			left->flip(L, R);
			right->flip(L, R);

			v[0 ^ lp] = ad(left->v[0], right->v[0]);
			v[1 ^ lp] = ad(left->v[1], right->v[1]);
		}
	}
};

segtree S;

void init(int N_, int M_, vi P_, vi A_)
{
	N = N_;
	M = M_;

	for(int i = 1; i < N+M; i++)
		children[P_[i]].push_back(i);

	dfs(0);
	dfs2(0, 1);

	A = vi(N, -1);
	for(int a : A_)
		A.push_back(a);

	S = segtree(N, N+M-1);
}

int count_ways(int L, int R)
{
	S.flip(L, R);
	return S.v[0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9680 KB Output is correct
2 Correct 5 ms 9680 KB Output is correct
3 Correct 6 ms 9808 KB Output is correct
4 Correct 5 ms 9868 KB Output is correct
5 Correct 5 ms 9808 KB Output is correct
6 Correct 5 ms 9808 KB Output is correct
7 Correct 7 ms 9808 KB Output is correct
8 Correct 5 ms 9808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9680 KB Output is correct
2 Correct 5 ms 9680 KB Output is correct
3 Correct 5 ms 9680 KB Output is correct
4 Correct 5 ms 9784 KB Output is correct
5 Correct 5 ms 9808 KB Output is correct
6 Correct 5 ms 9804 KB Output is correct
7 Correct 6 ms 9808 KB Output is correct
8 Correct 5 ms 9868 KB Output is correct
9 Correct 5 ms 9808 KB Output is correct
10 Correct 5 ms 9936 KB Output is correct
11 Correct 5 ms 9936 KB Output is correct
12 Correct 5 ms 9808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9680 KB Output is correct
2 Correct 5 ms 9680 KB Output is correct
3 Correct 6 ms 9808 KB Output is correct
4 Correct 5 ms 9868 KB Output is correct
5 Correct 5 ms 9808 KB Output is correct
6 Correct 5 ms 9808 KB Output is correct
7 Correct 7 ms 9808 KB Output is correct
8 Correct 5 ms 9808 KB Output is correct
9 Correct 6 ms 9680 KB Output is correct
10 Correct 5 ms 9680 KB Output is correct
11 Correct 5 ms 9680 KB Output is correct
12 Correct 5 ms 9784 KB Output is correct
13 Correct 5 ms 9808 KB Output is correct
14 Correct 5 ms 9804 KB Output is correct
15 Correct 6 ms 9808 KB Output is correct
16 Correct 5 ms 9868 KB Output is correct
17 Correct 5 ms 9808 KB Output is correct
18 Correct 5 ms 9936 KB Output is correct
19 Correct 5 ms 9936 KB Output is correct
20 Correct 5 ms 9808 KB Output is correct
21 Correct 8 ms 9808 KB Output is correct
22 Correct 6 ms 9812 KB Output is correct
23 Correct 5 ms 9680 KB Output is correct
24 Correct 4 ms 9808 KB Output is correct
25 Correct 6 ms 9828 KB Output is correct
26 Correct 5 ms 9896 KB Output is correct
27 Correct 5 ms 9808 KB Output is correct
28 Correct 6 ms 9864 KB Output is correct
29 Correct 7 ms 9808 KB Output is correct
30 Correct 5 ms 9808 KB Output is correct
31 Correct 5 ms 9808 KB Output is correct
32 Correct 5 ms 9808 KB Output is correct
33 Correct 5 ms 9808 KB Output is correct
34 Correct 5 ms 9808 KB Output is correct
35 Correct 5 ms 9808 KB Output is correct
36 Correct 5 ms 9936 KB Output is correct
37 Correct 7 ms 10064 KB Output is correct
38 Correct 6 ms 10064 KB Output is correct
39 Correct 5 ms 9808 KB Output is correct
40 Correct 7 ms 9808 KB Output is correct
41 Correct 5 ms 9808 KB Output is correct
42 Correct 5 ms 9808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 715 ms 15800 KB Output is correct
2 Correct 747 ms 22012 KB Output is correct
3 Correct 688 ms 21980 KB Output is correct
4 Correct 981 ms 21984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 715 ms 15800 KB Output is correct
2 Correct 747 ms 22012 KB Output is correct
3 Correct 688 ms 21980 KB Output is correct
4 Correct 981 ms 21984 KB Output is correct
5 Correct 753 ms 15848 KB Output is correct
6 Correct 931 ms 21988 KB Output is correct
7 Correct 1043 ms 21988 KB Output is correct
8 Correct 703 ms 21952 KB Output is correct
9 Correct 502 ms 10076 KB Output is correct
10 Correct 832 ms 10460 KB Output is correct
11 Correct 891 ms 10464 KB Output is correct
12 Correct 786 ms 10460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9680 KB Output is correct
2 Correct 5 ms 9680 KB Output is correct
3 Correct 5 ms 9680 KB Output is correct
4 Correct 5 ms 9784 KB Output is correct
5 Correct 5 ms 9808 KB Output is correct
6 Correct 5 ms 9804 KB Output is correct
7 Correct 6 ms 9808 KB Output is correct
8 Correct 5 ms 9868 KB Output is correct
9 Correct 5 ms 9808 KB Output is correct
10 Correct 5 ms 9936 KB Output is correct
11 Correct 5 ms 9936 KB Output is correct
12 Correct 5 ms 9808 KB Output is correct
13 Correct 715 ms 15800 KB Output is correct
14 Correct 747 ms 22012 KB Output is correct
15 Correct 688 ms 21980 KB Output is correct
16 Correct 981 ms 21984 KB Output is correct
17 Correct 753 ms 15848 KB Output is correct
18 Correct 931 ms 21988 KB Output is correct
19 Correct 1043 ms 21988 KB Output is correct
20 Correct 703 ms 21952 KB Output is correct
21 Correct 502 ms 10076 KB Output is correct
22 Correct 832 ms 10460 KB Output is correct
23 Correct 891 ms 10464 KB Output is correct
24 Correct 786 ms 10460 KB Output is correct
25 Correct 1027 ms 28120 KB Output is correct
26 Correct 915 ms 28464 KB Output is correct
27 Correct 725 ms 28372 KB Output is correct
28 Correct 887 ms 28472 KB Output is correct
29 Correct 970 ms 44104 KB Output is correct
30 Correct 929 ms 44120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9680 KB Output is correct
2 Correct 5 ms 9680 KB Output is correct
3 Correct 6 ms 9808 KB Output is correct
4 Correct 5 ms 9868 KB Output is correct
5 Correct 5 ms 9808 KB Output is correct
6 Correct 5 ms 9808 KB Output is correct
7 Correct 7 ms 9808 KB Output is correct
8 Correct 5 ms 9808 KB Output is correct
9 Correct 6 ms 9680 KB Output is correct
10 Correct 5 ms 9680 KB Output is correct
11 Correct 5 ms 9680 KB Output is correct
12 Correct 5 ms 9784 KB Output is correct
13 Correct 5 ms 9808 KB Output is correct
14 Correct 5 ms 9804 KB Output is correct
15 Correct 6 ms 9808 KB Output is correct
16 Correct 5 ms 9868 KB Output is correct
17 Correct 5 ms 9808 KB Output is correct
18 Correct 5 ms 9936 KB Output is correct
19 Correct 5 ms 9936 KB Output is correct
20 Correct 5 ms 9808 KB Output is correct
21 Correct 8 ms 9808 KB Output is correct
22 Correct 6 ms 9812 KB Output is correct
23 Correct 5 ms 9680 KB Output is correct
24 Correct 4 ms 9808 KB Output is correct
25 Correct 6 ms 9828 KB Output is correct
26 Correct 5 ms 9896 KB Output is correct
27 Correct 5 ms 9808 KB Output is correct
28 Correct 6 ms 9864 KB Output is correct
29 Correct 7 ms 9808 KB Output is correct
30 Correct 5 ms 9808 KB Output is correct
31 Correct 5 ms 9808 KB Output is correct
32 Correct 5 ms 9808 KB Output is correct
33 Correct 5 ms 9808 KB Output is correct
34 Correct 5 ms 9808 KB Output is correct
35 Correct 5 ms 9808 KB Output is correct
36 Correct 5 ms 9936 KB Output is correct
37 Correct 7 ms 10064 KB Output is correct
38 Correct 6 ms 10064 KB Output is correct
39 Correct 5 ms 9808 KB Output is correct
40 Correct 7 ms 9808 KB Output is correct
41 Correct 5 ms 9808 KB Output is correct
42 Correct 5 ms 9808 KB Output is correct
43 Correct 583 ms 10216 KB Output is correct
44 Correct 829 ms 10232 KB Output is correct
45 Correct 906 ms 10248 KB Output is correct
46 Correct 698 ms 10632 KB Output is correct
47 Correct 846 ms 10632 KB Output is correct
48 Correct 645 ms 10644 KB Output is correct
49 Correct 928 ms 10628 KB Output is correct
50 Correct 718 ms 10632 KB Output is correct
51 Correct 867 ms 10512 KB Output is correct
52 Correct 966 ms 10504 KB Output is correct
53 Correct 776 ms 10704 KB Output is correct
54 Correct 908 ms 10624 KB Output is correct
55 Correct 896 ms 10528 KB Output is correct
56 Correct 737 ms 10492 KB Output is correct
57 Correct 936 ms 10448 KB Output is correct
58 Correct 804 ms 11412 KB Output is correct
59 Correct 878 ms 11508 KB Output is correct
60 Correct 792 ms 11500 KB Output is correct
61 Correct 682 ms 10376 KB Output is correct
62 Correct 909 ms 10288 KB Output is correct
63 Correct 927 ms 10320 KB Output is correct
64 Correct 777 ms 10456 KB Output is correct
65 Correct 498 ms 10076 KB Output is correct
66 Correct 933 ms 10464 KB Output is correct
67 Correct 638 ms 10460 KB Output is correct
68 Correct 909 ms 10468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9680 KB Output is correct
2 Correct 5 ms 9680 KB Output is correct
3 Correct 6 ms 9808 KB Output is correct
4 Correct 5 ms 9868 KB Output is correct
5 Correct 5 ms 9808 KB Output is correct
6 Correct 5 ms 9808 KB Output is correct
7 Correct 7 ms 9808 KB Output is correct
8 Correct 5 ms 9808 KB Output is correct
9 Correct 6 ms 9680 KB Output is correct
10 Correct 5 ms 9680 KB Output is correct
11 Correct 5 ms 9680 KB Output is correct
12 Correct 5 ms 9784 KB Output is correct
13 Correct 5 ms 9808 KB Output is correct
14 Correct 5 ms 9804 KB Output is correct
15 Correct 6 ms 9808 KB Output is correct
16 Correct 5 ms 9868 KB Output is correct
17 Correct 5 ms 9808 KB Output is correct
18 Correct 5 ms 9936 KB Output is correct
19 Correct 5 ms 9936 KB Output is correct
20 Correct 5 ms 9808 KB Output is correct
21 Correct 8 ms 9808 KB Output is correct
22 Correct 6 ms 9812 KB Output is correct
23 Correct 5 ms 9680 KB Output is correct
24 Correct 4 ms 9808 KB Output is correct
25 Correct 6 ms 9828 KB Output is correct
26 Correct 5 ms 9896 KB Output is correct
27 Correct 5 ms 9808 KB Output is correct
28 Correct 6 ms 9864 KB Output is correct
29 Correct 7 ms 9808 KB Output is correct
30 Correct 5 ms 9808 KB Output is correct
31 Correct 5 ms 9808 KB Output is correct
32 Correct 5 ms 9808 KB Output is correct
33 Correct 5 ms 9808 KB Output is correct
34 Correct 5 ms 9808 KB Output is correct
35 Correct 5 ms 9808 KB Output is correct
36 Correct 5 ms 9936 KB Output is correct
37 Correct 7 ms 10064 KB Output is correct
38 Correct 6 ms 10064 KB Output is correct
39 Correct 5 ms 9808 KB Output is correct
40 Correct 7 ms 9808 KB Output is correct
41 Correct 5 ms 9808 KB Output is correct
42 Correct 5 ms 9808 KB Output is correct
43 Correct 715 ms 15800 KB Output is correct
44 Correct 747 ms 22012 KB Output is correct
45 Correct 688 ms 21980 KB Output is correct
46 Correct 981 ms 21984 KB Output is correct
47 Correct 753 ms 15848 KB Output is correct
48 Correct 931 ms 21988 KB Output is correct
49 Correct 1043 ms 21988 KB Output is correct
50 Correct 703 ms 21952 KB Output is correct
51 Correct 502 ms 10076 KB Output is correct
52 Correct 832 ms 10460 KB Output is correct
53 Correct 891 ms 10464 KB Output is correct
54 Correct 786 ms 10460 KB Output is correct
55 Correct 1027 ms 28120 KB Output is correct
56 Correct 915 ms 28464 KB Output is correct
57 Correct 725 ms 28372 KB Output is correct
58 Correct 887 ms 28472 KB Output is correct
59 Correct 970 ms 44104 KB Output is correct
60 Correct 929 ms 44120 KB Output is correct
61 Correct 583 ms 10216 KB Output is correct
62 Correct 829 ms 10232 KB Output is correct
63 Correct 906 ms 10248 KB Output is correct
64 Correct 698 ms 10632 KB Output is correct
65 Correct 846 ms 10632 KB Output is correct
66 Correct 645 ms 10644 KB Output is correct
67 Correct 928 ms 10628 KB Output is correct
68 Correct 718 ms 10632 KB Output is correct
69 Correct 867 ms 10512 KB Output is correct
70 Correct 966 ms 10504 KB Output is correct
71 Correct 776 ms 10704 KB Output is correct
72 Correct 908 ms 10624 KB Output is correct
73 Correct 896 ms 10528 KB Output is correct
74 Correct 737 ms 10492 KB Output is correct
75 Correct 936 ms 10448 KB Output is correct
76 Correct 804 ms 11412 KB Output is correct
77 Correct 878 ms 11508 KB Output is correct
78 Correct 792 ms 11500 KB Output is correct
79 Correct 682 ms 10376 KB Output is correct
80 Correct 909 ms 10288 KB Output is correct
81 Correct 927 ms 10320 KB Output is correct
82 Correct 777 ms 10456 KB Output is correct
83 Correct 498 ms 10076 KB Output is correct
84 Correct 933 ms 10464 KB Output is correct
85 Correct 638 ms 10460 KB Output is correct
86 Correct 909 ms 10468 KB Output is correct
87 Correct 4 ms 9680 KB Output is correct
88 Correct 618 ms 25704 KB Output is correct
89 Correct 967 ms 20140 KB Output is correct
90 Correct 948 ms 20796 KB Output is correct
91 Correct 837 ms 28588 KB Output is correct
92 Correct 1126 ms 28516 KB Output is correct
93 Correct 1142 ms 28484 KB Output is correct
94 Correct 1154 ms 28480 KB Output is correct
95 Correct 1148 ms 28528 KB Output is correct
96 Correct 999 ms 26120 KB Output is correct
97 Correct 999 ms 26080 KB Output is correct
98 Correct 859 ms 29936 KB Output is correct
99 Correct 911 ms 28460 KB Output is correct
100 Correct 1081 ms 26324 KB Output is correct
101 Correct 1153 ms 25724 KB Output is correct
102 Correct 1027 ms 24620 KB Output is correct
103 Correct 1138 ms 44096 KB Output is correct
104 Correct 1080 ms 46020 KB Output is correct
105 Correct 898 ms 46092 KB Output is correct
106 Correct 950 ms 22552 KB Output is correct
107 Correct 1045 ms 20980 KB Output is correct
108 Correct 1018 ms 22220 KB Output is correct
109 Correct 939 ms 24712 KB Output is correct