답안 #800707

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
800707 2023-08-01T18:40:52 Z dxz05 디지털 회로 (IOI22_circuit) C++17
100 / 100
997 ms 35912 KB
#include "circuit.h"
#include <bits/stdc++.h>
 
using namespace std;
 
const int MaxN = 200005;
const int MOD = 1e9 + 2022;

int binpow(int n, int k){
	int res = 1;
    while (k > 0){
        if (k & 1) res = 1LL * res * n % MOD;
        n = 1LL * n * n % MOD;
        k >>= 1;
    }
    return res;
}

int N, M;
vector<int> A;
 
int contribution[MaxN];
 
struct node{
	int sum;
	int sum2;
	bool flag;
	
	node(){
		sum = sum2 = 0;
		flag = false;
	};
};
 
node tree[4 * MaxN];
 
void flip(int v){
	swap(tree[v].sum, tree[v].sum2);
	tree[v].flag ^= 1;
}
 
void push(int v, int tl, int tr){
	if (tl == tr || !tree[v].flag) return;
	flip(v << 1);
	flip(v << 1 | 1);
	tree[v].flag = false;
}
 
void build(int v, int tl, int tr){
	if (tl == tr){
		tree[v].sum = A[tl - N] * contribution[tl];
		tree[v].sum2 = (!A[tl - N]) * contribution[tl];
		return;
	}
	int tm = (tl + tr) >> 1;
	build(v << 1, tl, tm);
	build(v << 1 | 1, tm + 1, tr);
	
	tree[v].sum = (tree[v << 1].sum + tree[v << 1 | 1].sum) % MOD;
	tree[v].sum2 = (tree[v << 1].sum2 + tree[v << 1 | 1].sum2) % MOD;
}
 
void update(int v, int tl, int tr, int l, int r){
	push(v, tl, tr);
	if (l <= tl && tr <= r){
		flip(v);
		return;
	}
	if (tl > r || tr < l) return;
	int tm = (tl + tr) >> 1;
	update(v << 1, tl, tm, l, r);
	update(v << 1 | 1, tm + 1, tr, l, r);
	
	tree[v].sum = (tree[v << 1].sum + tree[v << 1 | 1].sum) % MOD;
	tree[v].sum2 = (tree[v << 1].sum2 + tree[v << 1 | 1].sum2) % MOD;
}
 
void update(int l, int r){
	update(1, N, N + M - 1, l, r);
}
 
int get(){
	return tree[1].sum;
}
 
vector<int> g[MaxN];
 
long long sub[MaxN];

void dfs0(int v){
	sub[v] = 1;
	if (!g[v].empty()){
		sub[v] = sub[v] * (int) g[v].size() % MOD;
	}
	
	for (int u : g[v]){
		dfs0(u);
		sub[v] = sub[v] * sub[u] % MOD;		
	}
}

void dfs1(int v, long long up){
	int sz = (int) g[v].size();
	
	if (sz == 0){
		contribution[v] = up % MOD;
		return;
	}
	
	vector<long long> suff(sz, 1);
	for (int i = sz - 1; i >= 0; i--){
		int u = g[v][i];
		
		suff[i] = sub[u];
		if (i + 1 < sz) {
			suff[i] = suff[i] * suff[i + 1] % MOD;
		}
	}
	
	long long pref = 1;
	for (int i = 0; i < sz; i++){
		int u = g[v][i];
		
		long long ways = up * pref % MOD;
		if (i + 1 < sz) ways = ways * suff[i + 1] % MOD;
		
		dfs1(u, ways);
		
		pref = pref * sub[u] % MOD;		
	}
}

void init(int _N, int _M, vector<int> P, vector<int> _A) {
    N = _N, M = _M, A = _A;
    for (int i = 1; i < N + M; i++){
        g[P[i]].push_back(i);
    }
	
    dfs0(0);
    dfs1(0, 1);
        
    build(1, N, N + M - 1);
}
 
