답안 #735862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
735862 2023-05-04T20:38:35 Z AdamGS 디지털 회로 (IOI22_circuit) C++17
100 / 100
1314 ms 40480 KB
#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll MOD=1000000000+2022;
const int LIM=2e5+7;
vector<int>V[LIM];
ll ilo[LIM], tr[4*LIM], sum[4*LIM], lazy[4*LIM], N=1;
void DFS(int x) {
	ilo[x]=max(1, (int)V[x].size());
	for(auto i : V[x]) {
		DFS(i);
		ilo[x]=(ilo[x]*ilo[i])%MOD;
	}
}
void DFS2(int x, ll akt) {
	if(!V[x].size()) {
		sum[N+x]=akt;
		return;
	}
	vector<ll>pref(V[x].size()), suf(V[x].size());
	rep(i, V[x].size()) {
		pref[i]=ilo[V[x][i]];
		suf[V[x].size()-i-1]=ilo[V[x][V[x].size()-i-1]];
		if(i) {
			pref[i]=(pref[i]*pref[i-1])%MOD;
			suf[V[x].size()-i-1]=(suf[V[x].size()-i-1]*suf[V[x].size()-i])%MOD;
		}
	}
	rep(i, V[x].size()) {
		ll p=akt;
		if(i) p=(p*pref[i-1])%MOD;
		if(i+1<V[x].size()) p=(p*suf[i+1])%MOD;
		DFS2(V[x][i], p);
	}
}
void init(int n, int m, vector<int> P, vector<int> A) {
	while(N<n+m) N*=2;
	for(int i=1; i<P.size(); ++i) V[P[i]].pb(i);
	DFS(0);
	DFS2(0, 1);
	rep(i, m) if(A[i]) tr[N+n+i]=sum[N+n+i];
	for(int i=N-1; i; --i) {
		tr[i]=(tr[2*i]+tr[2*i+1])%MOD;
		sum[i]=(sum[2*i]+sum[2*i+1])%MOD;
	}
}
void spl(int v) {
	tr[2*v]=(sum[2*v]-tr[2*v]+MOD)%MOD;
	tr[2*v+1]=(sum[2*v+1]-tr[2*v+1]+MOD)%MOD;
	lazy[2*v]^=1;
	lazy[2*v+1]^=1;
	lazy[v]=0;
}
void upd(int v, int l, int r, int a, int b) {
	if(r<a || l>b) return;
	if(a<=l && r<=b) {
		tr[v]=(sum[v]-tr[v]+MOD)%MOD;
		lazy[v]^=1;
		return;
	}
	if(lazy[v]) spl(v);
	int mid=(l+r)/2;
	upd(2*v, l, mid, a, b);
	upd(2*v+1, mid+1, r, a, b);
	tr[v]=(tr[2*v]+tr[2*v+1])%MOD;
}
int count_ways(int l, int r) {
  upd(1, 0, N-1, l, r);
	return tr[1];
}

Compilation message

