Submission #1067086

# Submission time Handle Problem Language Result Execution time Memory
1067086 2024-08-20T11:05:44 Z pavement Digital Circuit (IOI22_circuit) C++17
46 / 100
723 ms 25680 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

using ll = long long;

const int MOD = (int)1e9 + 2022;
int N, M, coeff[100005];
vector<int> A, adj[100005];

struct node {
	node *left, *right;
	int S, E, val;
	node(int _s, int _e) : S(_s), E(_e) {
		if (S == E) {
			val = adj[S].size();
			return;
		}
		int M = (S + E) / 2;
		left = new node(S, M);
		right = new node(M + 1, E);
		val = (ll)left->val * right->val % MOD;
	}
	void upd(int p, int v) {
		if (S == E) {
			val = v;
			return;
		}
		int M = (S + E) / 2;
		if (p <= M) {
			left->upd(p, v);
		} else {
			right->upd(p, v);
		}
		val = (ll)left->val * right->val % MOD;
	}
} *root;

struct node2 {
	node2 *left, *right;
	int S, E, val[2];
	bool ip;
	node2(int _s, int _e) : S(_s), E(_e), ip(0) {
		if (S == E) {
			val[A[S]] = coeff[S];
			val[!A[S]] = 0;
			return;
		}
		int M = (S + E) / 2;
		left = new node2(S, M);
		right = new node2(M + 1, E);
		val[0] = (left->val[0] + right->val[0]) % MOD;
		val[1] = (left->val[1] + right->val[1]) % MOD;
	}
	void prop() {
		if (S == E || !ip) {
			return;
		}
		swap(left->val[0], left->val[1]);
		swap(right->val[0], right->val[1]);
		left->ip ^= 1;
		right->ip ^= 1;
		ip = 0;
	}
	void upd(int l, int r) {
		if (l > E || r < S) {
			return;
		}
		if (l <= S && E <= r) {
			swap(val[0], val[1]);
			ip ^= 1;
			return;
		}
		prop();
		left->upd(l, r);
		right->upd(l, r);
		val[0] = (left->val[0] + right->val[0]) % MOD;
		val[1] = (left->val[1] + right->val[1]) % MOD;
	}
} *root2;

void dfs(int u) {
	if (u < N) {
		root->upd(u, 1);
	} else {
		coeff[u - N] = root->val;
	}
	for (auto v : adj[u]) {
		dfs(v);
	}
	if (u < N) {
		root->upd(u, adj[u].size());
	}
}

void init(int N, int M, vector<int> P, vector<int> A) {
	::N = N;
	::M = M;
	::A = A;
	for (int i = 0; i < N + M; i++) {
		adj[P[i]].pb(i);
	}
	root = new node(0, N - 1);
	dfs(0);
	root2 = new node2(0, M - 1);
}

