Submission #693759

# Submission time Handle Problem Language Result Execution time Memory
693759 2023-02-03T08:01:25 Z Pyqe Digital Circuit (IOI22_circuit) C++17
100 / 100
1268 ms 48732 KB
#include <bits/stdc++.h>
#include "circuit.h"

using namespace std;

const long long dv=1e9+2022;
long long n,m,pr[200069],a[100069],dp[200069],wg[100069];
vector<long long> al[200069];

struct segtree
{
	long long l,r,sm[2];
	bool iv;
	segtree *p[2];
	
	void bd(long long lh,long long rh)
	{
		l=lh;
		r=rh;
		iv=0;
		if(l==r)
		{
			sm[a[l]]=wg[l];
			sm[!a[l]]=0;
		}
		else
		{
			long long ii,md=(l+r)/2;
			
			for(ii=0;ii<2;ii++)
			{
				p[ii]=new segtree;
				p[ii]->bd(!ii?l:md+1,!ii?md:r);
			}
			for(ii=0;ii<2;ii++)
			{
				sm[ii]=(p[0]->sm[ii]+p[1]->sm[ii])%dv;
			}
		}
	}
	inline void blc()
	{
		if(iv)
		{
			long long ii;
			
			for(ii=0;ii<2;ii++)
			{
				swap(p[ii]->sm[0],p[ii]->sm[1]);
				p[ii]->iv^=1;
			}
			iv=0;
		}
	}
	void ud(long long lh,long long rh)
	{
		if(l>rh||r<lh);
		else if(l>=lh&&r<=rh)
		{
			swap(sm[0],sm[1]);
			iv^=1;
		}
		else
		{
			long long ii;
			
			blc();
			for(ii=0;ii<2;ii++)
			{
				p[ii]->ud(lh,rh);
			}
			for(ii=0;ii<2;ii++)
			{
				sm[ii]=(p[0]->sm[ii]+p[1]->sm[ii])%dv;
			}
		}
	}
}
sg;

void dfs(long long x)
{
	long long i,sz=al[x].size(),l;
	
	dp[x]=max(sz,1ll);
	for(i=0;i<sz;i++)
	{
		l=al[x][i];
		dfs(l);
		dp[x]=dp[x]*dp[l]%dv;
	}
}

void dfs2(long long x,long long cw)
{
	if(x<=n)
	{
		long long i,sz=al[x].size(),l;
		vector<long long> mla,mla2;
		
		mla.push_back(1);
		for(i=0;i<sz;i++)
		{
			l=al[x][i];
			mla.push_back(mla[i]*dp[l]%dv);
		}
		mla2.push_back(1);
		for(i=sz-1;i>=0;i--)
		{
			l=al[x][i];
			mla2.push_back(mla2[sz-1-i]*dp[l]%dv);
		}
		for(i=0;i<sz;i++)
		{
			l=al[x][i];
			dfs2(l,cw*mla[i]%dv*mla2[sz-1-i]%dv);
		}
	}
	else
	{
		wg[x-n]=cw;
	}
}

void init(int on,int om,vector<int> prr,vector<int> aa)
{
	long long i;
	
	n=on;
	m=om;
	for(i=1;i<=n+m;i++)
	{
		pr[i]=prr[i-1]+1;
	}
	for(i=1;i<=m;i++)
	{
		a[i]=aa[i-1];
	}
	for(i=2;i<=n+m;i++)
	{
		al[pr[i]].push_back(i);
	}
	dfs(1);
	dfs2(1,1);
	sg.bd(1,m);
}

