Submission #629740

# Submission time Handle Problem Language Result Execution time Memory
629740 2022-08-15T02:27:37 Z MatheusLealV Digital Circuit (IOI22_circuit) C++17
46 / 100
2775 ms 18248 KB
#include "circuit.h"
#include <bits/stdc++.h>
#define N 100020
#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], sum_pref[4*N],custo[N];
#define mid ((a+b)/2)
void build(int nod, int a, int b){
	if(a==b){
		cnt[nod][custo[a]] ++;
		sum_pref[nod] = 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];
	cnt[nod][1] += cnt[2*nod][1]+cnt[2*nod+1][1];
	sum_pref[nod] = (sum_pref[2*nod] + sum_pref[2*nod+1])%mod;
}
void prop(int nod, int a, int b){
	if(!lazy[nod]) return;
	ll delta = (sum_pref[nod]*(cnt[nod][0] - cnt[nod][1]))%mod;
	ans += delta;
	ans %= mod;
	if(ans < 0) ans += delta;
	swap(cnt[nod][0],cnt[nod][1]);
	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];
	cnt[nod][1] = cnt[2*nod][1] + cnt[2*nod+1][1];
}
 
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();
	ans = yes[0];
	build(1,0,m-1);
}
 
int count_ways(int L, int R) {

	// upd(1,0,m-1,L,R);
	for(int i = L; i <= R; i++){
		state[i] ^= 1;
		ll delta = (1LL*pref[i]*(no[i] - yes[i]))%mod;
		if(delta < 0) delta += mod;
		ans += delta;

		ans %= mod;
		swap(yes[i], no[i]);
	}
  	// solve();
  	return ans;
 
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 2 ms 3536 KB Output is correct
4 Correct 2 ms 3536 KB Output is correct
5 Correct 2 ms 3536 KB Output is correct
6 Correct 2 ms 3536 KB Output is correct
7 Correct 2 ms 3536 KB Output is correct
8 Correct 2 ms 3536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3504 KB Output is correct
2 Correct 2 ms 3536 KB Output is correct
3 Correct 2 ms 3536 KB Output is correct
4 Correct 2 ms 3536 KB Output is correct
5 Correct 2 ms 3536 KB Output is correct
6 Correct 2 ms 3536 KB Output is correct
7 Correct 2 ms 3664 KB Output is correct
8 Correct 2 ms 3664 KB Output is correct
9 Correct 2 ms 3664 KB Output is correct
10 Correct 2 ms 3664 KB Output is correct
11 Correct 2 ms 3664 KB Output is correct
12 Correct 2 ms 3664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 2 ms 3536 KB Output is correct
4 Correct 2 ms 3536 KB Output is correct
5 Correct 2 ms 3536 KB Output is correct
6 Correct 2 ms 3536 KB Output is correct
7 Correct 2 ms 3536 KB Output is correct
8 Correct 2 ms 3536 KB Output is correct
9 Correct 3 ms 3504 KB Output is correct
10 Correct 2 ms 3536 KB Output is correct
11 Correct 2 ms 3536 KB Output is correct
12 Correct 2 ms 3536 KB Output is correct
13 Correct 2 ms 3536 KB Output is correct
14 Correct 2 ms 3536 KB Output is correct
15 Correct 2 ms 3664 KB Output is correct
16 Correct 2 ms 3664 KB Output is correct
17 Correct 2 ms 3664 KB Output is correct
18 Correct 2 ms 3664 KB Output is correct
19 Correct 2 ms 3664 KB Output is correct
20 Correct 2 ms 3664 KB Output is correct
21 Correct 2 ms 3536 KB Output is correct
22 Correct 3 ms 3584 KB Output is correct
23 Correct 3 ms 3536 KB Output is correct
24 Correct 2 ms 3664 KB Output is correct
25 Correct 3 ms 3664 KB Output is correct
26 Correct 2 ms 3664 KB Output is correct
27 Correct 2 ms 3664 KB Output is correct
28 Correct 2 ms 3664 KB Output is correct
29 Correct 2 ms 3536 KB Output is correct
30 Correct 2 ms 3536 KB Output is correct
31 Correct 3 ms 3536 KB Output is correct
32 Correct 2 ms 3664 KB Output is correct
33 Correct 2 ms 3536 KB Output is correct
34 Correct 2 ms 3536 KB Output is correct
35 Correct 2 ms 3536 KB Output is correct
36 Correct 2 ms 3664 KB Output is correct
37 Correct 3 ms 3664 KB Output is correct
38 Correct 2 ms 3664 KB Output is correct
39 Correct 2 ms 3536 KB Output is correct
40 Correct 2 ms 3536 KB Output is correct
41 Correct 2 ms 3536 KB Output is correct
42 Correct 2 ms 3536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 558 ms 9820 KB Output is correct
2 Runtime error 31 ms 18248 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 558 ms 9820 KB Output is correct
2 Runtime error 31 ms 18248 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3504 KB Output is correct
2 Correct 2 ms 3536 KB Output is correct
3 Correct 2 ms 3536 KB Output is correct
4 Correct 2 ms 3536 KB Output is correct
5 Correct 2 ms 3536 KB Output is correct
6 Correct 2 ms 3536 KB Output is correct
7 Correct 2 ms 3664 KB Output is correct
8 Correct 2 ms 3664 KB Output is correct
9 Correct 2 ms 3664 KB Output is correct
10 Correct 2 ms 3664 KB Output is correct
11 Correct 2 ms 3664 KB Output is correct
12 Correct 2 ms 3664 KB Output is correct
13 Correct 558 ms 9820 KB Output is correct
14 Runtime error 31 ms 18248 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 2 ms 3536 KB Output is correct
4 Correct 2 ms 3536 KB Output is correct
5 Correct 2 ms 3536 KB Output is correct
6 Correct 2 ms 3536 KB Output is correct
7 Correct 2 ms 3536 KB Output is correct
8 Correct 2 ms 3536 KB Output is correct
9 Correct 3 ms 3504 KB Output is correct
10 Correct 2 ms 3536 KB Output is correct
11 Correct 2 ms 3536 KB Output is correct
12 Correct 2 ms 3536 KB Output is correct
13 Correct 2 ms 3536 KB Output is correct
14 Correct 2 ms 3536 KB Output is correct
15 Correct 2 ms 3664 KB Output is correct
16 Correct 2 ms 3664 KB Output is correct
17 Correct 2 ms 3664 KB Output is correct
18 Correct 2 ms 3664 KB Output is correct
19 Correct 2 ms 3664 KB Output is correct
20 Correct 2 ms 3664 KB Output is correct
21 Correct 2 ms 3536 KB Output is correct
22 Correct 3 ms 3584 KB Output is correct
23 Correct 3 ms 3536 KB Output is correct
24 Correct 2 ms 3664 KB Output is correct
25 Correct 3 ms 3664 KB Output is correct
26 Correct 2 ms 3664 KB Output is correct
27 Correct 2 ms 3664 KB Output is correct
28 Correct 2 ms 3664 KB Output is correct
29 Correct 2 ms 3536 KB Output is correct
30 Correct 2 ms 3536 KB Output is correct
31 Correct 3 ms 3536 KB Output is correct
32 Correct 2 ms 3664 KB Output is correct
33 Correct 2 ms 3536 KB Output is correct
34 Correct 2 ms 3536 KB Output is correct
35 Correct 2 ms 3536 KB Output is correct
36 Correct 2 ms 3664 KB Output is correct
37 Correct 3 ms 3664 KB Output is correct
38 Correct 2 ms 3664 KB Output is correct
39 Correct 2 ms 3536 KB Output is correct
40 Correct 2 ms 3536 KB Output is correct
41 Correct 2 ms 3536 KB Output is correct
42 Correct 2 ms 3536 KB Output is correct
43 Correct 759 ms 4048 KB Output is correct
44 Correct 1128 ms 4176 KB Output is correct
45 Correct 1273 ms 4048 KB Output is correct
46 Correct 738 ms 4560 KB Output is correct
47 Correct 1634 ms 4560 KB Output is correct
48 Correct 1521 ms 4560 KB Output is correct
49 Correct 1496 ms 4560 KB Output is correct
50 Correct 2775 ms 4560 KB Output is correct
51 Correct 2757 ms 4308 KB Output is correct
52 Correct 1551 ms 4304 KB Output is correct
53 Correct 813 ms 3792 KB Output is correct
54 Correct 1448 ms 4560 KB Output is correct
55 Correct 1362 ms 4432 KB Output is correct
56 Correct 1549 ms 4304 KB Output is correct
57 Correct 1463 ms 4176 KB Output is correct
58 Correct 1563 ms 4560 KB Output is correct
59 Correct 1417 ms 4700 KB Output is correct
60 Correct 2738 ms 4700 KB Output is correct
61 Correct 1207 ms 4048 KB Output is correct
62 Correct 1269 ms 4048 KB Output is correct
63 Correct 1257 ms 4048 KB Output is correct
64 Correct 1523 ms 4176 KB Output is correct
65 Correct 407 ms 3792 KB Output is correct
66 Correct 1408 ms 4244 KB Output is correct
67 Correct 1422 ms 4176 KB Output is correct
68 Correct 2138 ms 4176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 2 ms 3536 KB Output is correct
4 Correct 2 ms 3536 KB Output is correct
5 Correct 2 ms 3536 KB Output is correct
6 Correct 2 ms 3536 KB Output is correct
7 Correct 2 ms 3536 KB Output is correct
8 Correct 2 ms 3536 KB Output is correct
9 Correct 3 ms 3504 KB Output is correct
10 Correct 2 ms 3536 KB Output is correct
11 Correct 2 ms 3536 KB Output is correct
12 Correct 2 ms 3536 KB Output is correct
13 Correct 2 ms 3536 KB Output is correct
14 Correct 2 ms 3536 KB Output is correct
15 Correct 2 ms 3664 KB Output is correct
16 Correct 2 ms 3664 KB Output is correct
17 Correct 2 ms 3664 KB Output is correct
18 Correct 2 ms 3664 KB Output is correct
19 Correct 2 ms 3664 KB Output is correct
20 Correct 2 ms 3664 KB Output is correct
21 Correct 2 ms 3536 KB Output is correct
22 Correct 3 ms 3584 KB Output is correct
23 Correct 3 ms 3536 KB Output is correct
24 Correct 2 ms 3664 KB Output is correct
25 Correct 3 ms 3664 KB Output is correct
26 Correct 2 ms 3664 KB Output is correct
27 Correct 2 ms 3664 KB Output is correct
28 Correct 2 ms 3664 KB Output is correct
29 Correct 2 ms 3536 KB Output is correct
30 Correct 2 ms 3536 KB Output is correct
31 Correct 3 ms 3536 KB Output is correct
32 Correct 2 ms 3664 KB Output is correct
33 Correct 2 ms 3536 KB Output is correct
34 Correct 2 ms 3536 KB Output is correct
35 Correct 2 ms 3536 KB Output is correct
36 Correct 2 ms 3664 KB Output is correct
37 Correct 3 ms 3664 KB Output is correct
38 Correct 2 ms 3664 KB Output is correct
39 Correct 2 ms 3536 KB Output is correct
40 Correct 2 ms 3536 KB Output is correct
41 Correct 2 ms 3536 KB Output is correct
42 Correct 2 ms 3536 KB Output is correct
43 Correct 558 ms 9820 KB Output is correct
44 Runtime error 31 ms 18248 KB Execution killed with signal 11
45 Halted 0 ms 0 KB -