답안 #1060281

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1060281 2024-08-15T12:37:47 Z DorostWef 디지털 회로 (IOI22_circuit) C++17
46 / 100
3000 ms 16464 KB
#include "circuit.h"

#include <bits/stdc++.h>

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target ("avx2")

using namespace std;
#define int long long
const int N = 200023, M = 1000002022;
int a[N], p[N];
int ans[N];
int st[N];
vector <int> g[N];
int pre[N], suf[N];
int x[N];

void predfs (int v) {
	int sz = (int)g[v].size();
	if (sz == 0) {
		st[v] = 1;
		return;
	}
	st[v] = sz;
	for (int u : g[v]) {
		predfs (u);
		st[v] = (st[v] * st[u]) % M;
	}
}

void dfs (int v) {
	int sz = (int)g[v].size();
	if (sz == 0) {
		return;
	}
	pre[0] = 1;
	suf[sz] = 1;
	for (int i = 0; i < sz; i++) {
		int u = g[v][i];
		pre[i + 1] = (pre[i] * st[u]) % M;
	}
	for (int i = sz - 1; i >= 0; i--) {
		int u = g[v][i];
		suf[i] = (suf[i + 1] * st[u]) % M;
	}
	for (int i = 0; i < sz; i++) {
		int u = g[v][i];
		ans[u] = (ans[v] * ((pre[i] * suf[i + 1]) % M) % M);
	}
	for (int i = 0; i < sz; i++) {
		int u = g[v][i];
		dfs (u);
	}
}

int m, n;

void init(int32_t N, int32_t M, std::vector<int32_t> P, std::vector<int32_t> A) {
	n = N;
	for (int i = 0; i < N + M; i++) {
		g[P[i]].push_back(i);
	}
	m = M;
	for (int i = 0; i < M; i++)
		a[i] = A[i];
	predfs (0);
	ans[0] = 1;
	dfs (0);
	for (int i = 0; i < M; i++)
		p[i] = ans[i + N];
}

