Submission #639359

# Submission time Handle Problem Language Result Execution time Memory
639359 2022-09-09T16:18:22 Z CSQ31 Digital Circuit (IOI22_circuit) C++17
46 / 100
1053 ms 14064 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD = 1000002022;
const int MAXN = 1e5+5;
vector<int>adj[MAXN];
ll c[MAXN],sub[MAXN];
int n,m;
void dfs(int v){
	if(adj[v].empty())sub[v] = 1;
	else sub[v] = adj[v].size();
	for(int x:adj[v]){
		dfs(x);
		sub[v] = sub[v]*sub[x]%MOD;
	}
	
}
void dfs(int v,ll cur){
	if(adj[v].empty()){
		c[v-n] = cur;
		return;
	}
	int s = adj[v].size();
	vector<ll>pref(s,1),suff(s,1);
	for(int i=0;i<s;i++){
		pref[i] = sub[adj[v][i]];
		suff[i] = sub[adj[v][i]];
		if(i)pref[i] = pref[i]*pref[i-1]%MOD;
	}
	for(int i=s-2;i>=0;i--)suff[i] = suff[i]*suff[i+1]%MOD;
	
	for(int i=0;i<s;i++){
		ll k = 1;
		if(i)k = pref[i-1]*k%MOD;
		if(i!=s-1)k = suff[i+1]*k%MOD;
		dfs(adj[v][i],(cur*k)%MOD);
		
	}
}
ll ans = 0;
vector<int>a;
ll t[4*MAXN],sum[4*MAXN];
bool lazy[4*MAXN];
void pushdown(int v){
	if(lazy[v]){
		t[2*v] = sum[2*v] - t[2*v] + MOD;
		t[2*v+1] = sum[2*v+1] - t[2*v+1] + MOD;
		if(t[2*v]>=MOD)t[2*v]-=MOD;
		if(t[2*v+1]>=MOD)t[2*v+1]-=MOD;	
		lazy[2*v]^=1;
		lazy[2*v+1]^=1;
		lazy[v] = 0;	
	}
	
}
void upd(int v,int l,int r,int tl,int tr){
	if(l>r)return;
	if(l==tl && r==tr){
		lazy[v]^=1;
		t[v] = sum[v]-t[v]+MOD;
		if(t[v]>=MOD)t[v]-=MOD;
		return;
	}
	int tm = (tl+tr)/2;
	pushdown(v);
	upd(2*v,l,min(r,tm),tl,tm);
	upd(2*v+1,max(tm+1,l),r,tm+1,tr);
	t[v] = t[2*v] + t[2*v+1];
	if(t[v]>=MOD)t[v]-=MOD;
}
void build(int v,int l,int r){
	if(l==r){
		sum[v] = c[l];
		if(a[l])t[v] = c[l];
		return;
	}
	int tm = (l+r)/2;
	build(2*v,l,tm);
	build(2*v+1,tm+1,r);
	t[v] = t[2*v]+t[2*v+1];
	sum[v] = sum[2*v]+sum[2*v+1];
	if(sum[v]>=MOD)sum[v]-=MOD;
	if(t[v]>=MOD)t[v]-=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++)adj[p[i]].push_back(i);
	dfs(0);
	dfs(0,1);
	build(1,0,m-1);
	
}

