Submission #629743

# Submission time Handle Problem Language Result Execution time Memory
629743 2022-08-15T02:49:05 Z MatheusLealV Digital Circuit (IOI22_circuit) C++17
100 / 100
1073 ms 27356 KB
#include "circuit.h"
#include <bits/stdc++.h>
#define N 200020
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long ll;
const ll mod = 1000002022;
 
ll yes[N], no[N], state[N],pai[N], n,m;
ll save[N], sum[N];
vector<ll> grafo[N];

ll pref[N], ans = 0;

void solve(){
	for(ll x=n;x<n+m+1;x++)yes[x]=state[x],no[x]=1-state[x],save[x]=sum[x]=1;
	pref[0]=1;
	for(ll x = n-1; x >= 0; x--){
		ll sum_cost = 1, C = sz(grafo[x]);
		no[x]=yes[x]=0;
		for(auto v: grafo[x]){
			ll old_yes = yes[x];

 			yes[x] = (1LL*old_yes*sum[v])%mod + (1LL*sum_cost*yes[v])%mod;
 			yes[x] %= mod;
 			pref[v] = sum_cost;
			sum_cost = (1LL*sum_cost*sum[v])%mod;
		}
		reverse(all(grafo[x]));
		ll suf = 1;
		for(auto v: grafo[x]){
			pref[v] = (1LL*pref[v]*suf)%mod;
			suf = (1LL*suf*sum[v])%mod;
		}

		if(save[x] == -1) save[x] = sum_cost;
		assert(save[x] == sum_cost);
		no[x] = (1LL*C*sum_cost%mod - yes[x])%mod;
		no[x] = (no[x] + mod)%mod;
		sum[x] = (yes[x] + no[x])%mod;
	}

	for(ll i = 0; i < n+m; i++){
		if(i)pref[i] = (pref[i] * pref[pai[i]])%mod;
	}
}
ll cnt[4*N][2],lazy[4*N],custo[N];
#define mid ((a+b)/2)
void build(int nod, int a, int b){
	if(a==b){
		cnt[nod][custo[a]] = pref[a+n];
		return;
	}
	build(2*nod,a,mid); build(2*nod+1,mid+1,b);
	cnt[nod][0] = (cnt[2*nod][0]+cnt[2*nod+1][0])%mod;
	cnt[nod][1] = (cnt[2*nod][1]+cnt[2*nod+1][1])%mod;
}
void prop(int nod, int a, int b){
	if(!lazy[nod]) return;
	swap(cnt[nod][0],cnt[nod][1]);
	lazy[nod]=0;
	if(a != b){
		lazy[2*nod] ^= 1;
		lazy[2*nod+1] ^= 1;
	}
}
void upd(int nod, int a, int b, int i, int j){
	prop(nod,a,b);
	if(j < a or i > b) return;
	if(i <= a and j >= b){
		lazy[nod] ^= 1;
		prop(nod,a,b);
		return;
	}
	upd(2*nod,a,mid,i,j); upd(2*nod+1,mid+1,b,i,j);
	cnt[nod][0] = (cnt[2*nod][0] + cnt[2*nod+1][0])%mod;
	cnt[nod][1] = (cnt[2*nod][1] + cnt[2*nod+1][1])%mod;
}
 
void init(int n_, int m_, vector<int> P, vector<int> A) {
	memset(save,-1,sizeof save);
	n = n_, m = m_;
	for(int i = 1; i < n+m; i++){
		grafo[P[i]].pb(i);
		pai[i] = P[i];
	}
	for(int i = 0;i<m;i++) state[i+n] = A[i],custo[i]=A[i];
	solve();

	build(1,0,m-1);
}
 