int count_ways(int L, int R) {
	root2->upd(L - N, R - N);
	return root2->val[1];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2904 KB Output is correct
4 Correct 1 ms 2904 KB Output is correct
5 Correct 1 ms 2904 KB Output is correct
6 Correct 1 ms 2904 KB Output is correct
7 Correct 1 ms 2904 KB Output is correct
8 Correct 1 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2904 KB Output is correct
4 Correct 1 ms 2724 KB Output is correct
5 Correct 1 ms 2904 KB Output is correct
6 Correct 1 ms 2904 KB Output is correct
7 Correct 1 ms 2904 KB Output is correct
8 Correct 1 ms 2904 KB Output is correct
9 Correct 1 ms 2904 KB Output is correct
10 Correct 1 ms 2904 KB Output is correct
11 Correct 1 ms 2904 KB Output is correct
12 Correct 1 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2904 KB Output is correct
4 Correct 1 ms 2904 KB Output is correct
5 Correct 1 ms 2904 KB Output is correct
6 Correct 1 ms 2904 KB Output is correct
7 Correct 1 ms 2904 KB Output is correct
8 Correct 1 ms 2904 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2904 KB Output is correct
12 Correct 1 ms 2724 KB Output is correct
13 Correct 1 ms 2904 KB Output is correct
14 Correct 1 ms 2904 KB Output is correct
15 Correct 1 ms 2904 KB Output is correct
16 Correct 1 ms 2904 KB Output is correct
17 Correct 1 ms 2904 KB Output is correct
18 Correct 1 ms 2904 KB Output is correct
19 Correct 1 ms 2904 KB Output is correct
20 Correct 1 ms 2904 KB Output is correct
21 Correct 1 ms 2904 KB Output is correct
22 Correct 1 ms 2904 KB Output is correct
23 Correct 1 ms 2904 KB Output is correct
24 Correct 1 ms 2904 KB Output is correct
25 Correct 1 ms 2904 KB Output is correct
26 Correct 1 ms 2904 KB Output is correct
27 Correct 2 ms 2904 KB Output is correct
28 Correct 1 ms 2904 KB Output is correct
29 Correct 1 ms 2904 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 1 ms 2904 KB Output is correct
32 Correct 1 ms 2904 KB Output is correct
33 Correct 1 ms 2904 KB Output is correct
34 Correct 1 ms 2904 KB Output is correct
35 Correct 1 ms 2648 KB Output is correct
36 Correct 1 ms 2904 KB Output is correct
37 Correct 1 ms 3016 KB Output is correct
38 Correct 1 ms 2904 KB Output is correct
39 Correct 1 ms 2904 KB Output is correct
40 Correct 1 ms 2904 KB Output is correct
41 Correct 1 ms 2904 KB Output is correct
42 Correct 1 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 501 ms 10840 KB Output is correct
2 Runtime error 42 ms 25680 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 501 ms 10840 KB Output is correct
2 Runtime error 42 ms 25680 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2904 KB Output is correct
4 Correct 1 ms 2724 KB Output is correct
5 Correct 1 ms 2904 KB Output is correct
6 Correct 1 ms 2904 KB Output is correct
7 Correct 1 ms 2904 KB Output is correct
8 Correct 1 ms 2904 KB Output is correct
9 Correct 1 ms 2904 KB Output is correct
10 Correct 1 ms 2904 KB Output is correct
11 Correct 1 ms 2904 KB Output is correct
12 Correct 1 ms 2904 KB Output is correct
13 Correct 501 ms 10840 KB Output is correct
14 Runtime error 42 ms 25680 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2904 KB Output is correct
4 Correct 1 ms 2904 KB Output is correct
5 Correct 1 ms 2904 KB Output is correct
6 Correct 1 ms 2904 KB Output is correct
7 Correct 1 ms 2904 KB Output is correct
8 Correct 1 ms 2904 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2904 KB Output is correct
12 Correct 1 ms 2724 KB Output is correct
13 Correct 1 ms 2904 KB Output is correct
14 Correct 1 ms 2904 KB Output is correct
15 Correct 1 ms 2904 KB Output is correct
16 Correct 1 ms 2904 KB Output is correct
17 Correct 1 ms 2904 KB Output is correct
18 Correct 1 ms 2904 KB Output is correct
19 Correct 1 ms 2904 KB Output is correct
20 Correct 1 ms 2904 KB Output is correct
21 Correct 1 ms 2904 KB Output is correct
22 Correct 1 ms 2904 KB Output is correct
23 Correct 1 ms 2904 KB Output is correct
24 Correct 1 ms 2904 KB Output is correct
25 Correct 1 ms 2904 KB Output is correct
26 Correct 1 ms 2904 KB Output is correct
27 Correct 2 ms 2904 KB Output is correct
28 Correct 1 ms 2904 KB Output is correct
29 Correct 1 ms 2904 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 1 ms 2904 KB Output is correct
32 Correct 1 ms 2904 KB Output is correct
33 Correct 1 ms 2904 KB Output is correct
34 Correct 1 ms 2904 KB Output is correct
35 Correct 1 ms 2648 KB Output is correct
36 Correct 1 ms 2904 KB Output is correct
37 Correct 1 ms 3016 KB Output is correct
38 Correct 1 ms 2904 KB Output is correct
39 Correct 1 ms 2904 KB Output is correct
40 Correct 1 ms 2904 KB Output is correct
41 Correct 1 ms 2904 KB Output is correct
42 Correct 1 ms 2904 KB Output is correct
43 Correct 439 ms 3416 KB Output is correct
44 Correct 625 ms 3416 KB Output is correct
45 Correct 603 ms 3416 KB Output is correct
46 Correct 676 ms 3928 KB Output is correct
47 Correct 698 ms 3928 KB Output is correct
48 Correct 651 ms 3928 KB Output is correct
49 Correct 716 ms 3928 KB Output is correct
50 Correct 723 ms 3928 KB Output is correct
51 Correct 679 ms 3160 KB Output is correct
52 Correct 689 ms 3160 KB Output is correct
53 Correct 609 ms 3672 KB Output is correct
54 Correct 659 ms 3928 KB Output is correct
55 Correct 638 ms 3672 KB Output is correct
56 Correct 656 ms 3416 KB Output is correct
57 Correct 657 ms 3160 KB Output is correct
58 Correct 639 ms 4184 KB Output is correct
59 Correct 638 ms 4440 KB Output is correct
60 Correct 627 ms 4440 KB Output is correct
61 Correct 661 ms 3672 KB Output is correct
62 Correct 681 ms 3416 KB Output is correct
63 Correct 700 ms 3416 KB Output is correct
64 Correct 639 ms 3160 KB Output is correct
65 Correct 284 ms 3160 KB Output is correct
66 Correct 563 ms 3672 KB Output is correct
67 Correct 522 ms 3672 KB Output is correct
68 Correct 622 ms 3672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2904 KB Output is correct
4 Correct 1 ms 2904 KB Output is correct
5 Correct 1 ms 2904 KB Output is correct
6 Correct 1 ms 2904 KB Output is correct
7 Correct 1 ms 2904 KB Output is correct
8 Correct 1 ms 2904 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2904 KB Output is correct
12 Correct 1 ms 2724 KB Output is correct
13 Correct 1 ms 2904 KB Output is correct
14 Correct 1 ms 2904 KB Output is correct
15 Correct 1 ms 2904 KB Output is correct
16 Correct 1 ms 2904 KB Output is correct
17 Correct 1 ms 2904 KB Output is correct
18 Correct 1 ms 2904 KB Output is correct
19 Correct 1 ms 2904 KB Output is correct
20 Correct 1 ms 2904 KB Output is correct
21 Correct 1 ms 2904 KB Output is correct
22 Correct 1 ms 2904 KB Output is correct
23 Correct 1 ms 2904 KB Output is correct
24 Correct 1 ms 2904 KB Output is correct
25 Correct 1 ms 2904 KB Output is correct
26 Correct 1 ms 2904 KB Output is correct
27 Correct 2 ms 2904 KB Output is correct
28 Correct 1 ms 2904 KB Output is correct
29 Correct 1 ms 2904 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 1 ms 2904 KB Output is correct
32 Correct 1 ms 2904 KB Output is correct
33 Correct 1 ms 2904 KB Output is correct
34 Correct 1 ms 2904 KB Output is correct
35 Correct 1 ms 2648 KB Output is correct
36 Correct 1 ms 2904 KB Output is correct
37 Correct 1 ms 3016 KB Output is correct
38 Correct 1 ms 2904 KB Output is correct
39 Correct 1 ms 2904 KB Output is correct
40 Correct 1 ms 2904 KB Output is correct
41 Correct 1 ms 2904 KB Output is correct
42 Correct 1 ms 2904 KB Output is correct
43 Correct 501 ms 10840 KB Output is correct
44 Runtime error 42 ms 25680 KB Execution killed with signal 11
45 Halted 0 ms 0 KB -