circuit.cpp: In function 'void DFS2(int, ll)':
circuit.cpp:6:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
circuit.cpp:28:2: note: in expansion of macro 'rep'
   28 |  rep(i, V[x].size()) {
      |  ^~~
circuit.cpp:6:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
circuit.cpp:36:2: note: in expansion of macro 'rep'
   36 |  rep(i, V[x].size()) {
      |  ^~~
circuit.cpp:39:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   if(i+1<V[x].size()) p=(p*suf[i+1])%MOD;
      |      ~~~^~~~~~~~~~~~
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:45:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for(int i=1; i<P.size(); ++i) V[P[i]].pb(i);
      |               ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 3 ms 5096 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 5096 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 4 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 4 ms 5352 KB Output is correct
11 Correct 3 ms 5376 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5096 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 4 ms 5096 KB Output is correct
14 Correct 4 ms 5072 KB Output is correct
15 Correct 4 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5352 KB Output is correct
19 Correct 3 ms 5376 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5084 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 4 ms 5072 KB Output is correct
25 Correct 3 ms 5152 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 5 ms 5280 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5108 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 4 ms 5072 KB Output is correct
33 Correct 4 ms 5072 KB Output is correct
34 Correct 4 ms 5128 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5372 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 5 ms 5400 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 4 ms 5072 KB Output is correct
41 Correct 4 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 638 ms 8824 KB Output is correct
2 Correct 892 ms 12684 KB Output is correct
3 Correct 791 ms 12616 KB Output is correct
4 Correct 983 ms 12480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 638 ms 8824 KB Output is correct
2 Correct 892 ms 12684 KB Output is correct
3 Correct 791 ms 12616 KB Output is correct
4 Correct 983 ms 12480 KB Output is correct
5 Correct 802 ms 9052 KB Output is correct
6 Correct 1050 ms 13020 KB Output is correct
7 Correct 940 ms 13032 KB Output is correct
8 Correct 1030 ms 12604 KB Output is correct
9 Correct 500 ms 5256 KB Output is correct
10 Correct 829 ms 5584 KB Output is correct
11 Correct 757 ms 5584 KB Output is correct
12 Correct 952 ms 5456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 3 ms 5096 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 5096 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 4 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 4 ms 5352 KB Output is correct
11 Correct 3 ms 5376 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 638 ms 8824 KB Output is correct
14 Correct 892 ms 12684 KB Output is correct
15 Correct 791 ms 12616 KB Output is correct
16 Correct 983 ms 12480 KB Output is correct
17 Correct 802 ms 9052 KB Output is correct
18 Correct 1050 ms 13020 KB Output is correct
19 Correct 940 ms 13032 KB Output is correct
20 Correct 1030 ms 12604 KB Output is correct
21 Correct 500 ms 5256 KB Output is correct
22 Correct 829 ms 5584 KB Output is correct
23 Correct 757 ms 5584 KB Output is correct
24 Correct 952 ms 5456 KB Output is correct
25 Correct 930 ms 18024 KB Output is correct
26 Correct 1024 ms 18180 KB Output is correct
27 Correct 950 ms 18184 KB Output is correct
28 Correct 909 ms 17792 KB Output is correct
29 Correct 919 ms 40084 KB Output is correct
30 Correct 1040 ms 39588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5096 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 4 ms 5096 KB Output is correct
14 Correct 4 ms 5072 KB Output is correct
15 Correct 4 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5352 KB Output is correct
19 Correct 3 ms 5376 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5084 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 4 ms 5072 KB Output is correct
25 Correct 3 ms 5152 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 5 ms 5280 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5108 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 4 ms 5072 KB Output is correct
33 Correct 4 ms 5072 KB Output is correct
34 Correct 4 ms 5128 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5372 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 5 ms 5400 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 4 ms 5072 KB Output is correct
41 Correct 4 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 591 ms 5456 KB Output is correct
44 Correct 999 ms 5384 KB Output is correct
45 Correct 1043 ms 5456 KB Output is correct
46 Correct 903 ms 5732 KB Output is correct
47 Correct 953 ms 5740 KB Output is correct
48 Correct 1014 ms 5712 KB Output is correct
49 Correct 737 ms 5768 KB Output is correct
50 Correct 686 ms 5712 KB Output is correct
51 Correct 722 ms 5512 KB Output is correct
52 Correct 984 ms 5548 KB Output is correct
53 Correct 802 ms 6480 KB Output is correct
54 Correct 957 ms 5712 KB Output is correct
55 Correct 767 ms 5456 KB Output is correct
56 Correct 924 ms 5508 KB Output is correct
57 Correct 1106 ms 5584 KB Output is correct
58 Correct 924 ms 6864 KB Output is correct
59 Correct 897 ms 7044 KB Output is correct
60 Correct 845 ms 6864 KB Output is correct
61 Correct 763 ms 5712 KB Output is correct
62 Correct 875 ms 5380 KB Output is correct
63 Correct 998 ms 5328 KB Output is correct
64 Correct 716 ms 5412 KB Output is correct
65 Correct 440 ms 5200 KB Output is correct
66 Correct 916 ms 5512 KB Output is correct
67 Correct 850 ms 5508 KB Output is correct
68 Correct 999 ms 5456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5096 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 4 ms 5096 KB Output is correct
14 Correct 4 ms 5072 KB Output is correct
15 Correct 4 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5352 KB Output is correct
19 Correct 3 ms 5376 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5084 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 4 ms 5072 KB Output is correct
25 Correct 3 ms 5152 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 5 ms 5280 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5108 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 4 ms 5072 KB Output is correct
33 Correct 4 ms 5072 KB Output is correct
34 Correct 4 ms 5128 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5372 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 5 ms 5400 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 4 ms 5072 KB Output is correct
41 Correct 4 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 638 ms 8824 KB Output is correct
44 Correct 892 ms 12684 KB Output is correct
45 Correct 791 ms 12616 KB Output is correct
46 Correct 983 ms 12480 KB Output is correct
47 Correct 802 ms 9052 KB Output is correct
48 Correct 1050 ms 13020 KB Output is correct
49 Correct 940 ms 13032 KB Output is correct
50 Correct 1030 ms 12604 KB Output is correct
51 Correct 500 ms 5256 KB Output is correct
52 Correct 829 ms 5584 KB Output is correct
53 Correct 757 ms 5584 KB Output is correct
54 Correct 952 ms 5456 KB Output is correct
55 Correct 930 ms 18024 KB Output is correct
56 Correct 1024 ms 18180 KB Output is correct
57 Correct 950 ms 18184 KB Output is correct
58 Correct 909 ms 17792 KB Output is correct
59 Correct 919 ms 40084 KB Output is correct
60 Correct 1040 ms 39588 KB Output is correct
61 Correct 591 ms 5456 KB Output is correct
62 Correct 999 ms 5384 KB Output is correct
63 Correct 1043 ms 5456 KB Output is correct
64 Correct 903 ms 5732 KB Output is correct
65 Correct 953 ms 5740 KB Output is correct
66 Correct 1014 ms 5712 KB Output is correct
67 Correct 737 ms 5768 KB Output is correct
68 Correct 686 ms 5712 KB Output is correct
69 Correct 722 ms 5512 KB Output is correct
70 Correct 984 ms 5548 KB Output is correct
71 Correct 802 ms 6480 KB Output is correct
72 Correct 957 ms 5712 KB Output is correct
73 Correct 767 ms 5456 KB Output is correct
74 Correct 924 ms 5508 KB Output is correct
75 Correct 1106 ms 5584 KB Output is correct
76 Correct 924 ms 6864 KB Output is correct
77 Correct 897 ms 7044 KB Output is correct
78 Correct 845 ms 6864 KB Output is correct
79 Correct 763 ms 5712 KB Output is correct
80 Correct 875 ms 5380 KB Output is correct
81 Correct 998 ms 5328 KB Output is correct
82 Correct 716 ms 5412 KB Output is correct
83 Correct 440 ms 5200 KB Output is correct
84 Correct 916 ms 5512 KB Output is correct
85 Correct 850 ms 5508 KB Output is correct
86 Correct 999 ms 5456 KB Output is correct
87 Correct 3 ms 4944 KB Output is correct
88 Correct 595 ms 17148 KB Output is correct
89 Correct 1040 ms 12820 KB Output is correct
90 Correct 968 ms 12720 KB Output is correct
91 Correct 1010 ms 17800 KB Output is correct
92 Correct 1105 ms 18300 KB Output is correct
93 Correct 1314 ms 18300 KB Output is correct
94 Correct 1184 ms 18300 KB Output is correct
95 Correct 1027 ms 17780 KB Output is correct
96 Correct 1010 ms 11488 KB Output is correct
97 Correct 1148 ms 12312 KB Output is correct
98 Correct 661 ms 33676 KB Output is correct
99 Correct 1188 ms 18232 KB Output is correct
100 Correct 935 ms 16020 KB Output is correct
101 Correct 900 ms 13392 KB Output is correct
102 Correct 707 ms 12332 KB Output is correct
103 Correct 992 ms 40160 KB Output is correct
104 Correct 948 ms 40480 KB Output is correct
105 Correct 887 ms 39992 KB Output is correct
106 Correct 918 ms 17168 KB Output is correct
107 Correct 1010 ms 12028 KB Output is correct
108 Correct 1035 ms 12148 KB Output is correct
109 Correct 1138 ms 12484 KB Output is correct