답안 #629975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
629975 2022-08-15T13:03:07 Z handlename 디지털 회로 (IOI22_circuit) C++17
100 / 100
1392 ms 41876 KB
#include <bits/stdc++.h>
//#include "circuit.h"
using namespace std;
#define pb push_back
#define mp make_pair
const int MOD=1e9+2022;
int n,mm,par[200001],arr[200001];
vector<int> adj[200001];
long long mult[200001],ans[200001];
long long dfs(int x){
	mult[x]=max((int)adj[x].size(),1);
	for (auto i:adj[x]){
		mult[x]*=dfs(i);
		mult[x]%=MOD;
	}
	return mult[x];
}
void dfs(int x,long long d){
	ans[x]=d;
	long long pre[adj[x].size()],suf[adj[x].size()];
	pre[0]=suf[adj[x].size()-1]=1;
	for (int i=1;i<(int)adj[x].size();i++){
		pre[i]=pre[i-1]*mult[adj[x][i-1]];
		pre[i]%=MOD;
	}
	for (int i=adj[x].size()-2;i>=0;i--){
		suf[i]=suf[i+1]*mult[adj[x][i+1]];
		suf[i]%=MOD;
	}
	for (int i=0;i<(int)adj[x].size();i++){
		long long cur=d;
		cur*=pre[i];
		cur%=MOD;
		cur*=suf[i];
		cur%=MOD;
		dfs(adj[x][i],cur);
	}
}
struct node{
	node *l,*r;
	int s,m,e;
	long long val,sum;
	bool flip;
	node(int ss,int ee){
		s=ss;
		e=ee;
		m=(s+e)/2;
		flip=false;
		if (s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
			val=l->val+r->val;
			sum=l->sum+r->sum;
			val%=MOD;
			sum%=MOD;
		}
		else {
			sum=ans[s];
			val=ans[s]*arr[s];
		}
	}
	long long value(){
		if (s==e){
			if (flip) val=sum-val;
			flip=false;
			return val;
		}
		if (flip){
			val=sum-val;
			l->flip=!(l->flip);
			r->flip=!(r->flip);
		}
		flip=false;
		return val;
	}
	void upd(int x,int y){
		value();
		if (s==x && e==y){
			flip=!flip;
			return;
		}
		if (x>m) r->upd(x,y);
		else if (y<=m) l->upd(x,y);
		else l->upd(x,m),r->upd(m+1,y);
		val=l->value()+r->value();
		val%=MOD;
	}
}*root;
void init(int N,int M,vector<int> P,vector<int> A){
	n=N;
	mm=M;
	for (int i=1;i<n+mm;i++){
		par[i]=P[i];
		adj[par[i]].pb(i);
	}
	for (int i=0;i<mm;i++){
		arr[n+i]=A[i];
	}
	dfs(0);
	dfs(0,1);
	root=new node(n,n+mm-1);
}
int count_ways(int l,int r){
	root->upd(l,r);
	return ((root->value())%MOD+MOD)%MOD;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 5200 KB Output is correct
6 Correct 3 ms 5188 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4996 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 3 ms 5080 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 5200 KB Output is correct
8 Correct 3 ms 5200 KB Output is correct
9 Correct 3 ms 5200 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 5200 KB Output is correct
6 Correct 3 ms 5188 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4996 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5080 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5200 KB Output is correct
16 Correct 3 ms 5200 KB Output is correct
17 Correct 3 ms 5200 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5200 KB Output is correct
21 Correct 3 ms 5200 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5200 KB Output is correct
25 Correct 4 ms 5192 KB Output is correct
26 Correct 3 ms 5200 KB Output is correct
27 Correct 3 ms 5200 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5180 KB Output is correct
31 Correct 4 ms 5200 KB Output is correct
32 Correct 3 ms 5220 KB Output is correct
33 Correct 3 ms 5200 KB Output is correct
34 Correct 3 ms 5200 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 4 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 630 ms 12292 KB Output is correct
2 Correct 746 ms 19528 KB Output is correct
3 Correct 585 ms 19568 KB Output is correct
4 Correct 780 ms 19528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 630 ms 12292 KB Output is correct
2 Correct 746 ms 19528 KB Output is correct
3 Correct 585 ms 19568 KB Output is correct
4 Correct 780 ms 19528 KB Output is correct
5 Correct 751 ms 12240 KB Output is correct
6 Correct 1107 ms 19624 KB Output is correct
7 Correct 913 ms 19564 KB Output is correct
8 Correct 923 ms 19584 KB Output is correct
9 Correct 374 ms 5468 KB Output is correct
10 Correct 760 ms 5840 KB Output is correct
11 Correct 857 ms 5840 KB Output is correct
12 Correct 846 ms 5840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4996 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 3 ms 5080 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 5200 KB Output is correct
8 Correct 3 ms 5200 KB Output is correct
9 Correct 3 ms 5200 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5200 KB Output is correct
13 Correct 630 ms 12292 KB Output is correct
14 Correct 746 ms 19528 KB Output is correct
15 Correct 585 ms 19568 KB Output is correct
16 Correct 780 ms 19528 KB Output is correct
17 Correct 751 ms 12240 KB Output is correct
18 Correct 1107 ms 19624 KB Output is correct
19 Correct 913 ms 19564 KB Output is correct
20 Correct 923 ms 19584 KB Output is correct
21 Correct 374 ms 5468 KB Output is correct
22 Correct 760 ms 5840 KB Output is correct
23 Correct 857 ms 5840 KB Output is correct
24 Correct 846 ms 5840 KB Output is correct
25 Correct 1140 ms 26912 KB Output is correct
26 Correct 1126 ms 27272 KB Output is correct
27 Correct 1163 ms 27208 KB Output is correct
28 Correct 730 ms 27300 KB Output is correct
29 Correct 990 ms 39880 KB Output is correct
30 Correct 963 ms 39812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 5200 KB Output is correct
6 Correct 3 ms 5188 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4996 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5080 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5200 KB Output is correct
16 Correct 3 ms 5200 KB Output is correct
17 Correct 3 ms 5200 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5200 KB Output is correct
21 Correct 3 ms 5200 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5200 KB Output is correct
25 Correct 4 ms 5192 KB Output is correct
26 Correct 3 ms 5200 KB Output is correct
27 Correct 3 ms 5200 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5180 KB Output is correct
31 Correct 4 ms 5200 KB Output is correct
32 Correct 3 ms 5220 KB Output is correct
33 Correct 3 ms 5200 KB Output is correct
34 Correct 3 ms 5200 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 4 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 665 ms 5584 KB Output is correct
44 Correct 714 ms 5584 KB Output is correct
45 Correct 686 ms 5584 KB Output is correct
46 Correct 895 ms 6096 KB Output is correct
47 Correct 914 ms 6096 KB Output is correct
48 Correct 902 ms 6096 KB Output is correct
49 Correct 900 ms 6096 KB Output is correct
50 Correct 827 ms 6096 KB Output is correct
51 Correct 846 ms 5840 KB Output is correct
52 Correct 754 ms 5840 KB Output is correct
53 Correct 681 ms 5840 KB Output is correct
54 Correct 856 ms 6096 KB Output is correct
55 Correct 863 ms 5968 KB Output is correct
56 Correct 809 ms 5840 KB Output is correct
57 Correct 922 ms 5840 KB Output is correct
58 Correct 876 ms 6736 KB Output is correct
59 Correct 919 ms 6736 KB Output is correct
60 Correct 795 ms 6736 KB Output is correct
61 Correct 782 ms 5712 KB Output is correct
62 Correct 877 ms 5712 KB Output is correct
63 Correct 684 ms 5712 KB Output is correct
64 Correct 771 ms 5840 KB Output is correct
65 Correct 344 ms 5456 KB Output is correct
66 Correct 826 ms 5840 KB Output is correct
67 Correct 1081 ms 5840 KB Output is correct
68 Correct 922 ms 5840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 5200 KB Output is correct
6 Correct 3 ms 5188 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4996 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5080 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5200 KB Output is correct
16 Correct 3 ms 5200 KB Output is correct
17 Correct 3 ms 5200 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5200 KB Output is correct
21 Correct 3 ms 5200 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5200 KB Output is correct
25 Correct 4 ms 5192 KB Output is correct
26 Correct 3 ms 5200 KB Output is correct
27 Correct 3 ms 5200 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5180 KB Output is correct
31 Correct 4 ms 5200 KB Output is correct
32 Correct 3 ms 5220 KB Output is correct
33 Correct 3 ms 5200 KB Output is correct
34 Correct 3 ms 5200 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 4 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 630 ms 12292 KB Output is correct
44 Correct 746 ms 19528 KB Output is correct
45 Correct 585 ms 19568 KB Output is correct
46 Correct 780 ms 19528 KB Output is correct
47 Correct 751 ms 12240 KB Output is correct
48 Correct 1107 ms 19624 KB Output is correct
49 Correct 913 ms 19564 KB Output is correct
50 Correct 923 ms 19584 KB Output is correct
51 Correct 374 ms 5468 KB Output is correct
52 Correct 760 ms 5840 KB Output is correct
53 Correct 857 ms 5840 KB Output is correct
54 Correct 846 ms 5840 KB Output is correct
55 Correct 1140 ms 26912 KB Output is correct
56 Correct 1126 ms 27272 KB Output is correct
57 Correct 1163 ms 27208 KB Output is correct
58 Correct 730 ms 27300 KB Output is correct
59 Correct 990 ms 39880 KB Output is correct
60 Correct 963 ms 39812 KB Output is correct
61 Correct 665 ms 5584 KB Output is correct
62 Correct 714 ms 5584 KB Output is correct
63 Correct 686 ms 5584 KB Output is correct
64 Correct 895 ms 6096 KB Output is correct
65 Correct 914 ms 6096 KB Output is correct
66 Correct 902 ms 6096 KB Output is correct
67 Correct 900 ms 6096 KB Output is correct
68 Correct 827 ms 6096 KB Output is correct
69 Correct 846 ms 5840 KB Output is correct
70 Correct 754 ms 5840 KB Output is correct
71 Correct 681 ms 5840 KB Output is correct
72 Correct 856 ms 6096 KB Output is correct
73 Correct 863 ms 5968 KB Output is correct
74 Correct 809 ms 5840 KB Output is correct
75 Correct 922 ms 5840 KB Output is correct
76 Correct 876 ms 6736 KB Output is correct
77 Correct 919 ms 6736 KB Output is correct
78 Correct 795 ms 6736 KB Output is correct
79 Correct 782 ms 5712 KB Output is correct
80 Correct 877 ms 5712 KB Output is correct
81 Correct 684 ms 5712 KB Output is correct
82 Correct 771 ms 5840 KB Output is correct
83 Correct 344 ms 5456 KB Output is correct
84 Correct 826 ms 5840 KB Output is correct
85 Correct 1081 ms 5840 KB Output is correct
86 Correct 922 ms 5840 KB Output is correct
87 Correct 3 ms 4944 KB Output is correct
88 Correct 551 ms 24060 KB Output is correct
89 Correct 1018 ms 17608 KB Output is correct
90 Correct 907 ms 18244 KB Output is correct
91 Correct 920 ms 27304 KB Output is correct
92 Correct 1028 ms 27384 KB Output is correct
93 Correct 1033 ms 27312 KB Output is correct
94 Correct 1119 ms 27304 KB Output is correct
95 Correct 858 ms 27412 KB Output is correct
96 Correct 868 ms 23292 KB Output is correct
97 Correct 1208 ms 23292 KB Output is correct
98 Correct 657 ms 23384 KB Output is correct
99 Correct 1085 ms 27196 KB Output is correct
100 Correct 1126 ms 24276 KB Output is correct
101 Correct 1024 ms 23300 KB Output is correct
102 Correct 922 ms 21876 KB Output is correct
103 Correct 1392 ms 39708 KB Output is correct
104 Correct 1082 ms 41876 KB Output is correct
105 Correct 1006 ms 41696 KB Output is correct
106 Correct 1008 ms 19196 KB Output is correct
107 Correct 979 ms 18240 KB Output is correct
108 Correct 1014 ms 19588 KB Output is correct
109 Correct 1169 ms 21904 KB Output is correct