답안 #667270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667270 2022-12-01T01:28:18 Z flappybird 디지털 회로 (IOI22_circuit) C++17
100 / 100
1125 ms 48880 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000002022ll
#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;
		if (s != e) 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();
	f(A[x]);
	int c = adj[x].size();
	for (i = 1; i < c; i++) psum[x][i] *= psum[x][i - 1], f(psum[x][i]);
	for (i = c - 2; i >= 0; i--) ssum[x][i] *= ssum[x][i + 1], f(ssum[x][i]);
	for (i = 0; i < c; i++) {
		ll mul = 1;
		if (i > 0) mul *= psum[x][i - 1], f(mul);
		if (i < c - 1) mul *= ssum[x][i + 1], f(mul);
		ma[adj[x][i]] *= mul;
		f(ma[adj[x][i]]);
	}
}

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++) {
      |              ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 7 ms 14416 KB Output is correct
3 Correct 8 ms 14600 KB Output is correct
4 Correct 8 ms 14544 KB Output is correct
5 Correct 9 ms 14516 KB Output is correct
6 Correct 9 ms 14544 KB Output is correct
7 Correct 8 ms 14544 KB Output is correct
8 Correct 8 ms 14544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14432 KB Output is correct
2 Correct 7 ms 14544 KB Output is correct
3 Correct 8 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 14632 KB Output is correct
7 Correct 8 ms 14672 KB Output is correct
8 Correct 10 ms 14672 KB Output is correct
9 Correct 8 ms 14672 KB Output is correct
10 Correct 8 ms 14800 KB Output is correct
11 Correct 8 ms 14696 KB Output is correct
12 Correct 8 ms 14588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 7 ms 14416 KB Output is correct
3 Correct 8 ms 14600 KB Output is correct
4 Correct 8 ms 14544 KB Output is correct
5 Correct 9 ms 14516 KB Output is correct
6 Correct 9 ms 14544 KB Output is correct
7 Correct 8 ms 14544 KB Output is correct
8 Correct 8 ms 14544 KB Output is correct
9 Correct 9 ms 14432 KB Output is correct
10 Correct 7 ms 14544 KB Output is correct
11 Correct 8 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 14632 KB Output is correct
15 Correct 8 ms 14672 KB Output is correct
16 Correct 10 ms 14672 KB Output is correct
17 Correct 8 ms 14672 KB Output is correct
18 Correct 8 ms 14800 KB Output is correct
19 Correct 8 ms 14696 KB Output is correct
20 Correct 8 ms 14588 KB Output is correct
21 Correct 7 ms 14672 KB Output is correct
22 Correct 7 ms 14544 KB Output is correct
23 Correct 7 ms 14580 KB Output is correct
24 Correct 9 ms 14672 KB Output is correct
25 Correct 8 ms 14672 KB Output is correct
26 Correct 9 ms 14672 KB Output is correct
27 Correct 9 ms 14672 KB Output is correct
28 Correct 8 ms 14672 KB Output is correct
29 Correct 8 ms 14544 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 14560 KB Output is correct
34 Correct 8 ms 14560 KB Output is correct
35 Correct 7 ms 14544 KB Output is correct
36 Correct 8 ms 14752 KB Output is correct
37 Correct 7 ms 14824 KB Output is correct
38 Correct 8 ms 14800 KB Output is correct
39 Correct 8 ms 14576 KB Output is correct
40 Correct 7 ms 14544 KB Output is correct
41 Correct 7 ms 14544 KB Output is correct
42 Correct 8 ms 14544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 530 ms 22580 KB Output is correct
2 Correct 949 ms 30660 KB Output is correct
3 Correct 745 ms 30600 KB Output is correct
4 Correct 769 ms 30572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 530 ms 22580 KB Output is correct
2 Correct 949 ms 30660 KB Output is correct
3 Correct 745 ms 30600 KB Output is correct
4 Correct 769 ms 30572 KB Output is correct
5 Correct 684 ms 22532 KB Output is correct
6 Correct 1093 ms 30596 KB Output is correct
7 Correct 1040 ms 30592 KB Output is correct
8 Correct 842 ms 30588 KB Output is correct
9 Correct 460 ms 14976 KB Output is correct
10 Correct 930 ms 15504 KB Output is correct
11 Correct 982 ms 15504 KB Output is correct
12 Correct 768 ms 15504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14432 KB Output is correct
2 Correct 7 ms 14544 KB Output is correct
3 Correct 8 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 14632 KB Output is correct
7 Correct 8 ms 14672 KB Output is correct
8 Correct 10 ms 14672 KB Output is correct
9 Correct 8 ms 14672 KB Output is correct
10 Correct 8 ms 14800 KB Output is correct
11 Correct 8 ms 14696 KB Output is correct
12 Correct 8 ms 14588 KB Output is correct
13 Correct 530 ms 22580 KB Output is correct
14 Correct 949 ms 30660 KB Output is correct
15 Correct 745 ms 30600 KB Output is correct
16 Correct 769 ms 30572 KB Output is correct
17 Correct 684 ms 22532 KB Output is correct
18 Correct 1093 ms 30596 KB Output is correct
19 Correct 1040 ms 30592 KB Output is correct
20 Correct 842 ms 30588 KB Output is correct
21 Correct 460 ms 14976 KB Output is correct
22 Correct 930 ms 15504 KB Output is correct
23 Correct 982 ms 15504 KB Output is correct
24 Correct 768 ms 15504 KB Output is correct
25 Correct 1117 ms 38568 KB Output is correct
26 Correct 974 ms 39016 KB Output is correct
27 Correct 1088 ms 39120 KB Output is correct
28 Correct 888 ms 39072 KB Output is correct
29 Correct 1042 ms 46852 KB Output is correct
30 Correct 847 ms 46912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 7 ms 14416 KB Output is correct
3 Correct 8 ms 14600 KB Output is correct
4 Correct 8 ms 14544 KB Output is correct
5 Correct 9 ms 14516 KB Output is correct
6 Correct 9 ms 14544 KB Output is correct
7 Correct 8 ms 14544 KB Output is correct
8 Correct 8 ms 14544 KB Output is correct
9 Correct 9 ms 14432 KB Output is correct
10 Correct 7 ms 14544 KB Output is correct
11 Correct 8 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 14632 KB Output is correct
15 Correct 8 ms 14672 KB Output is correct
16 Correct 10 ms 14672 KB Output is correct
17 Correct 8 ms 14672 KB Output is correct
18 Correct 8 ms 14800 KB Output is correct
19 Correct 8 ms 14696 KB Output is correct
20 Correct 8 ms 14588 KB Output is correct
21 Correct 7 ms 14672 KB Output is correct
22 Correct 7 ms 14544 KB Output is correct
23 Correct 7 ms 14580 KB Output is correct
24 Correct 9 ms 14672 KB Output is correct
25 Correct 8 ms 14672 KB Output is correct
26 Correct 9 ms 14672 KB Output is correct
27 Correct 9 ms 14672 KB Output is correct
28 Correct 8 ms 14672 KB Output is correct
29 Correct 8 ms 14544 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 14560 KB Output is correct
34 Correct 8 ms 14560 KB Output is correct
35 Correct 7 ms 14544 KB Output is correct
36 Correct 8 ms 14752 KB Output is correct
37 Correct 7 ms 14824 KB Output is correct
38 Correct 8 ms 14800 KB Output is correct
39 Correct 8 ms 14576 KB Output is correct
40 Correct 7 ms 14544 KB Output is correct
41 Correct 7 ms 14544 KB Output is correct
42 Correct 8 ms 14544 KB Output is correct
43 Correct 701 ms 15192 KB Output is correct
44 Correct 967 ms 15284 KB Output is correct
45 Correct 957 ms 15248 KB Output is correct
46 Correct 888 ms 15772 KB Output is correct
47 Correct 679 ms 15764 KB Output is correct
48 Correct 723 ms 15772 KB Output is correct
49 Correct 937 ms 15772 KB Output is correct
50 Correct 960 ms 15824 KB Output is correct
51 Correct 919 ms 15248 KB Output is correct
52 Correct 985 ms 15368 KB Output is correct
53 Correct 613 ms 15440 KB Output is correct
54 Correct 974 ms 15736 KB Output is correct
55 Correct 914 ms 15440 KB Output is correct
56 Correct 935 ms 15340 KB Output is correct
57 Correct 914 ms 15220 KB Output is correct
58 Correct 893 ms 16128 KB Output is correct
59 Correct 738 ms 16232 KB Output is correct
60 Correct 821 ms 16228 KB Output is correct
61 Correct 916 ms 15352 KB Output is correct
62 Correct 820 ms 15184 KB Output is correct
63 Correct 792 ms 15148 KB Output is correct
64 Correct 854 ms 15236 KB Output is correct
65 Correct 444 ms 14980 KB Output is correct
66 Correct 762 ms 15508 KB Output is correct
67 Correct 757 ms 15504 KB Output is correct
68 Correct 759 ms 15504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 7 ms 14416 KB Output is correct
3 Correct 8 ms 14600 KB Output is correct
4 Correct 8 ms 14544 KB Output is correct
5 Correct 9 ms 14516 KB Output is correct
6 Correct 9 ms 14544 KB Output is correct
7 Correct 8 ms 14544 KB Output is correct
8 Correct 8 ms 14544 KB Output is correct
9 Correct 9 ms 14432 KB Output is correct
10 Correct 7 ms 14544 KB Output is correct
11 Correct 8 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 14632 KB Output is correct
15 Correct 8 ms 14672 KB Output is correct
16 Correct 10 ms 14672 KB Output is correct
17 Correct 8 ms 14672 KB Output is correct
18 Correct 8 ms 14800 KB Output is correct
19 Correct 8 ms 14696 KB Output is correct
20 Correct 8 ms 14588 KB Output is correct
21 Correct 7 ms 14672 KB Output is correct
22 Correct 7 ms 14544 KB Output is correct
23 Correct 7 ms 14580 KB Output is correct
24 Correct 9 ms 14672 KB Output is correct
25 Correct 8 ms 14672 KB Output is correct
26 Correct 9 ms 14672 KB Output is correct
27 Correct 9 ms 14672 KB Output is correct
28 Correct 8 ms 14672 KB Output is correct
29 Correct 8 ms 14544 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 14560 KB Output is correct
34 Correct 8 ms 14560 KB Output is correct
35 Correct 7 ms 14544 KB Output is correct
36 Correct 8 ms 14752 KB Output is correct
37 Correct 7 ms 14824 KB Output is correct
38 Correct 8 ms 14800 KB Output is correct
39 Correct 8 ms 14576 KB Output is correct
40 Correct 7 ms 14544 KB Output is correct
41 Correct 7 ms 14544 KB Output is correct
42 Correct 8 ms 14544 KB Output is correct
43 Correct 530 ms 22580 KB Output is correct
44 Correct 949 ms 30660 KB Output is correct
45 Correct 745 ms 30600 KB Output is correct
46 Correct 769 ms 30572 KB Output is correct
47 Correct 684 ms 22532 KB Output is correct
48 Correct 1093 ms 30596 KB Output is correct
49 Correct 1040 ms 30592 KB Output is correct
50 Correct 842 ms 30588 KB Output is correct
51 Correct 460 ms 14976 KB Output is correct
52 Correct 930 ms 15504 KB Output is correct
53 Correct 982 ms 15504 KB Output is correct
54 Correct 768 ms 15504 KB Output is correct
55 Correct 1117 ms 38568 KB Output is correct
56 Correct 974 ms 39016 KB Output is correct
57 Correct 1088 ms 39120 KB Output is correct
58 Correct 888 ms 39072 KB Output is correct
59 Correct 1042 ms 46852 KB Output is correct
60 Correct 847 ms 46912 KB Output is correct
61 Correct 701 ms 15192 KB Output is correct
62 Correct 967 ms 15284 KB Output is correct
63 Correct 957 ms 15248 KB Output is correct
64 Correct 888 ms 15772 KB Output is correct
65 Correct 679 ms 15764 KB Output is correct
66 Correct 723 ms 15772 KB Output is correct
67 Correct 937 ms 15772 KB Output is correct
68 Correct 960 ms 15824 KB Output is correct
69 Correct 919 ms 15248 KB Output is correct
70 Correct 985 ms 15368 KB Output is correct
71 Correct 613 ms 15440 KB Output is correct
72 Correct 974 ms 15736 KB Output is correct
73 Correct 914 ms 15440 KB Output is correct
74 Correct 935 ms 15340 KB Output is correct
75 Correct 914 ms 15220 KB Output is correct
76 Correct 893 ms 16128 KB Output is correct
77 Correct 738 ms 16232 KB Output is correct
78 Correct 821 ms 16228 KB Output is correct
79 Correct 916 ms 15352 KB Output is correct
80 Correct 820 ms 15184 KB Output is correct
81 Correct 792 ms 15148 KB Output is correct
82 Correct 854 ms 15236 KB Output is correct
83 Correct 444 ms 14980 KB Output is correct
84 Correct 762 ms 15508 KB Output is correct
85 Correct 757 ms 15504 KB Output is correct
86 Correct 759 ms 15504 KB Output is correct
87 Correct 7 ms 14416 KB Output is correct
88 Correct 594 ms 36524 KB Output is correct
89 Correct 904 ms 30112 KB Output is correct
90 Correct 950 ms 29768 KB Output is correct
91 Correct 740 ms 39884 KB Output is correct
92 Correct 976 ms 39740 KB Output is correct
93 Correct 980 ms 39688 KB Output is correct
94 Correct 1060 ms 39660 KB Output is correct
95 Correct 1125 ms 39744 KB Output is correct
96 Correct 907 ms 29044 KB Output is correct
97 Correct 863 ms 29028 KB Output is correct
98 Correct 864 ms 34376 KB Output is correct
99 Correct 961 ms 39140 KB Output is correct
100 Correct 1043 ms 32988 KB Output is correct
101 Correct 904 ms 31208 KB Output is correct
102 Correct 943 ms 29064 KB Output is correct
103 Correct 921 ms 46844 KB Output is correct
104 Correct 901 ms 48880 KB Output is correct
105 Correct 862 ms 48828 KB Output is correct
106 Correct 1040 ms 30744 KB Output is correct
107 Correct 795 ms 27948 KB Output is correct
108 Correct 893 ms 28368 KB Output is correct
109 Correct 1072 ms 29052 KB Output is correct