Submission #629006

# Submission time Handle Problem Language Result Execution time Memory
629006 2022-08-13T23:20:15 Z errorgorn Digital Circuit (IOI22_circuit) C++17
100 / 100
1253 ms 57552 KB
#include "circuit.h"

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ii pair<int,int>
#define fi first
#define se second

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int MOD=1000002022;

struct node{
	int s,e,m;
	ii val={0,0};
	bool lazy=false;
	node *l,*r;
	
	node (int _s,int _e){
		s=_s,e=_e,m=s+e>>1;
		
		if (s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
		}
	}
	
	void propo(){
		if (!lazy) return;
		swap(val.fi,val.se);
		if (s!=e){
			l->lazy^=true;
			r->lazy^=true;
		}
		lazy=false;
	}
	
	void update(int i,ii k){
		if (s==e) val=k;
		else{
			if (i<=m) l->update(i,k);
			else r->update(i,k);
			
			val={(l->val.fi+r->val.fi)%MOD,(l->val.se+r->val.se)%MOD};
		}
	}
	
	void update(int i,int j){
		propo();
		
		if (s==i && e==j) lazy^=true;
		else{
			if (j<=m) l->update(i,j);
			else if (m<i) r->update(i,j);
			else l->update(i,m),r->update(m+1,j);
			
			l->propo(),r->propo();
			val={(l->val.fi+r->val.fi)%MOD,(l->val.se+r->val.se)%MOD};
		}
	}
} *root=new node(0,100005);

int n,m;
vector<int> al[100005];
int coef[100005];
int arr[100005];

int ss[100005];

void dfs_ss(int i){
	if (i<n){
		ss[i]=sz(al[i]);
		for (auto it:al[i]){
			dfs_ss(it);
			ss[i]=ss[i]*ss[it]%MOD;
		}
	}
	else ss[i]=1;
}

void dfs(int i,int ans){
	if (i<n){
		vector<int> v;
		for (auto it:al[i]) v.pub(ss[it]);
		
		vector<int> f={1},b={1};
		rep(x,0,sz(v)) f.pub(f.back()*v[x]%MOD);
		rep(x,sz(v),0) b.pub(b.back()*v[x]%MOD);
		
		reverse(all(b));
		
		rep(x,0,sz(v)) dfs(al[i][x],ans*f[x]%MOD*b[x+1]%MOD);
	}
	else coef[i-n]=ans;
}

void init(signed N, signed M, vector<signed> P, vector<signed> A) {
	n=N,m=M;
	rep(x,1,n+m) al[P[x]].pub(x);
	rep(x,0,m) arr[x]=A[x];
	
	dfs_ss(0);
	dfs(0,1);
	
	//rep(x,0,m) cout<<coef[x]<<" "; cout<<endl;
	rep(x,0,m){
		if (A[x]) root->update(x,{coef[x],0});
		else root->update(x,{0,coef[x]});
	}
}

signed count_ways(signed a, signed b) {
	root->update(a-n,b-n);
	return root->val.fi;
}

Compilation message

circuit.cpp: In constructor 'node::node(long long int, long long int)':
circuit.cpp:33:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |   s=_s,e=_e,m=s+e>>1;
      |               ~^~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 18384 KB Output is correct