int count_ways(int lb,int rb)
{
	lb++;
	rb++;
	lb-=n;
	rb-=n;
	sg.ud(lb,rb);
	return sg.sm[1];
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5008 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 5200 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5200 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 4 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 4 ms 5200 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
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5008 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 5200 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5200 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 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 4 ms 5200 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 4 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 3 ms 5200 KB Output is correct
26 Correct 5 ms 5200 KB Output is correct
27 Correct 4 ms 5200 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 3 ms 5200 KB Output is correct
30 Correct 3 ms 5200 KB Output is correct
31 Correct 3 ms 5328 KB Output is correct
32 Correct 3 ms 5164 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 5456 KB Output is correct
37 Correct 4 ms 5396 KB Output is correct
38 Correct 4 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 5092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 480 ms 12380 KB Output is correct
2 Correct 1127 ms 19852 KB Output is correct
3 Correct 870 ms 19832 KB Output is correct
4 Correct 874 ms 19852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 480 ms 12380 KB Output is correct
2 Correct 1127 ms 19852 KB Output is correct
3 Correct 870 ms 19832 KB Output is correct
4 Correct 874 ms 19852 KB Output is correct
5 Correct 771 ms 12408 KB Output is correct
6 Correct 946 ms 19792 KB Output is correct
7 Correct 924 ms 19864 KB Output is correct
8 Correct 838 ms 19860 KB Output is correct
9 Correct 417 ms 5456 KB Output is correct
10 Correct 1022 ms 5840 KB Output is correct
11 Correct 1029 ms 5892 KB Output is correct
12 Correct 997 ms 5840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 4 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 4 ms 5200 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 480 ms 12380 KB Output is correct
14 Correct 1127 ms 19852 KB Output is correct
15 Correct 870 ms 19832 KB Output is correct
16 Correct 874 ms 19852 KB Output is correct
17 Correct 771 ms 12408 KB Output is correct
18 Correct 946 ms 19792 KB Output is correct
19 Correct 924 ms 19864 KB Output is correct
20 Correct 838 ms 19860 KB Output is correct
21 Correct 417 ms 5456 KB Output is correct
22 Correct 1022 ms 5840 KB Output is correct
23 Correct 1029 ms 5892 KB Output is correct
24 Correct 997 ms 5840 KB Output is correct
25 Correct 1268 ms 27288 KB Output is correct
26 Correct 1067 ms 27596 KB Output is correct
27 Correct 1078 ms 27648 KB Output is correct
28 Correct 731 ms 27592 KB Output is correct
29 Correct 892 ms 48004 KB Output is correct
30 Correct 922 ms 47944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5008 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 5200 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5200 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 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 4 ms 5200 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 4 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 3 ms 5200 KB Output is correct
26 Correct 5 ms 5200 KB Output is correct
27 Correct 4 ms 5200 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 3 ms 5200 KB Output is correct
30 Correct 3 ms 5200 KB Output is correct
31 Correct 3 ms 5328 KB Output is correct
32 Correct 3 ms 5164 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 5456 KB Output is correct
37 Correct 4 ms 5396 KB Output is correct
38 Correct 4 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 5092 KB Output is correct
43 Correct 533 ms 5584 KB Output is correct
44 Correct 922 ms 5584 KB Output is correct
45 Correct 803 ms 5584 KB Output is correct
46 Correct 767 ms 6156 KB Output is correct
47 Correct 858 ms 6096 KB Output is correct
48 Correct 841 ms 6096 KB Output is correct
49 Correct 890 ms 6096 KB Output is correct
50 Correct 717 ms 6096 KB Output is correct
51 Correct 956 ms 5840 KB Output is correct
52 Correct 743 ms 5840 KB Output is correct
53 Correct 626 ms 6536 KB Output is correct
54 Correct 909 ms 6096 KB Output is correct
55 Correct 895 ms 5968 KB Output is correct
56 Correct 876 ms 5896 KB Output is correct
57 Correct 861 ms 5840 KB Output is correct
58 Correct 1010 ms 7108 KB Output is correct
59 Correct 914 ms 7136 KB Output is correct
60 Correct 767 ms 7208 KB Output is correct
61 Correct 992 ms 5768 KB Output is correct
62 Correct 938 ms 5712 KB Output is correct
63 Correct 840 ms 5792 KB Output is correct
64 Correct 980 ms 5888 KB Output is correct
65 Correct 358 ms 5456 KB Output is correct
66 Correct 904 ms 5896 KB Output is correct
67 Correct 714 ms 5840 KB Output is correct
68 Correct 808 ms 5840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5008 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 5200 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5200 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 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 4 ms 5200 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 4 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 3 ms 5200 KB Output is correct
26 Correct 5 ms 5200 KB Output is correct
27 Correct 4 ms 5200 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 3 ms 5200 KB Output is correct
30 Correct 3 ms 5200 KB Output is correct
31 Correct 3 ms 5328 KB Output is correct
32 Correct 3 ms 5164 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 5456 KB Output is correct
37 Correct 4 ms 5396 KB Output is correct
38 Correct 4 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 5092 KB Output is correct
43 Correct 480 ms 12380 KB Output is correct
44 Correct 1127 ms 19852 KB Output is correct
45 Correct 870 ms 19832 KB Output is correct
46 Correct 874 ms 19852 KB Output is correct
47 Correct 771 ms 12408 KB Output is correct
48 Correct 946 ms 19792 KB Output is correct
49 Correct 924 ms 19864 KB Output is correct
50 Correct 838 ms 19860 KB Output is correct
51 Correct 417 ms 5456 KB Output is correct
52 Correct 1022 ms 5840 KB Output is correct
53 Correct 1029 ms 5892 KB Output is correct
54 Correct 997 ms 5840 KB Output is correct
55 Correct 1268 ms 27288 KB Output is correct
56 Correct 1067 ms 27596 KB Output is correct
57 Correct 1078 ms 27648 KB Output is correct
58 Correct 731 ms 27592 KB Output is correct
59 Correct 892 ms 48004 KB Output is correct
60 Correct 922 ms 47944 KB Output is correct
61 Correct 533 ms 5584 KB Output is correct
62 Correct 922 ms 5584 KB Output is correct
63 Correct 803 ms 5584 KB Output is correct
64 Correct 767 ms 6156 KB Output is correct
65 Correct 858 ms 6096 KB Output is correct
66 Correct 841 ms 6096 KB Output is correct
67 Correct 890 ms 6096 KB Output is correct
68 Correct 717 ms 6096 KB Output is correct
69 Correct 956 ms 5840 KB Output is correct
70 Correct 743 ms 5840 KB Output is correct
71 Correct 626 ms 6536 KB Output is correct
72 Correct 909 ms 6096 KB Output is correct
73 Correct 895 ms 5968 KB Output is correct
74 Correct 876 ms 5896 KB Output is correct
75 Correct 861 ms 5840 KB Output is correct
76 Correct 1010 ms 7108 KB Output is correct
77 Correct 914 ms 7136 KB Output is correct
78 Correct 767 ms 7208 KB Output is correct
79 Correct 992 ms 5768 KB Output is correct
80 Correct 938 ms 5712 KB Output is correct
81 Correct 840 ms 5792 KB Output is correct
82 Correct 980 ms 5888 KB Output is correct
83 Correct 358 ms 5456 KB Output is correct
84 Correct 904 ms 5896 KB Output is correct
85 Correct 714 ms 5840 KB Output is correct
86 Correct 808 ms 5840 KB Output is correct
87 Correct 3 ms 5072 KB Output is correct
88 Correct 689 ms 24704 KB Output is correct
89 Correct 878 ms 17648 KB Output is correct
90 Correct 871 ms 18832 KB Output is correct
91 Correct 965 ms 28188 KB Output is correct
92 Correct 1069 ms 28312 KB Output is correct
93 Correct 1022 ms 28276 KB Output is correct
94 Correct 1114 ms 28328 KB Output is correct
95 Correct 1027 ms 28232 KB Output is correct
96 Correct 911 ms 22992 KB Output is correct
97 Correct 952 ms 23004 KB Output is correct
98 Correct 845 ms 37064 KB Output is correct
99 Correct 1178 ms 27636 KB Output is correct
100 Correct 925 ms 25820 KB Output is correct
101 Correct 1029 ms 24816 KB Output is correct
102 Correct 971 ms 23040 KB Output is correct
103 Correct 1094 ms 48028 KB Output is correct
104 Correct 1012 ms 48728 KB Output is correct
105 Correct 980 ms 48732 KB Output is correct
106 Correct 1109 ms 20984 KB Output is correct
107 Correct 969 ms 18940 KB Output is correct
108 Correct 832 ms 20700 KB Output is correct
109 Correct 996 ms 23292 KB Output is correct