Submission #667267

# Submission time Handle Problem Language Result Execution time Memory
667267 2022-12-01T01:19:40 Z flappybird Digital Circuit (IOI22_circuit) C++17
34 / 100
1032 ms 75976 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000002022
#define MAX 201010

int N, M;
vector<int> adj[MAX], prt;
vector<ll> psum[MAX], ssum[MAX];
ll A[MAX];
ll ma[MAX];
ll mulall[MAX];
vector<int> ison;

ll f(ll& a) { a %= MOD, a += MOD, a %= MOD; return a; }

struct segtree {
	vector<ll> tree, sum;
	vector<int> lazy;
	void init(int s, int e, int ind) {
		if (s == e) {
			sum[ind] = mulall[s];
			if (ison[s]) tree[ind] = mulall[s];
			return;
		}
		int m = (s + e) >> 1;
		init(s, m, ind * 2);
		init(m + 1, e, ind * 2 + 1);
		sum[ind] = sum[ind * 2] + sum[ind * 2 + 1];
		f(sum[ind]);
		tree[ind] = tree[ind * 2] + tree[ind * 2 + 1];
		f(tree[ind]);
	}
	segtree(int N = 0) {
		tree.resize(N * 4);
		lazy.resize(N * 4);
		sum.resize(N * 4);
	}
	void prop(int ind) {
		if (lazy[ind]) {
			for (auto c : { ind * 2, ind * 2 + 1 }) tree[c] = sum[c] - tree[c], f(tree[c]), lazy[c] ^= 1;
			lazy[ind] = 0;
		}
	}
	void upd(int s, int e, int l, int r, int ind = 1) {
		if (e < l || r < s) return;
		prop(ind);
		if (l <= s && e <= r) {
			tree[ind] = sum[ind] - tree[ind];
			f(tree[ind]);
			lazy[ind] ^= 1;
			return;
		}
		int m = (s + e) >> 1;
		upd(s, m, l, r, ind * 2);
		upd(m + 1, e, l, r, ind * 2 + 1);
		tree[ind] = tree[ind * 2] + tree[ind * 2 + 1];
		f(tree[ind]);
	}
	ll get() { return tree[1]; }
};

void dfs(int x) {
	A[x] = 1;
	ma[x] = 1;
	if (x >= N) {
		return;
	}
	psum[x].resize(adj[x].size());
	ssum[x].resize(adj[x].size());
	int i;
	for (i = 0; i < adj[x].size(); i++) {
		int v = adj[x][i];
		dfs(v);
		psum[x][i] = ssum[x][i] = A[v];
		A[x] *= A[v];
		A[x] %= MOD;
	}
	A[x] *= adj[x].size();
	A[x] %= MOD;
	int c = adj[x].size();
	for (i = 1; i < c; i++) psum[x][i] *= psum[x][i - 1], psum[x][i] %= MOD;
	for (i = c - 2; i >= 0; i--) ssum[x][i] *= ssum[x][i + 1], ssum[x][i] %= MOD;
	for (i = 0; i < c; i++) {
		ll mul = 1;
		if (i > 0) mul *= psum[x][i - 1];
		if (i < c - 1) mul *= ssum[x][i + 1], mul %= MOD;
		ma[adj[x][i]] *= mul;
		ma[adj[x][i]] %= MOD;
	}
}

void calc(int x, ll d) {
	d *= ma[x];
	d %= MOD;
	if (x >= N) mulall[x - N + 1] = d;
	for (auto v : adj[x]) calc(v, d);
}

segtree seg;

void init(int _N, int _M, std::vector<int> _P, std::vector<int> A) {
	prt = _P;
	N = _N;
	M = _M;
	for (int i = 1; i < N + M; i++) adj[prt[i]].push_back(i);
	dfs(0);
	calc(0, 1);
	ison = A;
	ison.insert(ison.begin(), 0);
	seg = segtree(M);
	seg.init(1, M, 1);
}

int count_ways(int L, int R) {
	L -= N - 1;
	R -= N - 1;
	seg.upd(1, M, L, R);
	return seg.get();
}

Compilation message