2 Correct 11 ms 18256 KB Output is correct
3 Correct 11 ms 18384 KB Output is correct
4 Correct 12 ms 18396 KB Output is correct
5 Correct 11 ms 18384 KB Output is correct
6 Correct 11 ms 18344 KB Output is correct
7 Correct 12 ms 18384 KB Output is correct
8 Correct 12 ms 18384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 18256 KB Output is correct
2 Correct 14 ms 18244 KB Output is correct
3 Correct 11 ms 18256 KB Output is correct
4 Correct 12 ms 18256 KB Output is correct
5 Correct 11 ms 18256 KB Output is correct
6 Correct 12 ms 18264 KB Output is correct
7 Correct 12 ms 18356 KB Output is correct
8 Correct 14 ms 18384 KB Output is correct
9 Correct 12 ms 18396 KB Output is correct
10 Correct 12 ms 18640 KB Output is correct
11 Correct 12 ms 18616 KB Output is correct
12 Correct 16 ms 18384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 18384 KB Output is correct
2 Correct 11 ms 18256 KB Output is correct
3 Correct 11 ms 18384 KB Output is correct
4 Correct 12 ms 18396 KB Output is correct
5 Correct 11 ms 18384 KB Output is correct
6 Correct 11 ms 18344 KB Output is correct
7 Correct 12 ms 18384 KB Output is correct
8 Correct 12 ms 18384 KB Output is correct
9 Correct 11 ms 18256 KB Output is correct
10 Correct 14 ms 18244 KB Output is correct
11 Correct 11 ms 18256 KB Output is correct
12 Correct 12 ms 18256 KB Output is correct
13 Correct 11 ms 18256 KB Output is correct
14 Correct 12 ms 18264 KB Output is correct
15 Correct 12 ms 18356 KB Output is correct
16 Correct 14 ms 18384 KB Output is correct
17 Correct 12 ms 18396 KB Output is correct
18 Correct 12 ms 18640 KB Output is correct
19 Correct 12 ms 18616 KB Output is correct
20 Correct 16 ms 18384 KB Output is correct
21 Correct 16 ms 18384 KB Output is correct
22 Correct 12 ms 18256 KB Output is correct
23 Correct 13 ms 18264 KB Output is correct
24 Correct 12 ms 18324 KB Output is correct
25 Correct 12 ms 18384 KB Output is correct
26 Correct 12 ms 18296 KB Output is correct
27 Correct 12 ms 18384 KB Output is correct
28 Correct 12 ms 18384 KB Output is correct
29 Correct 13 ms 18384 KB Output is correct
30 Correct 12 ms 18384 KB Output is correct
31 Correct 11 ms 18640 KB Output is correct
32 Correct 14 ms 18344 KB Output is correct
33 Correct 12 ms 18384 KB Output is correct
34 Correct 12 ms 18344 KB Output is correct
35 Correct 12 ms 18384 KB Output is correct
36 Correct 17 ms 18664 KB Output is correct
37 Correct 13 ms 18624 KB Output is correct
38 Correct 13 ms 18672 KB Output is correct
39 Correct 12 ms 18384 KB Output is correct
40 Correct 13 ms 18384 KB Output is correct
41 Correct 12 ms 18384 KB Output is correct
42 Correct 12 ms 18384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 685 ms 21088 KB Output is correct
2 Correct 941 ms 23700 KB Output is correct
3 Correct 997 ms 23628 KB Output is correct
4 Correct 876 ms 23688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 685 ms 21088 KB Output is correct
2 Correct 941 ms 23700 KB Output is correct
3 Correct 997 ms 23628 KB Output is correct
4 Correct 876 ms 23688 KB Output is correct
5 Correct 947 ms 21148 KB Output is correct
6 Correct 977 ms 23688 KB Output is correct
7 Correct 1195 ms 23632 KB Output is correct
8 Correct 1056 ms 23716 KB Output is correct
9 Correct 480 ms 18480 KB Output is correct
10 Correct 971 ms 18584 KB Output is correct
11 Correct 904 ms 18660 KB Output is correct
12 Correct 1024 ms 18588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 18256 KB Output is correct
2 Correct 14 ms 18244 KB Output is correct
3 Correct 11 ms 18256 KB Output is correct
4 Correct 12 ms 18256 KB Output is correct
5 Correct 11 ms 18256 KB Output is correct
6 Correct 12 ms 18264 KB Output is correct
7 Correct 12 ms 18356 KB Output is correct
8 Correct 14 ms 18384 KB Output is correct
9 Correct 12 ms 18396 KB Output is correct
10 Correct 12 ms 18640 KB Output is correct
11 Correct 12 ms 18616 KB Output is correct
12 Correct 16 ms 18384 KB Output is correct
13 Correct 685 ms 21088 KB Output is correct
14 Correct 941 ms 23700 KB Output is correct
15 Correct 997 ms 23628 KB Output is correct
16 Correct 876 ms 23688 KB Output is correct
17 Correct 947 ms 21148 KB Output is correct
18 Correct 977 ms 23688 KB Output is correct
19 Correct 1195 ms 23632 KB Output is correct
20 Correct 1056 ms 23716 KB Output is correct
21 Correct 480 ms 18480 KB Output is correct
22 Correct 971 ms 18584 KB Output is correct
23 Correct 904 ms 18660 KB Output is correct
24 Correct 1024 ms 18588 KB Output is correct
25 Correct 1106 ms 25980 KB Output is correct
26 Correct 1253 ms 26144 KB Output is correct
27 Correct 1138 ms 26148 KB Output is correct
28 Correct 875 ms 26012 KB Output is correct
29 Correct 1073 ms 57416 KB Output is correct
30 Correct 1041 ms 57372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 18384 KB Output is correct
2 Correct 11 ms 18256 KB Output is correct
3 Correct 11 ms 18384 KB Output is correct
4 Correct 12 ms 18396 KB Output is correct
5 Correct 11 ms 18384 KB Output is correct
6 Correct 11 ms 18344 KB Output is correct
7 Correct 12 ms 18384 KB Output is correct
8 Correct 12 ms 18384 KB Output is correct
9 Correct 11 ms 18256 KB Output is correct
10 Correct 14 ms 18244 KB Output is correct
11 Correct 11 ms 18256 KB Output is correct
12 Correct 12 ms 18256 KB Output is correct
13 Correct 11 ms 18256 KB Output is correct
14 Correct 12 ms 18264 KB Output is correct
15 Correct 12 ms 18356 KB Output is correct
16 Correct 14 ms 18384 KB Output is correct
17 Correct 12 ms 18396 KB Output is correct
18 Correct 12 ms 18640 KB Output is correct
19 Correct 12 ms 18616 KB Output is correct
20 Correct 16 ms 18384 KB Output is correct
21 Correct 16 ms 18384 KB Output is correct
22 Correct 12 ms 18256 KB Output is correct
23 Correct 13 ms 18264 KB Output is correct
24 Correct 12 ms 18324 KB Output is correct
25 Correct 12 ms 18384 KB Output is correct
26 Correct 12 ms 18296 KB Output is correct
27 Correct 12 ms 18384 KB Output is correct
28 Correct 12 ms 18384 KB Output is correct
29 Correct 13 ms 18384 KB Output is correct
30 Correct 12 ms 18384 KB Output is correct
31 Correct 11 ms 18640 KB Output is correct
32 Correct 14 ms 18344 KB Output is correct
33 Correct 12 ms 18384 KB Output is correct
34 Correct 12 ms 18344 KB Output is correct
35 Correct 12 ms 18384 KB Output is correct
36 Correct 17 ms 18664 KB Output is correct
37 Correct 13 ms 18624 KB Output is correct
38 Correct 13 ms 18672 KB Output is correct
39 Correct 12 ms 18384 KB Output is correct
40 Correct 13 ms 18384 KB Output is correct
41 Correct 12 ms 18384 KB Output is correct
42 Correct 12 ms 18384 KB Output is correct
43 Correct 637 ms 18512 KB Output is correct
44 Correct 923 ms 18640 KB Output is correct
45 Correct 778 ms 18512 KB Output is correct
46 Correct 956 ms 18768 KB Output is correct
47 Correct 812 ms 18728 KB Output is correct
48 Correct 890 ms 18784 KB Output is correct
49 Correct 1064 ms 18768 KB Output is correct
50 Correct 889 ms 18696 KB Output is correct
51 Correct 885 ms 18768 KB Output is correct
52 Correct 961 ms 18768 KB Output is correct
53 Correct 741 ms 19920 KB Output is correct
54 Correct 959 ms 18760 KB Output is correct
55 Correct 930 ms 18704 KB Output is correct
56 Correct 936 ms 18556 KB Output is correct
57 Correct 796 ms 18596 KB Output is correct
58 Correct 953 ms 20304 KB Output is correct
59 Correct 960 ms 20304 KB Output is correct
60 Correct 677 ms 20380 KB Output is correct
61 Correct 986 ms 18896 KB Output is correct
62 Correct 857 ms 18512 KB Output is correct
63 Correct 708 ms 18512 KB Output is correct
64 Correct 935 ms 18512 KB Output is correct
65 Correct 452 ms 18440 KB Output is correct
66 Correct 847 ms 18640 KB Output is correct
67 Correct 967 ms 18624 KB Output is correct
68 Correct 836 ms 18640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 18384 KB Output is correct
2 Correct 11 ms 18256 KB Output is correct
3 Correct 11 ms 18384 KB Output is correct
4 Correct 12 ms 18396 KB Output is correct
5 Correct 11 ms 18384 KB Output is correct
6 Correct 11 ms 18344 KB Output is correct
7 Correct 12 ms 18384 KB Output is correct
8 Correct 12 ms 18384 KB Output is correct
9 Correct 11 ms 18256 KB Output is correct
10 Correct 14 ms 18244 KB Output is correct
11 Correct 11 ms 18256 KB Output is correct
12 Correct 12 ms 18256 KB Output is correct
13 Correct 11 ms 18256 KB Output is correct
14 Correct 12 ms 18264 KB Output is correct
15 Correct 12 ms 18356 KB Output is correct
16 Correct 14 ms 18384 KB Output is correct
17 Correct 12 ms 18396 KB Output is correct
18 Correct 12 ms 18640 KB Output is correct
19 Correct 12 ms 18616 KB Output is correct
20 Correct 16 ms 18384 KB Output is correct
21 Correct 16 ms 18384 KB Output is correct
22 Correct 12 ms 18256 KB Output is correct
23 Correct 13 ms 18264 KB Output is correct
24 Correct 12 ms 18324 KB Output is correct
25 Correct 12 ms 18384 KB Output is correct
26 Correct 12 ms 18296 KB Output is correct
27 Correct 12 ms 18384 KB Output is correct
28 Correct 12 ms 18384 KB Output is correct
29 Correct 13 ms 18384 KB Output is correct
30 Correct 12 ms 18384 KB Output is correct
31 Correct 11 ms 18640 KB Output is correct
32 Correct 14 ms 18344 KB Output is correct
33 Correct 12 ms 18384 KB Output is correct
34 Correct 12 ms 18344 KB Output is correct
35 Correct 12 ms 18384 KB Output is correct
36 Correct 17 ms 18664 KB Output is correct
37 Correct 13 ms 18624 KB Output is correct
38 Correct 13 ms 18672 KB Output is correct
39 Correct 12 ms 18384 KB Output is correct
40 Correct 13 ms 18384 KB Output is correct
41 Correct 12 ms 18384 KB Output is correct
42 Correct 12 ms 18384 KB Output is correct
43 Correct 685 ms 21088 KB Output is correct
44 Correct 941 ms 23700 KB Output is correct
45 Correct 997 ms 23628 KB Output is correct
46 Correct 876 ms 23688 KB Output is correct
47 Correct 947 ms 21148 KB Output is correct
48 Correct 977 ms 23688 KB Output is correct
49 Correct 1195 ms 23632 KB Output is correct
50 Correct 1056 ms 23716 KB Output is correct
51 Correct 480 ms 18480 KB Output is correct
52 Correct 971 ms 18584 KB Output is correct
53 Correct 904 ms 18660 KB Output is correct
54 Correct 1024 ms 18588 KB Output is correct
55 Correct 1106 ms 25980 KB Output is correct
56 Correct 1253 ms 26144 KB Output is correct
57 Correct 1138 ms 26148 KB Output is correct
58 Correct 875 ms 26012 KB Output is correct
59 Correct 1073 ms 57416 KB Output is correct
60 Correct 1041 ms 57372 KB Output is correct
61 Correct 637 ms 18512 KB Output is correct
62 Correct 923 ms 18640 KB Output is correct
63 Correct 778 ms 18512 KB Output is correct
64 Correct 956 ms 18768 KB Output is correct
65 Correct 812 ms 18728 KB Output is correct
66 Correct 890 ms 18784 KB Output is correct
67 Correct 1064 ms 18768 KB Output is correct
68 Correct 889 ms 18696 KB Output is correct
69 Correct 885 ms 18768 KB Output is correct
70 Correct 961 ms 18768 KB Output is correct
71 Correct 741 ms 19920 KB Output is correct
72 Correct 959 ms 18760 KB Output is correct
73 Correct 930 ms 18704 KB Output is correct
74 Correct 936 ms 18556 KB Output is correct
75 Correct 796 ms 18596 KB Output is correct
76 Correct 953 ms 20304 KB Output is correct
77 Correct 960 ms 20304 KB Output is correct
78 Correct 677 ms 20380 KB Output is correct
79 Correct 986 ms 18896 KB Output is correct
80 Correct 857 ms 18512 KB Output is correct
81 Correct 708 ms 18512 KB Output is correct
82 Correct 935 ms 18512 KB Output is correct
83 Correct 452 ms 18440 KB Output is correct
84 Correct 847 ms 18640 KB Output is correct
85 Correct 967 ms 18624 KB Output is correct
86 Correct 836 ms 18640 KB Output is correct
87 Correct 11 ms 18256 KB Output is correct
88 Correct 648 ms 25764 KB Output is correct
89 Correct 943 ms 23720 KB Output is correct
90 Correct 966 ms 23752 KB Output is correct
91 Correct 857 ms 26652 KB Output is correct
92 Correct 1026 ms 26652 KB Output is correct
93 Correct 978 ms 26776 KB Output is correct
94 Correct 1157 ms 26700 KB Output is correct
95 Correct 1010 ms 26652 KB Output is correct
96 Correct 816 ms 25416 KB Output is correct
97 Correct 890 ms 25484 KB Output is correct
98 Correct 838 ms 51108 KB Output is correct
99 Correct 884 ms 26056 KB Output is correct
100 Correct 1081 ms 25032 KB Output is correct
101 Correct 981 ms 24432 KB Output is correct
102 Correct 872 ms 23200 KB Output is correct
103 Correct 1077 ms 57460 KB Output is correct
104 Correct 1039 ms 57532 KB Output is correct
105 Correct 841 ms 57552 KB Output is correct
106 Correct 1022 ms 30148 KB Output is correct
107 Correct 862 ms 22988 KB Output is correct
108 Correct 936 ms 23388 KB Output is correct
109 Correct 992 ms 23448 KB Output is correct