int count_ways(int L, int R) {
	L-=n;
	R-=n;
	upd(1,L,R,0,m-1);
	return t[1];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2768 KB Output is correct
6 Correct 2 ms 2768 KB Output is correct
7 Correct 2 ms 2768 KB Output is correct
8 Correct 2 ms 2768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2768 KB Output is correct
6 Correct 2 ms 2768 KB Output is correct
7 Correct 3 ms 2768 KB Output is correct
8 Correct 2 ms 2768 KB Output is correct
9 Correct 2 ms 2768 KB Output is correct
10 Correct 3 ms 2896 KB Output is correct
11 Correct 2 ms 2896 KB Output is correct
12 Correct 3 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2768 KB Output is correct
6 Correct 2 ms 2768 KB Output is correct
7 Correct 2 ms 2768 KB Output is correct
8 Correct 2 ms 2768 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2768 KB Output is correct
14 Correct 2 ms 2768 KB Output is correct
15 Correct 3 ms 2768 KB Output is correct
16 Correct 2 ms 2768 KB Output is correct
17 Correct 2 ms 2768 KB Output is correct
18 Correct 3 ms 2896 KB Output is correct
19 Correct 2 ms 2896 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 2 ms 2768 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2768 KB Output is correct
25 Correct 2 ms 2768 KB Output is correct
26 Correct 2 ms 2768 KB Output is correct
27 Correct 2 ms 2768 KB Output is correct
28 Correct 2 ms 2768 KB Output is correct
29 Correct 2 ms 2768 KB Output is correct
30 Correct 2 ms 2768 KB Output is correct
31 Correct 2 ms 2896 KB Output is correct
32 Correct 2 ms 2768 KB Output is correct
33 Correct 2 ms 2768 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 3 ms 2896 KB Output is correct
37 Correct 2 ms 2896 KB Output is correct
38 Correct 2 ms 2936 KB Output is correct
39 Correct 2 ms 2768 KB Output is correct
40 Correct 2 ms 2768 KB Output is correct
41 Correct 2 ms 2652 KB Output is correct
42 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 690 ms 6400 KB Output is correct
2 Runtime error 30 ms 14064 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 690 ms 6400 KB Output is correct
2 Runtime error 30 ms 14064 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2768 KB Output is correct
6 Correct 2 ms 2768 KB Output is correct
7 Correct 3 ms 2768 KB Output is correct
8 Correct 2 ms 2768 KB Output is correct
9 Correct 2 ms 2768 KB Output is correct
10 Correct 3 ms 2896 KB Output is correct
11 Correct 2 ms 2896 KB Output is correct
12 Correct 3 ms 2688 KB Output is correct
13 Correct 690 ms 6400 KB Output is correct
14 Runtime error 30 ms 14064 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2768 KB Output is correct
6 Correct 2 ms 2768 KB Output is correct
7 Correct 2 ms 2768 KB Output is correct
8 Correct 2 ms 2768 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2768 KB Output is correct
14 Correct 2 ms 2768 KB Output is correct
15 Correct 3 ms 2768 KB Output is correct
16 Correct 2 ms 2768 KB Output is correct
17 Correct 2 ms 2768 KB Output is correct
18 Correct 3 ms 2896 KB Output is correct
19 Correct 2 ms 2896 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 2 ms 2768 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2768 KB Output is correct
25 Correct 2 ms 2768 KB Output is correct
26 Correct 2 ms 2768 KB Output is correct
27 Correct 2 ms 2768 KB Output is correct
28 Correct 2 ms 2768 KB Output is correct
29 Correct 2 ms 2768 KB Output is correct
30 Correct 2 ms 2768 KB Output is correct
31 Correct 2 ms 2896 KB Output is correct
32 Correct 2 ms 2768 KB Output is correct
33 Correct 2 ms 2768 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 3 ms 2896 KB Output is correct
37 Correct 2 ms 2896 KB Output is correct
38 Correct 2 ms 2936 KB Output is correct
39 Correct 2 ms 2768 KB Output is correct
40 Correct 2 ms 2768 KB Output is correct
41 Correct 2 ms 2652 KB Output is correct
42 Correct 2 ms 2652 KB Output is correct
43 Correct 727 ms 3036 KB Output is correct
44 Correct 828 ms 3024 KB Output is correct
45 Correct 948 ms 3024 KB Output is correct
46 Correct 981 ms 3280 KB Output is correct
47 Correct 836 ms 3280 KB Output is correct
48 Correct 852 ms 3288 KB Output is correct
49 Correct 917 ms 3280 KB Output is correct
50 Correct 825 ms 3280 KB Output is correct
51 Correct 629 ms 3240 KB Output is correct
52 Correct 859 ms 3236 KB Output is correct
53 Correct 848 ms 3920 KB Output is correct
54 Correct 893 ms 3280 KB Output is correct
55 Correct 906 ms 3152 KB Output is correct
56 Correct 977 ms 3216 KB Output is correct
57 Correct 766 ms 3152 KB Output is correct
58 Correct 613 ms 4304 KB Output is correct
59 Correct 773 ms 4432 KB Output is correct
60 Correct 843 ms 4432 KB Output is correct
61 Correct 829 ms 3280 KB Output is correct
62 Correct 1053 ms 3024 KB Output is correct
63 Correct 849 ms 2896 KB Output is correct
64 Correct 911 ms 3152 KB Output is correct
65 Correct 474 ms 2896 KB Output is correct
66 Correct 754 ms 3024 KB Output is correct
67 Correct 724 ms 3024 KB Output is correct
68 Correct 925 ms 3152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2768 KB Output is correct
6 Correct 2 ms 2768 KB Output is correct
7 Correct 2 ms 2768 KB Output is correct
8 Correct 2 ms 2768 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2768 KB Output is correct
14 Correct 2 ms 2768 KB Output is correct
15 Correct 3 ms 2768 KB Output is correct
16 Correct 2 ms 2768 KB Output is correct
17 Correct 2 ms 2768 KB Output is correct
18 Correct 3 ms 2896 KB Output is correct
19 Correct 2 ms 2896 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 2 ms 2768 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2768 KB Output is correct
25 Correct 2 ms 2768 KB Output is correct
26 Correct 2 ms 2768 KB Output is correct
27 Correct 2 ms 2768 KB Output is correct
28 Correct 2 ms 2768 KB Output is correct
29 Correct 2 ms 2768 KB Output is correct
30 Correct 2 ms 2768 KB Output is correct
31 Correct 2 ms 2896 KB Output is correct
32 Correct 2 ms 2768 KB Output is correct
33 Correct 2 ms 2768 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 3 ms 2896 KB Output is correct
37 Correct 2 ms 2896 KB Output is correct
38 Correct 2 ms 2936 KB Output is correct
39 Correct 2 ms 2768 KB Output is correct
40 Correct 2 ms 2768 KB Output is correct
41 Correct 2 ms 2652 KB Output is correct
42 Correct 2 ms 2652 KB Output is correct
43 Correct 690 ms 6400 KB Output is correct
44 Runtime error 30 ms 14064 KB Execution killed with signal 11
45 Halted 0 ms 0 KB -