int32_t count_ways(int32_t L, int32_t R) {
	L -= n;
	R -= n;
	for (int i = L; i <= R; i++) {
		a[i] = 1 - a[i];
	}
	int sum = 0;
	for (int i = 0; i < m; i++) {
		sum += a[i] * p[i];
		sum %= M;
	}
	return (int32_t)sum;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14680 KB Output is correct
3 Correct 2 ms 14772 KB Output is correct
4 Correct 3 ms 14680 KB Output is correct
5 Correct 2 ms 14680 KB Output is correct
6 Correct 2 ms 14680 KB Output is correct
7 Correct 2 ms 14680 KB Output is correct
8 Correct 2 ms 14680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14680 KB Output is correct
3 Correct 2 ms 14680 KB Output is correct
4 Correct 2 ms 14680 KB Output is correct
5 Correct 2 ms 14680 KB Output is correct
6 Correct 2 ms 14680 KB Output is correct
7 Correct 2 ms 14856 KB Output is correct
8 Correct 2 ms 14680 KB Output is correct
9 Correct 2 ms 14680 KB Output is correct
10 Correct 2 ms 14680 KB Output is correct
11 Correct 2 ms 14680 KB Output is correct
12 Correct 2 ms 14680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14680 KB Output is correct
3 Correct 2 ms 14772 KB Output is correct
4 Correct 3 ms 14680 KB Output is correct
5 Correct 2 ms 14680 KB Output is correct
6 Correct 2 ms 14680 KB Output is correct
7 Correct 2 ms 14680 KB Output is correct
8 Correct 2 ms 14680 KB Output is correct
9 Correct 2 ms 14680 KB Output is correct
10 Correct 2 ms 14680 KB Output is correct
11 Correct 2 ms 14680 KB Output is correct
12 Correct 2 ms 14680 KB Output is correct
13 Correct 2 ms 14680 KB Output is correct
14 Correct 2 ms 14680 KB Output is correct
15 Correct 2 ms 14856 KB Output is correct
16 Correct 2 ms 14680 KB Output is correct
17 Correct 2 ms 14680 KB Output is correct
18 Correct 2 ms 14680 KB Output is correct
19 Correct 2 ms 14680 KB Output is correct
20 Correct 2 ms 14680 KB Output is correct
21 Correct 2 ms 14680 KB Output is correct
22 Correct 2 ms 14680 KB Output is correct
23 Correct 2 ms 14680 KB Output is correct
24 Correct 2 ms 14680 KB Output is correct
25 Correct 2 ms 14680 KB Output is correct
26 Correct 2 ms 14680 KB Output is correct
27 Correct 2 ms 14680 KB Output is correct
28 Correct 2 ms 14680 KB Output is correct
29 Correct 2 ms 14680 KB Output is correct
30 Correct 2 ms 14680 KB Output is correct
31 Correct 2 ms 14680 KB Output is correct
32 Correct 2 ms 14680 KB Output is correct
33 Correct 2 ms 14772 KB Output is correct
34 Correct 2 ms 14680 KB Output is correct
35 Correct 2 ms 14680 KB Output is correct
36 Correct 2 ms 14680 KB Output is correct
37 Correct 2 ms 14936 KB Output is correct
38 Correct 2 ms 14680 KB Output is correct
39 Correct 2 ms 14680 KB Output is correct
40 Correct 2 ms 14680 KB Output is correct
41 Correct 2 ms 14680 KB Output is correct
42 Correct 2 ms 14680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3056 ms 16464 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3056 ms 16464 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14680 KB Output is correct
3 Correct 2 ms 14680 KB Output is correct
4 Correct 2 ms 14680 KB Output is correct
5 Correct 2 ms 14680 KB Output is correct
6 Correct 2 ms 14680 KB Output is correct
7 Correct 2 ms 14856 KB Output is correct
8 Correct 2 ms 14680 KB Output is correct
9 Correct 2 ms 14680 KB Output is correct
10 Correct 2 ms 14680 KB Output is correct
11 Correct 2 ms 14680 KB Output is correct
12 Correct 2 ms 14680 KB Output is correct
13 Execution timed out 3056 ms 16464 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14680 KB Output is correct
3 Correct 2 ms 14772 KB Output is correct
4 Correct 3 ms 14680 KB Output is correct
5 Correct 2 ms 14680 KB Output is correct
6 Correct 2 ms 14680 KB Output is correct
7 Correct 2 ms 14680 KB Output is correct
8 Correct 2 ms 14680 KB Output is correct
9 Correct 2 ms 14680 KB Output is correct
10 Correct 2 ms 14680 KB Output is correct
11 Correct 2 ms 14680 KB Output is correct
12 Correct 2 ms 14680 KB Output is correct
13 Correct 2 ms 14680 KB Output is correct
14 Correct 2 ms 14680 KB Output is correct
15 Correct 2 ms 14856 KB Output is correct
16 Correct 2 ms 14680 KB Output is correct
17 Correct 2 ms 14680 KB Output is correct
18 Correct 2 ms 14680 KB Output is correct
19 Correct 2 ms 14680 KB Output is correct
20 Correct 2 ms 14680 KB Output is correct
21 Correct 2 ms 14680 KB Output is correct
22 Correct 2 ms 14680 KB Output is correct
23 Correct 2 ms 14680 KB Output is correct
24 Correct 2 ms 14680 KB Output is correct
25 Correct 2 ms 14680 KB Output is correct
26 Correct 2 ms 14680 KB Output is correct
27 Correct 2 ms 14680 KB Output is correct
28 Correct 2 ms 14680 KB Output is correct
29 Correct 2 ms 14680 KB Output is correct
30 Correct 2 ms 14680 KB Output is correct
31 Correct 2 ms 14680 KB Output is correct
32 Correct 2 ms 14680 KB Output is correct
33 Correct 2 ms 14772 KB Output is correct
34 Correct 2 ms 14680 KB Output is correct
35 Correct 2 ms 14680 KB Output is correct
36 Correct 2 ms 14680 KB Output is correct
37 Correct 2 ms 14936 KB Output is correct
38 Correct 2 ms 14680 KB Output is correct
39 Correct 2 ms 14680 KB Output is correct
40 Correct 2 ms 14680 KB Output is correct
41 Correct 2 ms 14680 KB Output is correct
42 Correct 2 ms 14680 KB Output is correct
43 Correct 1186 ms 14936 KB Output is correct
44 Correct 1550 ms 14936 KB Output is correct
45 Correct 1672 ms 14936 KB Output is correct
46 Correct 2447 ms 14936 KB Output is correct
47 Correct 2459 ms 14936 KB Output is correct
48 Correct 2477 ms 14936 KB Output is correct
49 Correct 2485 ms 15188 KB Output is correct
50 Correct 2582 ms 14936 KB Output is correct
51 Correct 2561 ms 14960 KB Output is correct
52 Correct 2441 ms 14960 KB Output is correct
53 Correct 648 ms 15192 KB Output is correct
54 Correct 2471 ms 14936 KB Output is correct
55 Correct 2421 ms 14936 KB Output is correct
56 Correct 2460 ms 14936 KB Output is correct
57 Correct 2404 ms 14936 KB Output is correct
58 Correct 2452 ms 15192 KB Output is correct
59 Correct 2466 ms 15464 KB Output is correct
60 Correct 2552 ms 15472 KB Output is correct
61 Correct 1472 ms 14936 KB Output is correct
62 Correct 1829 ms 14936 KB Output is correct
63 Correct 1960 ms 14936 KB Output is correct
64 Correct 2396 ms 14936 KB Output is correct
65 Correct 669 ms 14680 KB Output is correct
66 Correct 2086 ms 14936 KB Output is correct
67 Correct 2105 ms 14936 KB Output is correct
68 Correct 2180 ms 14936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14680 KB Output is correct
3 Correct 2 ms 14772 KB Output is correct
4 Correct 3 ms 14680 KB Output is correct
5 Correct 2 ms 14680 KB Output is correct
6 Correct 2 ms 14680 KB Output is correct
7 Correct 2 ms 14680 KB Output is correct
8 Correct 2 ms 14680 KB Output is correct
9 Correct 2 ms 14680 KB Output is correct
10 Correct 2 ms 14680 KB Output is correct
11 Correct 2 ms 14680 KB Output is correct
12 Correct 2 ms 14680 KB Output is correct
13 Correct 2 ms 14680 KB Output is correct
14 Correct 2 ms 14680 KB Output is correct
15 Correct 2 ms 14856 KB Output is correct
16 Correct 2 ms 14680 KB Output is correct
17 Correct 2 ms 14680 KB Output is correct
18 Correct 2 ms 14680 KB Output is correct
19 Correct 2 ms 14680 KB Output is correct
20 Correct 2 ms 14680 KB Output is correct
21 Correct 2 ms 14680 KB Output is correct
22 Correct 2 ms 14680 KB Output is correct
23 Correct 2 ms 14680 KB Output is correct
24 Correct 2 ms 14680 KB Output is correct
25 Correct 2 ms 14680 KB Output is correct
26 Correct 2 ms 14680 KB Output is correct
27 Correct 2 ms 14680 KB Output is correct
28 Correct 2 ms 14680 KB Output is correct
29 Correct 2 ms 14680 KB Output is correct
30 Correct 2 ms 14680 KB Output is correct
31 Correct 2 ms 14680 KB Output is correct
32 Correct 2 ms 14680 KB Output is correct
33 Correct 2 ms 14772 KB Output is correct
34 Correct 2 ms 14680 KB Output is correct
35 Correct 2 ms 14680 KB Output is correct
36 Correct 2 ms 14680 KB Output is correct
37 Correct 2 ms 14936 KB Output is correct
38 Correct 2 ms 14680 KB Output is correct
39 Correct 2 ms 14680 KB Output is correct
40 Correct 2 ms 14680 KB Output is correct
41 Correct 2 ms 14680 KB Output is correct
42 Correct 2 ms 14680 KB Output is correct
43 Execution timed out 3056 ms 16464 KB Time limit exceeded
44 Halted 0 ms 0 KB -