int count_ways(int L, int R) {

	upd(1,0,m-1,L-n,R-n);
	prop(1,0,m-1);
  	return cnt[1][1];
 
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6608 KB Output is correct
2 Correct 3 ms 6528 KB Output is correct
3 Correct 3 ms 6748 KB Output is correct
4 Correct 4 ms 6740 KB Output is correct
5 Correct 4 ms 6736 KB Output is correct
6 Correct 4 ms 6736 KB Output is correct
7 Correct 4 ms 6736 KB Output is correct
8 Correct 4 ms 6736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6608 KB Output is correct
2 Correct 4 ms 6608 KB Output is correct
3 Correct 4 ms 6616 KB Output is correct
4 Correct 4 ms 6608 KB Output is correct
5 Correct 4 ms 6608 KB Output is correct
6 Correct 4 ms 6736 KB Output is correct
7 Correct 4 ms 6736 KB Output is correct
8 Correct 4 ms 6736 KB Output is correct
9 Correct 4 ms 6736 KB Output is correct
10 Correct 4 ms 6736 KB Output is correct
11 Correct 4 ms 6736 KB Output is correct
12 Correct 4 ms 6736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6608 KB Output is correct
2 Correct 3 ms 6528 KB Output is correct
3 Correct 3 ms 6748 KB Output is correct
4 Correct 4 ms 6740 KB Output is correct
5 Correct 4 ms 6736 KB Output is correct
6 Correct 4 ms 6736 KB Output is correct
7 Correct 4 ms 6736 KB Output is correct
8 Correct 4 ms 6736 KB Output is correct
9 Correct 3 ms 6608 KB Output is correct
10 Correct 4 ms 6608 KB Output is correct
11 Correct 4 ms 6616 KB Output is correct
12 Correct 4 ms 6608 KB Output is correct
13 Correct 4 ms 6608 KB Output is correct
14 Correct 4 ms 6736 KB Output is correct
15 Correct 4 ms 6736 KB Output is correct
16 Correct 4 ms 6736 KB Output is correct
17 Correct 4 ms 6736 KB Output is correct
18 Correct 4 ms 6736 KB Output is correct
19 Correct 4 ms 6736 KB Output is correct
20 Correct 4 ms 6736 KB Output is correct
21 Correct 4 ms 6736 KB Output is correct
22 Correct 4 ms 6736 KB Output is correct
23 Correct 4 ms 6736 KB Output is correct
24 Correct 4 ms 6736 KB Output is correct
25 Correct 4 ms 6816 KB Output is correct
26 Correct 4 ms 6736 KB Output is correct
27 Correct 4 ms 6736 KB Output is correct
28 Correct 4 ms 6736 KB Output is correct
29 Correct 5 ms 6736 KB Output is correct
30 Correct 4 ms 6736 KB Output is correct
31 Correct 5 ms 6608 KB Output is correct
32 Correct 4 ms 6736 KB Output is correct
33 Correct 4 ms 6780 KB Output is correct
34 Correct 5 ms 6736 KB Output is correct
35 Correct 4 ms 6736 KB Output is correct
36 Correct 4 ms 6736 KB Output is correct
37 Correct 4 ms 6736 KB Output is correct
38 Correct 4 ms 6736 KB Output is correct
39 Correct 4 ms 6608 KB Output is correct
40 Correct 4 ms 6736 KB Output is correct
41 Correct 4 ms 6736 KB Output is correct
42 Correct 4 ms 6744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 674 ms 12416 KB Output is correct
2 Correct 938 ms 18300 KB Output is correct
3 Correct 746 ms 18376 KB Output is correct
4 Correct 826 ms 18376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 674 ms 12416 KB Output is correct
2 Correct 938 ms 18300 KB Output is correct
3 Correct 746 ms 18376 KB Output is correct
4 Correct 826 ms 18376 KB Output is correct
5 Correct 705 ms 12648 KB Output is correct
6 Correct 942 ms 18668 KB Output is correct
7 Correct 1050 ms 18780 KB Output is correct
8 Correct 787 ms 18284 KB Output is correct
9 Correct 430 ms 6992 KB Output is correct
10 Correct 774 ms 7376 KB Output is correct
11 Correct 760 ms 7376 KB Output is correct
12 Correct 787 ms 7248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6608 KB Output is correct
2 Correct 4 ms 6608 KB Output is correct
3 Correct 4 ms 6616 KB Output is correct
4 Correct 4 ms 6608 KB Output is correct
5 Correct 4 ms 6608 KB Output is correct
6 Correct 4 ms 6736 KB Output is correct
7 Correct 4 ms 6736 KB Output is correct
8 Correct 4 ms 6736 KB Output is correct
9 Correct 4 ms 6736 KB Output is correct
10 Correct 4 ms 6736 KB Output is correct
11 Correct 4 ms 6736 KB Output is correct
12 Correct 4 ms 6736 KB Output is correct
13 Correct 674 ms 12416 KB Output is correct
14 Correct 938 ms 18300 KB Output is correct
15 Correct 746 ms 18376 KB Output is correct
16 Correct 826 ms 18376 KB Output is correct
17 Correct 705 ms 12648 KB Output is correct
18 Correct 942 ms 18668 KB Output is correct
19 Correct 1050 ms 18780 KB Output is correct
20 Correct 787 ms 18284 KB Output is correct
21 Correct 430 ms 6992 KB Output is correct
22 Correct 774 ms 7376 KB Output is correct
23 Correct 760 ms 7376 KB Output is correct
24 Correct 787 ms 7248 KB Output is correct
25 Correct 1000 ms 26340 KB Output is correct
26 Correct 1073 ms 26448 KB Output is correct
27 Correct 1020 ms 26664 KB Output is correct
28 Correct 463 ms 25476 KB Output is correct
29 Correct 956 ms 26472 KB Output is correct
30 Correct 940 ms 25544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6608 KB Output is correct
2 Correct 3 ms 6528 KB Output is correct
3 Correct 3 ms 6748 KB Output is correct
4 Correct 4 ms 6740 KB Output is correct
5 Correct 4 ms 6736 KB Output is correct
6 Correct 4 ms 6736 KB Output is correct
7 Correct 4 ms 6736 KB Output is correct
8 Correct 4 ms 6736 KB Output is correct
9 Correct 3 ms 6608 KB Output is correct
10 Correct 4 ms 6608 KB Output is correct
11 Correct 4 ms 6616 KB Output is correct
12 Correct 4 ms 6608 KB Output is correct
13 Correct 4 ms 6608 KB Output is correct
14 Correct 4 ms 6736 KB Output is correct
15 Correct 4 ms 6736 KB Output is correct
16 Correct 4 ms 6736 KB Output is correct
17 Correct 4 ms 6736 KB Output is correct
18 Correct 4 ms 6736 KB Output is correct
19 Correct 4 ms 6736 KB Output is correct
20 Correct 4 ms 6736 KB Output is correct
21 Correct 4 ms 6736 KB Output is correct
22 Correct 4 ms 6736 KB Output is correct
23 Correct 4 ms 6736 KB Output is correct
24 Correct 4 ms 6736 KB Output is correct
25 Correct 4 ms 6816 KB Output is correct
26 Correct 4 ms 6736 KB Output is correct
27 Correct 4 ms 6736 KB Output is correct
28 Correct 4 ms 6736 KB Output is correct
29 Correct 5 ms 6736 KB Output is correct
30 Correct 4 ms 6736 KB Output is correct
31 Correct 5 ms 6608 KB Output is correct
32 Correct 4 ms 6736 KB Output is correct
33 Correct 4 ms 6780 KB Output is correct
34 Correct 5 ms 6736 KB Output is correct
35 Correct 4 ms 6736 KB Output is correct
36 Correct 4 ms 6736 KB Output is correct
37 Correct 4 ms 6736 KB Output is correct
38 Correct 4 ms 6736 KB Output is correct
39 Correct 4 ms 6608 KB Output is correct
40 Correct 4 ms 6736 KB Output is correct
41 Correct 4 ms 6736 KB Output is correct
42 Correct 4 ms 6744 KB Output is correct
43 Correct 465 ms 7248 KB Output is correct
44 Correct 831 ms 7248 KB Output is correct
45 Correct 546 ms 7248 KB Output is correct
46 Correct 878 ms 7632 KB Output is correct
47 Correct 849 ms 7760 KB Output is correct
48 Correct 858 ms 7760 KB Output is correct
49 Correct 657 ms 7760 KB Output is correct
50 Correct 1047 ms 7632 KB Output is correct
51 Correct 916 ms 7348 KB Output is correct
52 Correct 753 ms 7444 KB Output is correct
53 Correct 646 ms 6992 KB Output is correct
54 Correct 726 ms 7632 KB Output is correct
55 Correct 850 ms 7484 KB Output is correct
56 Correct 799 ms 7504 KB Output is correct
57 Correct 970 ms 7376 KB Output is correct
58 Correct 1002 ms 7640 KB Output is correct
59 Correct 902 ms 7836 KB Output is correct
60 Correct 758 ms 7632 KB Output is correct
61 Correct 780 ms 7280 KB Output is correct
62 Correct 616 ms 7120 KB Output is correct
63 Correct 943 ms 7120 KB Output is correct
64 Correct 792 ms 7376 KB Output is correct
65 Correct 447 ms 6992 KB Output is correct
66 Correct 965 ms 7376 KB Output is correct
67 Correct 838 ms 7372 KB Output is correct
68 Correct 842 ms 7248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6608 KB Output is correct
2 Correct 3 ms 6528 KB Output is correct
3 Correct 3 ms 6748 KB Output is correct
4 Correct 4 ms 6740 KB Output is correct
5 Correct 4 ms 6736 KB Output is correct
6 Correct 4 ms 6736 KB Output is correct
7 Correct 4 ms 6736 KB Output is correct
8 Correct 4 ms 6736 KB Output is correct
9 Correct 3 ms 6608 KB Output is correct
10 Correct 4 ms 6608 KB Output is correct
11 Correct 4 ms 6616 KB Output is correct
12 Correct 4 ms 6608 KB Output is correct
13 Correct 4 ms 6608 KB Output is correct
14 Correct 4 ms 6736 KB Output is correct
15 Correct 4 ms 6736 KB Output is correct
16 Correct 4 ms 6736 KB Output is correct
17 Correct 4 ms 6736 KB Output is correct
18 Correct 4 ms 6736 KB Output is correct
19 Correct 4 ms 6736 KB Output is correct
20 Correct 4 ms 6736 KB Output is correct
21 Correct 4 ms 6736 KB Output is correct
22 Correct 4 ms 6736 KB Output is correct
23 Correct 4 ms 6736 KB Output is correct
24 Correct 4 ms 6736 KB Output is correct
25 Correct 4 ms 6816 KB Output is correct
26 Correct 4 ms 6736 KB Output is correct
27 Correct 4 ms 6736 KB Output is correct
28 Correct 4 ms 6736 KB Output is correct
29 Correct 5 ms 6736 KB Output is correct
30 Correct 4 ms 6736 KB Output is correct
31 Correct 5 ms 6608 KB Output is correct
32 Correct 4 ms 6736 KB Output is correct
33 Correct 4 ms 6780 KB Output is correct
34 Correct 5 ms 6736 KB Output is correct
35 Correct 4 ms 6736 KB Output is correct
36 Correct 4 ms 6736 KB Output is correct
37 Correct 4 ms 6736 KB Output is correct
38 Correct 4 ms 6736 KB Output is correct
39 Correct 4 ms 6608 KB Output is correct
40 Correct 4 ms 6736 KB Output is correct
41 Correct 4 ms 6736 KB Output is correct
42 Correct 4 ms 6744 KB Output is correct
43 Correct 674 ms 12416 KB Output is correct
44 Correct 938 ms 18300 KB Output is correct
45 Correct 746 ms 18376 KB Output is correct
46 Correct 826 ms 18376 KB Output is correct
47 Correct 705 ms 12648 KB Output is correct
48 Correct 942 ms 18668 KB Output is correct
49 Correct 1050 ms 18780 KB Output is correct
50 Correct 787 ms 18284 KB Output is correct
51 Correct 430 ms 6992 KB Output is correct
52 Correct 774 ms 7376 KB Output is correct
53 Correct 760 ms 7376 KB Output is correct
54 Correct 787 ms 7248 KB Output is correct
55 Correct 1000 ms 26340 KB Output is correct
56 Correct 1073 ms 26448 KB Output is correct
57 Correct 1020 ms 26664 KB Output is correct
58 Correct 463 ms 25476 KB Output is correct
59 Correct 956 ms 26472 KB Output is correct
60 Correct 940 ms 25544 KB Output is correct
61 Correct 465 ms 7248 KB Output is correct
62 Correct 831 ms 7248 KB Output is correct
63 Correct 546 ms 7248 KB Output is correct
64 Correct 878 ms 7632 KB Output is correct
65 Correct 849 ms 7760 KB Output is correct
66 Correct 858 ms 7760 KB Output is correct
67 Correct 657 ms 7760 KB Output is correct
68 Correct 1047 ms 7632 KB Output is correct
69 Correct 916 ms 7348 KB Output is correct
70 Correct 753 ms 7444 KB Output is correct
71 Correct 646 ms 6992 KB Output is correct
72 Correct 726 ms 7632 KB Output is correct
73 Correct 850 ms 7484 KB Output is correct
74 Correct 799 ms 7504 KB Output is correct
75 Correct 970 ms 7376 KB Output is correct
76 Correct 1002 ms 7640 KB Output is correct
77 Correct 902 ms 7836 KB Output is correct
78 Correct 758 ms 7632 KB Output is correct
79 Correct 780 ms 7280 KB Output is correct
80 Correct 616 ms 7120 KB Output is correct
81 Correct 943 ms 7120 KB Output is correct
82 Correct 792 ms 7376 KB Output is correct
83 Correct 447 ms 6992 KB Output is correct
84 Correct 965 ms 7376 KB Output is correct
85 Correct 838 ms 7372 KB Output is correct
86 Correct 842 ms 7248 KB Output is correct
87 Correct 3 ms 6608 KB Output is correct
88 Correct 538 ms 25348 KB Output is correct
89 Correct 985 ms 18708 KB Output is correct
90 Correct 934 ms 18616 KB Output is correct
91 Correct 717 ms 26632 KB Output is correct
92 Correct 948 ms 27056 KB Output is correct
93 Correct 1055 ms 27068 KB Output is correct
94 Correct 930 ms 27052 KB Output is correct
95 Correct 1010 ms 26140 KB Output is correct
96 Correct 920 ms 18628 KB Output is correct
97 Correct 938 ms 19944 KB Output is correct
98 Correct 787 ms 14408 KB Output is correct
99 Correct 856 ms 26440 KB Output is correct
100 Correct 987 ms 23744 KB Output is correct
101 Correct 748 ms 22216 KB Output is correct
102 Correct 917 ms 20020 KB Output is correct
103 Correct 953 ms 26440 KB Output is correct
104 Correct 1051 ms 27356 KB Output is correct
105 Correct 677 ms 26364 KB Output is correct
106 Correct 947 ms 18200 KB Output is correct
107 Correct 879 ms 20504 KB Output is correct
108 Correct 840 ms 20708 KB Output is correct
109 Correct 901 ms 20176 KB Output is correct