Submission #1024454

# Submission time Handle Problem Language Result Execution time Memory
1024454 2024-07-16T05:25:09 Z vjudge1 Digital Circuit (IOI22_circuit) C++17
18 / 100
3000 ms 12632 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<int, int> pii;

const int MOD = 1000002022;
const int maxn = 2e5 + 100;

int n, k;
int p[maxn];
vector<int> g[maxn];
int a[maxn];
ll dp[2][maxn * 4];
int t[maxn * 4];
ll d[maxn];

void calc(int v){
	fill(d, d + g[v].size() + 1, 0);
	d[0] = 1; dp[1][v] = dp[0][v] = 0;
	for(int to: g[v]){
		for(int cnt = g[v].size(); cnt >= 0; cnt--){
			d[cnt] = d[cnt] * dp[0][to] % MOD;
			if(cnt) d[cnt] = (d[cnt] + d[cnt-1] * dp[1][to]) % MOD;
		}
	}
	for(int cnt = 0; cnt <= g[v].size(); cnt++){
		dp[1][v] = (dp[1][v] + d[cnt] * cnt) % MOD;
		dp[0][v] = (dp[0][v] + d[cnt] * (g[v].size() - cnt)) % MOD;
	}
}

void build(int v = 1, int tl = k + 1, int tr = n){
	if(tl < tr){
		int mid = (tl + tr) >> 1;
		build(v<<1, tl, mid);
		build(v<<1|1, mid+1, tr);
		calc(v);
	}
}

void pre(int v){
	t[v] ^= 1;
	swap(dp[0][v], dp[1][v]);
}

void push(int v, int tl, int tr){
	if(tl == tr || !t[v]) return;
	pre(v<<1); pre(v<<1|1);
}

void upd(int l, int r, int v = 1, int tl = 1 + k, int tr = n){
	push(v, tl, tr);
	if(tl > r || tr < l) return;
	if(l <= tl && tr <= r) pre(v);
	else{
		int mid = (tl + tr) >> 1;
		upd(l, r, v<<1, tl, mid);
		upd(l, r, v<<1|1, mid+1, tr);
		calc(v);
	}
}

void init(int N, int M, std::vector<int> P, std::vector<int> A){
	int n = N + M; k = N;
	for(int i = 1; i <= n; i++){
		p[i] = P[i-1]; p[i]++;
		g[p[i]].push_back(i);
	}
	for(int i = k + 1; i <= n; i++){
		a[i] = A[i - k - 1];
		dp[a[i]][i] = 1;
		dp[a[i]^1][i] = 0;
	}
	if(n > 10000) build();
}

int count_ways(int L, int R){
	if(n <= 10000){
		for(int i = L + 1; i <= R + 1; i++){
			a[i] ^= 1;
			dp[a[i]][i] = 1;
			dp[a[i]^1][i] = 0;
		}
		for(int v = k; v > 0; v--) calc(v);
	} else upd(L + 1, R + 1);
	return dp[1][1];
}

Compilation message

