답안 #1078717

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078717 2024-08-28T05:02:12 Z Gromp15 디지털 회로 (IOI22_circuit) C++17
50 / 100
3000 ms 11200 KB
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)x.size()
#define ar array
#include "circuit.h"
using namespace std;

const int mod = int(1e9) + 2022;
void fadd(int &a, int b) {
	a += b;
	if (a >= mod) a -= mod;
}
int add(int x, int y) {
	return x+y >= mod ? x+y-mod : x+y;
}


struct seg {
	int N; vector<int> tree, tot, lazy;
	seg() {}
	seg(int n, const vector<int>& v, const vector<int>& a) : N(1<<(__lg(n)+1)), tree(2*N), tot(2*N), lazy(2*N) {
		for (int i = 0; i < n; i++) tot[i+N] = v[i], tree[i+N] = v[i] * a[i];
		for (int i = N-1; i >= 1; i--) tot[i] = add(tot[i*2], tot[i*2+1]), tree[i] = add(tree[i*2], tree[i*2+1]);
	}
	void push(int node) {
		if (!lazy[node]) return;
		tree[node] = tot[node] - tree[node];
		if (tree[node] < 0) tree[node] += mod;
		if (node < N) {
			lazy[node*2] ^= 1;
			lazy[node*2+1] ^= 1;
		}
		lazy[node] = 0;
	}
	void update(int node, int nl, int nr, int ql, int qr) {
		push(node);
		if (ql > nr || qr < nl) return;
		if (ql <= nl && nr <= qr) {
			lazy[node] ^= 1; push(node); return;
		}
		int mid = (nl+nr)/2;
		update(node*2, nl, mid, ql, qr);
		update(node*2+1, mid+1, nr, ql, qr);
		tree[node] = add(tree[node*2], tree[node*2+1]);
	}
} st;

vector<int> p, a, sub, sub2, val;
vector<vector<int>> adj;
int n, m;

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
	n = N, m = M;
	p = P, a = A;
	adj.resize(N), sub.resize(N+M, 1), sub2.resize(N+M, 1);
	for (int i = 1; i < N + M; i++) adj[P[i]].emplace_back(i);
	for (int i = N-1; i >= 0; i--) {
		sub[i] = sz(adj[i]);
		int cur = sz(adj[i]);
		vector<int> pref(cur), suff(cur);
		for (int j = 0; j < cur; j++) {
			pref[j] = suff[j] = sub[adj[i][j]];
		}
		for (int j = 1; j < cur; j++) pref[j] = (ll)pref[j-1] * pref[j] % mod;
		for (int j = cur-2; j >= 0; j--) suff[j] = (ll)suff[j+1] * suff[j] % mod;
		for (int j = 0; j < cur; j++) {
			int u = adj[i][j];
			sub[i] = (ll)sub[i] * sub[u] % mod;
			sub2[u] = (ll)(j ? pref[j-1] : 1) * (j+1 < cur ? suff[j+1] : 1) % mod;
		}
	}
	val.resize(N+M);
	val[0] = 1;
	for (int i = 1; i < N + M; i++) val[i] = (ll)val[p[i]] * sub2[i] % mod;
	vector<int> val2(M);
	for (int i = N; i < N+M; i++) val2[i-N] = val[i];
	st = seg(m, val2, A);
}


int count_ways(int L, int R) {
	for (int i = L-n; i <= R-n; i++) a[i] ^= 1;
	st.update(1, 0, st.N-1, L - n, R - n);
	return st.tree[1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 420 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 427 ms 5720 KB Output is correct
2 Correct 661 ms 11200 KB Output is correct
3 Correct 661 ms 11096 KB Output is correct
4 Correct 712 ms 11096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 427 ms 5720 KB Output is correct
2 Correct 661 ms 11200 KB Output is correct
3 Correct 661 ms 11096 KB Output is correct
4 Correct 712 ms 11096 KB Output is correct
5 Correct 1040 ms 5720 KB Output is correct
6 Correct 1779 ms 11096 KB Output is correct
7 Correct 1833 ms 11088 KB Output is correct
8 Execution timed out 3030 ms 11092 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 427 ms 5720 KB Output is correct
14 Correct 661 ms 11200 KB Output is correct
15 Correct 661 ms 11096 KB Output is correct
16 Correct 712 ms 11096 KB Output is correct
17 Correct 1040 ms 5720 KB Output is correct
18 Correct 1779 ms 11096 KB Output is correct
19 Correct 1833 ms 11088 KB Output is correct
20 Execution timed out 3030 ms 11092 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 420 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 480 ms 856 KB Output is correct
44 Correct 680 ms 924 KB Output is correct
45 Correct 684 ms 884 KB Output is correct
46 Correct 600 ms 1192 KB Output is correct
47 Correct 736 ms 1192 KB Output is correct
48 Correct 760 ms 1192 KB Output is correct
49 Correct 779 ms 1188 KB Output is correct
50 Correct 918 ms 1192 KB Output is correct
51 Correct 919 ms 832 KB Output is correct
52 Correct 703 ms 856 KB Output is correct
53 Correct 607 ms 600 KB Output is correct
54 Correct 757 ms 1188 KB Output is correct
55 Correct 743 ms 992 KB Output is correct
56 Correct 789 ms 936 KB Output is correct
57 Correct 743 ms 824 KB Output is correct
58 Correct 733 ms 1364 KB Output is correct
59 Correct 772 ms 1228 KB Output is correct
60 Correct 912 ms 1228 KB Output is correct
61 Correct 690 ms 916 KB Output is correct
62 Correct 701 ms 808 KB Output is correct
63 Correct 723 ms 772 KB Output is correct
64 Correct 731 ms 856 KB Output is correct
65 Correct 288 ms 748 KB Output is correct
66 Correct 669 ms 1076 KB Output is correct
67 Correct 761 ms 1108 KB Output is correct
68 Correct 919 ms 1084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 420 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 427 ms 5720 KB Output is correct
44 Correct 661 ms 11200 KB Output is correct
45 Correct 661 ms 11096 KB Output is correct
46 Correct 712 ms 11096 KB Output is correct
47 Correct 1040 ms 5720 KB Output is correct
48 Correct 1779 ms 11096 KB Output is correct
49 Correct 1833 ms 11088 KB Output is correct
50 Execution timed out 3030 ms 11092 KB Time limit exceeded
51 Halted 0 ms 0 KB -