circuit.cpp: In function 'void dfs(int)':
circuit.cpp:73:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |  for (i = 0; i < adj[x].size(); i++) {
      |              ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 7 ms 14416 KB Output is correct
3 Correct 7 ms 14544 KB Output is correct
4 Correct 7 ms 14544 KB Output is correct
5 Correct 8 ms 14552 KB Output is correct
6 Correct 9 ms 14596 KB Output is correct
7 Correct 8 ms 14544 KB Output is correct
8 Correct 8 ms 14544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 9 ms 14416 KB Output is correct
3 Correct 7 ms 14544 KB Output is correct
4 Correct 7 ms 14544 KB Output is correct
5 Correct 8 ms 14544 KB Output is correct
6 Correct 8 ms 14552 KB Output is correct
7 Correct 8 ms 14684 KB Output is correct
8 Correct 8 ms 14672 KB Output is correct
9 Correct 8 ms 14672 KB Output is correct
10 Correct 8 ms 14756 KB Output is correct
11 Correct 8 ms 14800 KB Output is correct
12 Correct 8 ms 14672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 7 ms 14416 KB Output is correct
3 Correct 7 ms 14544 KB Output is correct
4 Correct 7 ms 14544 KB Output is correct
5 Correct 8 ms 14552 KB Output is correct
6 Correct 9 ms 14596 KB Output is correct
7 Correct 8 ms 14544 KB Output is correct
8 Correct 8 ms 14544 KB Output is correct
9 Correct 7 ms 14416 KB Output is correct
10 Correct 9 ms 14416 KB Output is correct
11 Correct 7 ms 14544 KB Output is correct
12 Correct 7 ms 14544 KB Output is correct
13 Correct 8 ms 14544 KB Output is correct
14 Correct 8 ms 14552 KB Output is correct
15 Correct 8 ms 14684 KB Output is correct
16 Correct 8 ms 14672 KB Output is correct
17 Correct 8 ms 14672 KB Output is correct
18 Correct 8 ms 14756 KB Output is correct
19 Correct 8 ms 14800 KB Output is correct
20 Correct 8 ms 14672 KB Output is correct
21 Correct 10 ms 14672 KB Output is correct
22 Correct 7 ms 14544 KB Output is correct
23 Correct 7 ms 14544 KB Output is correct
24 Correct 8 ms 14672 KB Output is correct
25 Correct 8 ms 14672 KB Output is correct
26 Correct 8 ms 14672 KB Output is correct
27 Correct 8 ms 14672 KB Output is correct
28 Correct 8 ms 14672 KB Output is correct
29 Correct 8 ms 14512 KB Output is correct
30 Correct 8 ms 14544 KB Output is correct
31 Correct 8 ms 14672 KB Output is correct
32 Correct 8 ms 14672 KB Output is correct
33 Correct 8 ms 14544 KB Output is correct
34 Correct 7 ms 14544 KB Output is correct
35 Correct 8 ms 14544 KB Output is correct
36 Correct 8 ms 14800 KB Output is correct
37 Correct 8 ms 14800 KB Output is correct
38 Correct 8 ms 14800 KB Output is correct
39 Correct 8 ms 14512 KB Output is correct
40 Correct 8 ms 14544 KB Output is correct
41 Correct 8 ms 14544 KB Output is correct
42 Correct 7 ms 14544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 677 ms 22468 KB Output is correct
2 Correct 752 ms 30532 KB Output is correct
3 Correct 986 ms 30564 KB Output is correct
4 Correct 1032 ms 30592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 677 ms 22468 KB Output is correct
2 Correct 752 ms 30532 KB Output is correct
3 Correct 986 ms 30564 KB Output is correct
4 Correct 1032 ms 30592 KB Output is correct
5 Correct 857 ms 22512 KB Output is correct
6 Correct 843 ms 30628 KB Output is correct
7 Correct 978 ms 30720 KB Output is correct
8 Correct 996 ms 30600 KB Output is correct
9 Correct 473 ms 14928 KB Output is correct
10 Correct 743 ms 15512 KB Output is correct
11 Correct 932 ms 15496 KB Output is correct
12 Correct 941 ms 15504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 9 ms 14416 KB Output is correct
3 Correct 7 ms 14544 KB Output is correct
4 Correct 7 ms 14544 KB Output is correct
5 Correct 8 ms 14544 KB Output is correct
6 Correct 8 ms 14552 KB Output is correct
7 Correct 8 ms 14684 KB Output is correct
8 Correct 8 ms 14672 KB Output is correct
9 Correct 8 ms 14672 KB Output is correct
10 Correct 8 ms 14756 KB Output is correct
11 Correct 8 ms 14800 KB Output is correct
12 Correct 8 ms 14672 KB Output is correct
13 Correct 677 ms 22468 KB Output is correct
14 Correct 752 ms 30532 KB Output is correct
15 Correct 986 ms 30564 KB Output is correct
16 Correct 1032 ms 30592 KB Output is correct
17 Correct 857 ms 22512 KB Output is correct
18 Correct 843 ms 30628 KB Output is correct
19 Correct 978 ms 30720 KB Output is correct
20 Correct 996 ms 30600 KB Output is correct
21 Correct 473 ms 14928 KB Output is correct
22 Correct 743 ms 15512 KB Output is correct
23 Correct 932 ms 15496 KB Output is correct
24 Correct 941 ms 15504 KB Output is correct
25 Runtime error 145 ms 75976 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 7 ms 14416 KB Output is correct
3 Correct 7 ms 14544 KB Output is correct
4 Correct 7 ms 14544 KB Output is correct
5 Correct 8 ms 14552 KB Output is correct
6 Correct 9 ms 14596 KB Output is correct
7 Correct 8 ms 14544 KB Output is correct
8 Correct 8 ms 14544 KB Output is correct
9 Correct 7 ms 14416 KB Output is correct
10 Correct 9 ms 14416 KB Output is correct
11 Correct 7 ms 14544 KB Output is correct
12 Correct 7 ms 14544 KB Output is correct
13 Correct 8 ms 14544 KB Output is correct
14 Correct 8 ms 14552 KB Output is correct
15 Correct 8 ms 14684 KB Output is correct
16 Correct 8 ms 14672 KB Output is correct
17 Correct 8 ms 14672 KB Output is correct
18 Correct 8 ms 14756 KB Output is correct
19 Correct 8 ms 14800 KB Output is correct
20 Correct 8 ms 14672 KB Output is correct
21 Correct 10 ms 14672 KB Output is correct
22 Correct 7 ms 14544 KB Output is correct
23 Correct 7 ms 14544 KB Output is correct
24 Correct 8 ms 14672 KB Output is correct
25 Correct 8 ms 14672 KB Output is correct
26 Correct 8 ms 14672 KB Output is correct
27 Correct 8 ms 14672 KB Output is correct
28 Correct 8 ms 14672 KB Output is correct
29 Correct 8 ms 14512 KB Output is correct
30 Correct 8 ms 14544 KB Output is correct
31 Correct 8 ms 14672 KB Output is correct
32 Correct 8 ms 14672 KB Output is correct
33 Correct 8 ms 14544 KB Output is correct
34 Correct 7 ms 14544 KB Output is correct
35 Correct 8 ms 14544 KB Output is correct
36 Correct 8 ms 14800 KB Output is correct
37 Correct 8 ms 14800 KB Output is correct
38 Correct 8 ms 14800 KB Output is correct
39 Correct 8 ms 14512 KB Output is correct
40 Correct 8 ms 14544 KB Output is correct
41 Correct 8 ms 14544 KB Output is correct
42 Correct 7 ms 14544 KB Output is correct
43 Runtime error 24 ms 30648 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 7 ms 14416 KB Output is correct
3 Correct 7 ms 14544 KB Output is correct
4 Correct 7 ms 14544 KB Output is correct
5 Correct 8 ms 14552 KB Output is correct
6 Correct 9 ms 14596 KB Output is correct
7 Correct 8 ms 14544 KB Output is correct
8 Correct 8 ms 14544 KB Output is correct
9 Correct 7 ms 14416 KB Output is correct
10 Correct 9 ms 14416 KB Output is correct
11 Correct 7 ms 14544 KB Output is correct
12 Correct 7 ms 14544 KB Output is correct
13 Correct 8 ms 14544 KB Output is correct
14 Correct 8 ms 14552 KB Output is correct
15 Correct 8 ms 14684 KB Output is correct
16 Correct 8 ms 14672 KB Output is correct
17 Correct 8 ms 14672 KB Output is correct
18 Correct 8 ms 14756 KB Output is correct
19 Correct 8 ms 14800 KB Output is correct
20 Correct 8 ms 14672 KB Output is correct
21 Correct 10 ms 14672 KB Output is correct
22 Correct 7 ms 14544 KB Output is correct
23 Correct 7 ms 14544 KB Output is correct
24 Correct 8 ms 14672 KB Output is correct
25 Correct 8 ms 14672 KB Output is correct
26 Correct 8 ms 14672 KB Output is correct
27 Correct 8 ms 14672 KB Output is correct
28 Correct 8 ms 14672 KB Output is correct
29 Correct 8 ms 14512 KB Output is correct
30 Correct 8 ms 14544 KB Output is correct
31 Correct 8 ms 14672 KB Output is correct
32 Correct 8 ms 14672 KB Output is correct
33 Correct 8 ms 14544 KB Output is correct
34 Correct 7 ms 14544 KB Output is correct
35 Correct 8 ms 14544 KB Output is correct
36 Correct 8 ms 14800 KB Output is correct
37 Correct 8 ms 14800 KB Output is correct
38 Correct 8 ms 14800 KB Output is correct
39 Correct 8 ms 14512 KB Output is correct
40 Correct 8 ms 14544 KB Output is correct
41 Correct 8 ms 14544 KB Output is correct
42 Correct 7 ms 14544 KB Output is correct
43 Correct 677 ms 22468 KB Output is correct
44 Correct 752 ms 30532 KB Output is correct
45 Correct 986 ms 30564 KB Output is correct
46 Correct 1032 ms 30592 KB Output is correct
47 Correct 857 ms 22512 KB Output is correct
48 Correct 843 ms 30628 KB Output is correct
49 Correct 978 ms 30720 KB Output is correct
50 Correct 996 ms 30600 KB Output is correct
51 Correct 473 ms 14928 KB Output is correct
52 Correct 743 ms 15512 KB Output is correct
53 Correct 932 ms 15496 KB Output is correct
54 Correct 941 ms 15504 KB Output is correct
55 Runtime error 145 ms 75976 KB Execution killed with signal 11
56 Halted 0 ms 0 KB -