circuit.cpp: In function 'void calc(int)':
circuit.cpp:26:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for(int cnt = 0; cnt <= g[v].size(); cnt++){
      |                   ~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10584 KB Output is correct
3 Correct 17 ms 10584 KB Output is correct
4 Correct 18 ms 10584 KB Output is correct
5 Correct 18 ms 10584 KB Output is correct
6 Correct 18 ms 10584 KB Output is correct
7 Correct 18 ms 10584 KB Output is correct
8 Correct 18 ms 10584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 1 ms 10584 KB Output is correct
3 Correct 2 ms 10584 KB Output is correct
4 Correct 1 ms 10584 KB Output is correct
5 Correct 1 ms 10584 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 10584 KB Output is correct
8 Correct 2 ms 10584 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 10584 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 2 ms 10584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10584 KB Output is correct
3 Correct 17 ms 10584 KB Output is correct
4 Correct 18 ms 10584 KB Output is correct
5 Correct 18 ms 10584 KB Output is correct
6 Correct 18 ms 10584 KB Output is correct
7 Correct 18 ms 10584 KB Output is correct
8 Correct 18 ms 10584 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 1 ms 10584 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 1 ms 10584 KB Output is correct
13 Correct 1 ms 10584 KB Output is correct
14 Correct 2 ms 10584 KB Output is correct
15 Correct 2 ms 10584 KB Output is correct
16 Correct 2 ms 10584 KB Output is correct
17 Correct 2 ms 10584 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 2 ms 10584 KB Output is correct
20 Correct 2 ms 10584 KB Output is correct
21 Correct 2 ms 10584 KB Output is correct
22 Correct 2 ms 10584 KB Output is correct
23 Correct 1 ms 10584 KB Output is correct
24 Correct 2 ms 10584 KB Output is correct
25 Correct 2 ms 10584 KB Output is correct
26 Correct 2 ms 10584 KB Output is correct
27 Correct 2 ms 10584 KB Output is correct
28 Correct 2 ms 10584 KB Output is correct
29 Correct 18 ms 10584 KB Output is correct
30 Correct 21 ms 10584 KB Output is correct
31 Correct 1 ms 10584 KB Output is correct
32 Correct 2 ms 10584 KB Output is correct
33 Correct 2 ms 10584 KB Output is correct
34 Correct 2 ms 10584 KB Output is correct
35 Correct 5 ms 10584 KB Output is correct
36 Correct 2 ms 10584 KB Output is correct
37 Correct 19 ms 10584 KB Output is correct
38 Correct 19 ms 10584 KB Output is correct
39 Correct 2 ms 10584 KB Output is correct
40 Correct 1 ms 10584 KB Output is correct
41 Correct 2 ms 10584 KB Output is correct
42 Correct 3 ms 10584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3080 ms 12632 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3080 ms 12632 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 1 ms 10584 KB Output is correct
3 Correct 2 ms 10584 KB Output is correct
4 Correct 1 ms 10584 KB Output is correct
5 Correct 1 ms 10584 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 10584 KB Output is correct
8 Correct 2 ms 10584 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 10584 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 2 ms 10584 KB Output is correct
13 Execution timed out 3080 ms 12632 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10584 KB Output is correct
3 Correct 17 ms 10584 KB Output is correct
4 Correct 18 ms 10584 KB Output is correct
5 Correct 18 ms 10584 KB Output is correct
6 Correct 18 ms 10584 KB Output is correct
7 Correct 18 ms 10584 KB Output is correct
8 Correct 18 ms 10584 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 1 ms 10584 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 1 ms 10584 KB Output is correct
13 Correct 1 ms 10584 KB Output is correct
14 Correct 2 ms 10584 KB Output is correct
15 Correct 2 ms 10584 KB Output is correct
16 Correct 2 ms 10584 KB Output is correct
17 Correct 2 ms 10584 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 2 ms 10584 KB Output is correct
20 Correct 2 ms 10584 KB Output is correct
21 Correct 2 ms 10584 KB Output is correct
22 Correct 2 ms 10584 KB Output is correct
23 Correct 1 ms 10584 KB Output is correct
24 Correct 2 ms 10584 KB Output is correct
25 Correct 2 ms 10584 KB Output is correct
26 Correct 2 ms 10584 KB Output is correct
27 Correct 2 ms 10584 KB Output is correct
28 Correct 2 ms 10584 KB Output is correct
29 Correct 18 ms 10584 KB Output is correct
30 Correct 21 ms 10584 KB Output is correct
31 Correct 1 ms 10584 KB Output is correct
32 Correct 2 ms 10584 KB Output is correct
33 Correct 2 ms 10584 KB Output is correct
34 Correct 2 ms 10584 KB Output is correct
35 Correct 5 ms 10584 KB Output is correct
36 Correct 2 ms 10584 KB Output is correct
37 Correct 19 ms 10584 KB Output is correct
38 Correct 19 ms 10584 KB Output is correct
39 Correct 2 ms 10584 KB Output is correct
40 Correct 1 ms 10584 KB Output is correct
41 Correct 2 ms 10584 KB Output is correct
42 Correct 3 ms 10584 KB Output is correct
43 Execution timed out 3058 ms 10840 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10584 KB Output is correct
3 Correct 17 ms 10584 KB Output is correct
4 Correct 18 ms 10584 KB Output is correct
5 Correct 18 ms 10584 KB Output is correct
6 Correct 18 ms 10584 KB Output is correct
7 Correct 18 ms 10584 KB Output is correct
8 Correct 18 ms 10584 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 1 ms 10584 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 1 ms 10584 KB Output is correct
13 Correct 1 ms 10584 KB Output is correct
14 Correct 2 ms 10584 KB Output is correct
15 Correct 2 ms 10584 KB Output is correct
16 Correct 2 ms 10584 KB Output is correct
17 Correct 2 ms 10584 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 2 ms 10584 KB Output is correct
20 Correct 2 ms 10584 KB Output is correct
21 Correct 2 ms 10584 KB Output is correct
22 Correct 2 ms 10584 KB Output is correct
23 Correct 1 ms 10584 KB Output is correct
24 Correct 2 ms 10584 KB Output is correct
25 Correct 2 ms 10584 KB Output is correct
26 Correct 2 ms 10584 KB Output is correct
27 Correct 2 ms 10584 KB Output is correct
28 Correct 2 ms 10584 KB Output is correct
29 Correct 18 ms 10584 KB Output is correct
30 Correct 21 ms 10584 KB Output is correct
31 Correct 1 ms 10584 KB Output is correct
32 Correct 2 ms 10584 KB Output is correct
33 Correct 2 ms 10584 KB Output is correct
34 Correct 2 ms 10584 KB Output is correct
35 Correct 5 ms 10584 KB Output is correct
36 Correct 2 ms 10584 KB Output is correct
37 Correct 19 ms 10584 KB Output is correct
38 Correct 19 ms 10584 KB Output is correct
39 Correct 2 ms 10584 KB Output is correct
40 Correct 1 ms 10584 KB Output is correct
41 Correct 2 ms 10584 KB Output is correct
42 Correct 3 ms 10584 KB Output is correct
43 Execution timed out 3080 ms 12632 KB Time limit exceeded
44 Halted 0 ms 0 KB -