int count_ways(int L, int R) {
    update(L, R);
    return get();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14288 KB Output is correct
2 Correct 6 ms 14288 KB Output is correct
3 Correct 6 ms 14416 KB Output is correct
4 Correct 6 ms 14416 KB Output is correct
5 Correct 6 ms 14416 KB Output is correct
6 Correct 6 ms 14416 KB Output is correct
7 Correct 7 ms 14416 KB Output is correct
8 Correct 7 ms 14360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14316 KB Output is correct
2 Correct 6 ms 14416 KB Output is correct
3 Correct 7 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 7 ms 14416 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 8 ms 14412 KB Output is correct
8 Correct 6 ms 14416 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 7 ms 14544 KB Output is correct
11 Correct 6 ms 14544 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14288 KB Output is correct
2 Correct 6 ms 14288 KB Output is correct
3 Correct 6 ms 14416 KB Output is correct
4 Correct 6 ms 14416 KB Output is correct
5 Correct 6 ms 14416 KB Output is correct
6 Correct 6 ms 14416 KB Output is correct
7 Correct 7 ms 14416 KB Output is correct
8 Correct 7 ms 14360 KB Output is correct
9 Correct 8 ms 14316 KB Output is correct
10 Correct 6 ms 14416 KB Output is correct
11 Correct 7 ms 14416 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
13 Correct 7 ms 14416 KB Output is correct
14 Correct 7 ms 14416 KB Output is correct
15 Correct 8 ms 14412 KB Output is correct
16 Correct 6 ms 14416 KB Output is correct
17 Correct 9 ms 14416 KB Output is correct
18 Correct 7 ms 14544 KB Output is correct
19 Correct 6 ms 14544 KB Output is correct
20 Correct 7 ms 14416 KB Output is correct
21 Correct 6 ms 14416 KB Output is correct
22 Correct 6 ms 14416 KB Output is correct
23 Correct 7 ms 14416 KB Output is correct
24 Correct 8 ms 14456 KB Output is correct
25 Correct 7 ms 14444 KB Output is correct
26 Correct 7 ms 14416 KB Output is correct
27 Correct 6 ms 14416 KB Output is correct
28 Correct 6 ms 14416 KB Output is correct
29 Correct 6 ms 14416 KB Output is correct
30 Correct 7 ms 14332 KB Output is correct
31 Correct 6 ms 14552 KB Output is correct
32 Correct 8 ms 14576 KB Output is correct
33 Correct 7 ms 14416 KB Output is correct
34 Correct 7 ms 14416 KB Output is correct
35 Correct 7 ms 14432 KB Output is correct
36 Correct 7 ms 14544 KB Output is correct
37 Correct 7 ms 14544 KB Output is correct
38 Correct 7 ms 14544 KB Output is correct
39 Correct 6 ms 14416 KB Output is correct
40 Correct 7 ms 14416 KB Output is correct
41 Correct 6 ms 14416 KB Output is correct
42 Correct 7 ms 14376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 559 ms 16964 KB Output is correct
2 Correct 695 ms 19504 KB Output is correct
3 Correct 793 ms 19504 KB Output is correct
4 Correct 831 ms 19500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 559 ms 16964 KB Output is correct
2 Correct 695 ms 19504 KB Output is correct
3 Correct 793 ms 19504 KB Output is correct
4 Correct 831 ms 19500 KB Output is correct
5 Correct 663 ms 16968 KB Output is correct
6 Correct 881 ms 19528 KB Output is correct
7 Correct 826 ms 19508 KB Output is correct
8 Correct 723 ms 19524 KB Output is correct
9 Correct 414 ms 14544 KB Output is correct
10 Correct 730 ms 14672 KB Output is correct
11 Correct 440 ms 14672 KB Output is correct
12 Correct 709 ms 14672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14316 KB Output is correct
2 Correct 6 ms 14416 KB Output is correct
3 Correct 7 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 7 ms 14416 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 8 ms 14412 KB Output is correct
8 Correct 6 ms 14416 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 7 ms 14544 KB Output is correct
11 Correct 6 ms 14544 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
13 Correct 559 ms 16964 KB Output is correct
14 Correct 695 ms 19504 KB Output is correct
15 Correct 793 ms 19504 KB Output is correct
16 Correct 831 ms 19500 KB Output is correct
17 Correct 663 ms 16968 KB Output is correct
18 Correct 881 ms 19528 KB Output is correct
19 Correct 826 ms 19508 KB Output is correct
20 Correct 723 ms 19524 KB Output is correct
21 Correct 414 ms 14544 KB Output is correct
22 Correct 730 ms 14672 KB Output is correct
23 Correct 440 ms 14672 KB Output is correct
24 Correct 709 ms 14672 KB Output is correct
25 Correct 850 ms 22068 KB Output is correct
26 Correct 889 ms 22216 KB Output is correct
27 Correct 906 ms 22216 KB Output is correct
28 Correct 685 ms 22096 KB Output is correct
29 Correct 960 ms 34672 KB Output is correct
30 Correct 855 ms 34640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14288 KB Output is correct
2 Correct 6 ms 14288 KB Output is correct
3 Correct 6 ms 14416 KB Output is correct
4 Correct 6 ms 14416 KB Output is correct
5 Correct 6 ms 14416 KB Output is correct
6 Correct 6 ms 14416 KB Output is correct
7 Correct 7 ms 14416 KB Output is correct
8 Correct 7 ms 14360 KB Output is correct
9 Correct 8 ms 14316 KB Output is correct
10 Correct 6 ms 14416 KB Output is correct
11 Correct 7 ms 14416 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
13 Correct 7 ms 14416 KB Output is correct
14 Correct 7 ms 14416 KB Output is correct
15 Correct 8 ms 14412 KB Output is correct
16 Correct 6 ms 14416 KB Output is correct
17 Correct 9 ms 14416 KB Output is correct
18 Correct 7 ms 14544 KB Output is correct
19 Correct 6 ms 14544 KB Output is correct
20 Correct 7 ms 14416 KB Output is correct
21 Correct 6 ms 14416 KB Output is correct
22 Correct 6 ms 14416 KB Output is correct
23 Correct 7 ms 14416 KB Output is correct
24 Correct 8 ms 14456 KB Output is correct
25 Correct 7 ms 14444 KB Output is correct
26 Correct 7 ms 14416 KB Output is correct
27 Correct 6 ms 14416 KB Output is correct
28 Correct 6 ms 14416 KB Output is correct
29 Correct 6 ms 14416 KB Output is correct
30 Correct 7 ms 14332 KB Output is correct
31 Correct 6 ms 14552 KB Output is correct
32 Correct 8 ms 14576 KB Output is correct
33 Correct 7 ms 14416 KB Output is correct
34 Correct 7 ms 14416 KB Output is correct
35 Correct 7 ms 14432 KB Output is correct
36 Correct 7 ms 14544 KB Output is correct
37 Correct 7 ms 14544 KB Output is correct
38 Correct 7 ms 14544 KB Output is correct
39 Correct 6 ms 14416 KB Output is correct
40 Correct 7 ms 14416 KB Output is correct
41 Correct 6 ms 14416 KB Output is correct
42 Correct 7 ms 14376 KB Output is correct
43 Correct 529 ms 14524 KB Output is correct
44 Correct 615 ms 14672 KB Output is correct
45 Correct 678 ms 14544 KB Output is correct
46 Correct 641 ms 14672 KB Output is correct
47 Correct 767 ms 14672 KB Output is correct
48 Correct 724 ms 14800 KB Output is correct
49 Correct 624 ms 14672 KB Output is correct
50 Correct 660 ms 14672 KB Output is correct
51 Correct 862 ms 14632 KB Output is correct
52 Correct 827 ms 14628 KB Output is correct
53 Correct 460 ms 15136 KB Output is correct
54 Correct 719 ms 14672 KB Output is correct
55 Correct 710 ms 14544 KB Output is correct
56 Correct 934 ms 14544 KB Output is correct
57 Correct 997 ms 14544 KB Output is correct
58 Correct 905 ms 15312 KB Output is correct
59 Correct 677 ms 15440 KB Output is correct
60 Correct 775 ms 15440 KB Output is correct
61 Correct 842 ms 14800 KB Output is correct
62 Correct 821 ms 14544 KB Output is correct
63 Correct 895 ms 14544 KB Output is correct
64 Correct 827 ms 14544 KB Output is correct
65 Correct 227 ms 14544 KB Output is correct
66 Correct 661 ms 14672 KB Output is correct
67 Correct 867 ms 14672 KB Output is correct
68 Correct 722 ms 14672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14288 KB Output is correct
2 Correct 6 ms 14288 KB Output is correct
3 Correct 6 ms 14416 KB Output is correct
4 Correct 6 ms 14416 KB Output is correct
5 Correct 6 ms 14416 KB Output is correct
6 Correct 6 ms 14416 KB Output is correct
7 Correct 7 ms 14416 KB Output is correct
8 Correct 7 ms 14360 KB Output is correct
9 Correct 8 ms 14316 KB Output is correct
10 Correct 6 ms 14416 KB Output is correct
11 Correct 7 ms 14416 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
13 Correct 7 ms 14416 KB Output is correct
14 Correct 7 ms 14416 KB Output is correct
15 Correct 8 ms 14412 KB Output is correct
16 Correct 6 ms 14416 KB Output is correct
17 Correct 9 ms 14416 KB Output is correct
18 Correct 7 ms 14544 KB Output is correct
19 Correct 6 ms 14544 KB Output is correct
20 Correct 7 ms 14416 KB Output is correct
21 Correct 6 ms 14416 KB Output is correct
22 Correct 6 ms 14416 KB Output is correct
23 Correct 7 ms 14416 KB Output is correct
24 Correct 8 ms 14456 KB Output is correct
25 Correct 7 ms 14444 KB Output is correct
26 Correct 7 ms 14416 KB Output is correct
27 Correct 6 ms 14416 KB Output is correct
28 Correct 6 ms 14416 KB Output is correct
29 Correct 6 ms 14416 KB Output is correct
30 Correct 7 ms 14332 KB Output is correct
31 Correct 6 ms 14552 KB Output is correct
32 Correct 8 ms 14576 KB Output is correct
33 Correct 7 ms 14416 KB Output is correct
34 Correct 7 ms 14416 KB Output is correct
35 Correct 7 ms 14432 KB Output is correct
36 Correct 7 ms 14544 KB Output is correct
37 Correct 7 ms 14544 KB Output is correct
38 Correct 7 ms 14544 KB Output is correct
39 Correct 6 ms 14416 KB Output is correct
40 Correct 7 ms 14416 KB Output is correct
41 Correct 6 ms 14416 KB Output is correct
42 Correct 7 ms 14376 KB Output is correct
43 Correct 559 ms 16964 KB Output is correct
44 Correct 695 ms 19504 KB Output is correct
45 Correct 793 ms 19504 KB Output is correct
46 Correct 831 ms 19500 KB Output is correct
47 Correct 663 ms 16968 KB Output is correct
48 Correct 881 ms 19528 KB Output is correct
49 Correct 826 ms 19508 KB Output is correct
50 Correct 723 ms 19524 KB Output is correct
51 Correct 414 ms 14544 KB Output is correct
52 Correct 730 ms 14672 KB Output is correct
53 Correct 440 ms 14672 KB Output is correct
54 Correct 709 ms 14672 KB Output is correct
55 Correct 850 ms 22068 KB Output is correct
56 Correct 889 ms 22216 KB Output is correct
57 Correct 906 ms 22216 KB Output is correct
58 Correct 685 ms 22096 KB Output is correct
59 Correct 960 ms 34672 KB Output is correct
60 Correct 855 ms 34640 KB Output is correct
61 Correct 529 ms 14524 KB Output is correct
62 Correct 615 ms 14672 KB Output is correct
63 Correct 678 ms 14544 KB Output is correct
64 Correct 641 ms 14672 KB Output is correct
65 Correct 767 ms 14672 KB Output is correct
66 Correct 724 ms 14800 KB Output is correct
67 Correct 624 ms 14672 KB Output is correct
68 Correct 660 ms 14672 KB Output is correct
69 Correct 862 ms 14632 KB Output is correct
70 Correct 827 ms 14628 KB Output is correct
71 Correct 460 ms 15136 KB Output is correct
72 Correct 719 ms 14672 KB Output is correct
73 Correct 710 ms 14544 KB Output is correct
74 Correct 934 ms 14544 KB Output is correct
75 Correct 997 ms 14544 KB Output is correct
76 Correct 905 ms 15312 KB Output is correct
77 Correct 677 ms 15440 KB Output is correct
78 Correct 775 ms 15440 KB Output is correct
79 Correct 842 ms 14800 KB Output is correct
80 Correct 821 ms 14544 KB Output is correct
81 Correct 895 ms 14544 KB Output is correct
82 Correct 827 ms 14544 KB Output is correct
83 Correct 227 ms 14544 KB Output is correct
84 Correct 661 ms 14672 KB Output is correct
85 Correct 867 ms 14672 KB Output is correct
86 Correct 722 ms 14672 KB Output is correct
87 Correct 6 ms 14288 KB Output is correct
88 Correct 490 ms 21432 KB Output is correct
89 Correct 857 ms 19600 KB Output is correct
90 Correct 876 ms 19292 KB Output is correct
91 Correct 805 ms 22216 KB Output is correct
92 Correct 961 ms 22284 KB Output is correct
93 Correct 890 ms 22328 KB Output is correct
94 Correct 944 ms 22216 KB Output is correct
95 Correct 842 ms 22260 KB Output is correct
96 Correct 822 ms 18764 KB Output is correct
97 Correct 852 ms 18780 KB Output is correct
98 Correct 857 ms 31600 KB Output is correct
99 Correct 962 ms 22212 KB Output is correct
100 Correct 746 ms 19844 KB Output is correct
101 Correct 916 ms 19124 KB Output is correct
102 Correct 891 ms 17972 KB Output is correct
103 Correct 909 ms 34732 KB Output is correct
104 Correct 997 ms 35912 KB Output is correct
105 Correct 839 ms 35892 KB Output is correct
106 Correct 820 ms 21940 KB Output is correct
107 Correct 882 ms 18392 KB Output is correct
108 Correct 975 ms 18328 KB Output is correct
109 Correct 839 ms 18128 KB Output is correct