답안 #1058040

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058040 2024-08-14T08:05:31 Z fuad27 디지털 회로 (IOI22_circuit) C++17
46 / 100
572 ms 19288 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
const long long mod=1'000'002'022; // ????? 
const int N = 1e5+10;
vector<int> child[N];
long long total[N];
long long contrib[N];
 
void dfs(int at) {
	total[at] = max(1, (int)child[at].size());
	for(int to:child[at]) {
		dfs(to);
		total[at] = (total[at] * total[to])%mod;
	}
}
void dfs2(int at) {
	if(!child[at].size())return;
	long long sumtot = 0;
	for(int to:child[at]) {
		sumtot+=total[to];
		sumtot%=mod;
	}
	int c = child[at].size();
	vector<long long> pref(c);
	pref[0] = 1;
	for(int i = 1;i<c;i++) {
		pref[i] = (pref[i-1] * total[child[at][i-1]])%mod;
	}
	long long suff = 1;
	for(int i = c-1;i>=0;i--) {
		contrib[child[at][i]] = (((suff*pref[i])%mod)*contrib[at])%mod;
		dfs2(child[at][i]);
		suff = (suff*total[child[at][i]])%mod;
	}
}
vector<int> A;
int nn;

pair<long long, long long> T[4*N];
int lz[4*N];
void build(vector<int> &a, int tl = 0, int tr = N-1, int v = 1) {
	if(tl == tr) {
		if((int)a.size() > tl)T[v] = {a[tl], 0};
		else T[v] = {0, 0};
		return;
	}
	int tm = (tl+tr)/2;
	build(a, tl, tm, 2*v);
	build(a, tm+1, tr, 2*v+1);
	T[v].first = (T[2*v].first + T[2*v+1].first)%mod;
	T[v].second = (T[2*v].second + T[2*v+1].second)%mod;
}
void push(int v) {
	if(lz[v]) {
		lz[v] = 0;
		lz[2*v]^=1;
		lz[2*v+1]^=1;
		swap(T[2*v].first, T[2*v].second);
		swap(T[2*v+1].first, T[2*v+1].second);
	}
}
void update(int l, int r, int tl = 0, int tr = N-1, int v = 1) {
	if(r < tl or tr < l)return;
	if(l<=tl and tr<=r) {
		lz[v] ^= 1;
		swap(T[v].first, T[v].second);
		return;
	}
	push(v);
	int tm = (tl+tr)/2;
	update(l, r, tl, tm, 2*v);
	update(l, r, tm+1, tr, 2*v+1);
	T[v].first = (T[2*v].first + T[2*v+1].first)%mod;
	T[v].second = (T[2*v].second + T[2*v+1].second)%mod;
}

void init(int n, int m, std::vector<int> p, std::vector<int> a) {
	nn=n;
	A = a;
	for(int i = 1;i<m+n;i++) {
		child[p[i]].push_back(i);
	}
	for(int i= 0;i<m+n;i++)contrib[i] = 1;
	dfs(0);
	dfs2(0);
	vector<int> cont(m);
	for(int i = 0;i<m;i++) {
		cont[i] = contrib[i+n];
	}
	build(cont);
	for(int i = 0;i<m;i++) {
		if(A[i]) {
			update(i, i);
		}
	}
}
 
int count_ways(int L, int R) {
	L-=nn, R-=nn;
	update(L, R);
	long long ans = (total[0] - T[1].first)%mod;
	ans+=mod;
	ans%=mod;
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11864 KB Output is correct
2 Correct 2 ms 11864 KB Output is correct
3 Correct 2 ms 11864 KB Output is correct
4 Correct 2 ms 11864 KB Output is correct
5 Correct 2 ms 11864 KB Output is correct
6 Correct 2 ms 11864 KB Output is correct
7 Correct 2 ms 11864 KB Output is correct
8 Correct 2 ms 11864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11864 KB Output is correct
2 Correct 2 ms 11864 KB Output is correct
3 Correct 2 ms 11864 KB Output is correct
4 Correct 3 ms 11864 KB Output is correct
5 Correct 2 ms 11864 KB Output is correct
6 Correct 2 ms 11864 KB Output is correct
7 Correct 2 ms 11864 KB Output is correct
8 Correct 2 ms 11864 KB Output is correct
9 Correct 2 ms 11864 KB Output is correct
10 Correct 3 ms 12120 KB Output is correct
11 Correct 3 ms 12164 KB Output is correct
12 Correct 3 ms 11864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11864 KB Output is correct
2 Correct 2 ms 11864 KB Output is correct
3 Correct 2 ms 11864 KB Output is correct
4 Correct 2 ms 11864 KB Output is correct
5 Correct 2 ms 11864 KB Output is correct
6 Correct 2 ms 11864 KB Output is correct
7 Correct 2 ms 11864 KB Output is correct
8 Correct 2 ms 11864 KB Output is correct
9 Correct 2 ms 11864 KB Output is correct
10 Correct 2 ms 11864 KB Output is correct
11 Correct 2 ms 11864 KB Output is correct
12 Correct 3 ms 11864 KB Output is correct
13 Correct 2 ms 11864 KB Output is correct
14 Correct 2 ms 11864 KB Output is correct
15 Correct 2 ms 11864 KB Output is correct
16 Correct 2 ms 11864 KB Output is correct
17 Correct 2 ms 11864 KB Output is correct
18 Correct 3 ms 12120 KB Output is correct
19 Correct 3 ms 12164 KB Output is correct
20 Correct 3 ms 11864 KB Output is correct
21 Correct 2 ms 11864 KB Output is correct
22 Correct 3 ms 11864 KB Output is correct
23 Correct 2 ms 11864 KB Output is correct
24 Correct 2 ms 11864 KB Output is correct
25 Correct 2 ms 11864 KB Output is correct
26 Correct 2 ms 11864 KB Output is correct
27 Correct 2 ms 11864 KB Output is correct
28 Correct 3 ms 11864 KB Output is correct
29 Correct 2 ms 11864 KB Output is correct
30 Correct 2 ms 11864 KB Output is correct
31 Correct 2 ms 12120 KB Output is correct
32 Correct 3 ms 11864 KB Output is correct
33 Correct 2 ms 12036 KB Output is correct
34 Correct 3 ms 11864 KB Output is correct
35 Correct 2 ms 11864 KB Output is correct
36 Correct 2 ms 12120 KB Output is correct
37 Correct 2 ms 12120 KB Output is correct
38 Correct 2 ms 12120 KB Output is correct
39 Correct 2 ms 11864 KB Output is correct
40 Correct 2 ms 12040 KB Output is correct
41 Correct 3 ms 11864 KB Output is correct
42 Correct 2 ms 11864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 384 ms 14096 KB Output is correct
2 Runtime error 19 ms 19288 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 384 ms 14096 KB Output is correct
2 Runtime error 19 ms 19288 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11864 KB Output is correct
2 Correct 2 ms 11864 KB Output is correct
3 Correct 2 ms 11864 KB Output is correct
4 Correct 3 ms 11864 KB Output is correct
5 Correct 2 ms 11864 KB Output is correct
6 Correct 2 ms 11864 KB Output is correct
7 Correct 2 ms 11864 KB Output is correct
8 Correct 2 ms 11864 KB Output is correct
9 Correct 2 ms 11864 KB Output is correct
10 Correct 3 ms 12120 KB Output is correct
11 Correct 3 ms 12164 KB Output is correct
12 Correct 3 ms 11864 KB Output is correct
13 Correct 384 ms 14096 KB Output is correct
14 Runtime error 19 ms 19288 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11864 KB Output is correct
2 Correct 2 ms 11864 KB Output is correct
3 Correct 2 ms 11864 KB Output is correct
4 Correct 2 ms 11864 KB Output is correct
5 Correct 2 ms 11864 KB Output is correct
6 Correct 2 ms 11864 KB Output is correct
7 Correct 2 ms 11864 KB Output is correct
8 Correct 2 ms 11864 KB Output is correct
9 Correct 2 ms 11864 KB Output is correct
10 Correct 2 ms 11864 KB Output is correct
11 Correct 2 ms 11864 KB Output is correct
12 Correct 3 ms 11864 KB Output is correct
13 Correct 2 ms 11864 KB Output is correct
14 Correct 2 ms 11864 KB Output is correct
15 Correct 2 ms 11864 KB Output is correct
16 Correct 2 ms 11864 KB Output is correct
17 Correct 2 ms 11864 KB Output is correct
18 Correct 3 ms 12120 KB Output is correct
19 Correct 3 ms 12164 KB Output is correct
20 Correct 3 ms 11864 KB Output is correct
21 Correct 2 ms 11864 KB Output is correct
22 Correct 3 ms 11864 KB Output is correct
23 Correct 2 ms 11864 KB Output is correct
24 Correct 2 ms 11864 KB Output is correct
25 Correct 2 ms 11864 KB Output is correct
26 Correct 2 ms 11864 KB Output is correct
27 Correct 2 ms 11864 KB Output is correct
28 Correct 3 ms 11864 KB Output is correct
29 Correct 2 ms 11864 KB Output is correct
30 Correct 2 ms 11864 KB Output is correct
31 Correct 2 ms 12120 KB Output is correct
32 Correct 3 ms 11864 KB Output is correct
33 Correct 2 ms 12036 KB Output is correct
34 Correct 3 ms 11864 KB Output is correct
35 Correct 2 ms 11864 KB Output is correct
36 Correct 2 ms 12120 KB Output is correct
37 Correct 2 ms 12120 KB Output is correct
38 Correct 2 ms 12120 KB Output is correct
39 Correct 2 ms 11864 KB Output is correct
40 Correct 2 ms 12040 KB Output is correct
41 Correct 3 ms 11864 KB Output is correct
42 Correct 2 ms 11864 KB Output is correct
43 Correct 367 ms 12120 KB Output is correct
44 Correct 557 ms 12120 KB Output is correct
45 Correct 561 ms 12120 KB Output is correct
46 Correct 566 ms 12120 KB Output is correct
47 Correct 551 ms 12120 KB Output is correct
48 Correct 509 ms 12120 KB Output is correct
49 Correct 435 ms 12120 KB Output is correct
50 Correct 414 ms 12120 KB Output is correct
51 Correct 416 ms 12208 KB Output is correct
52 Correct 559 ms 12200 KB Output is correct
53 Correct 544 ms 12632 KB Output is correct
54 Correct 526 ms 12120 KB Output is correct
55 Correct 543 ms 12120 KB Output is correct
56 Correct 517 ms 12120 KB Output is correct
57 Correct 439 ms 12120 KB Output is correct
58 Correct 434 ms 12632 KB Output is correct
59 Correct 572 ms 12888 KB Output is correct
60 Correct 560 ms 12888 KB Output is correct
61 Correct 496 ms 12120 KB Output is correct
62 Correct 508 ms 12120 KB Output is correct
63 Correct 527 ms 12120 KB Output is correct
64 Correct 466 ms 12120 KB Output is correct
65 Correct 177 ms 12120 KB Output is correct
66 Correct 454 ms 12160 KB Output is correct
67 Correct 486 ms 12120 KB Output is correct
68 Correct 572 ms 12120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11864 KB Output is correct
2 Correct 2 ms 11864 KB Output is correct
3 Correct 2 ms 11864 KB Output is correct
4 Correct 2 ms 11864 KB Output is correct
5 Correct 2 ms 11864 KB Output is correct
6 Correct 2 ms 11864 KB Output is correct
7 Correct 2 ms 11864 KB Output is correct
8 Correct 2 ms 11864 KB Output is correct
9 Correct 2 ms 11864 KB Output is correct
10 Correct 2 ms 11864 KB Output is correct
11 Correct 2 ms 11864 KB Output is correct
12 Correct 3 ms 11864 KB Output is correct
13 Correct 2 ms 11864 KB Output is correct
14 Correct 2 ms 11864 KB Output is correct
15 Correct 2 ms 11864 KB Output is correct
16 Correct 2 ms 11864 KB Output is correct
17 Correct 2 ms 11864 KB Output is correct
18 Correct 3 ms 12120 KB Output is correct
19 Correct 3 ms 12164 KB Output is correct
20 Correct 3 ms 11864 KB Output is correct
21 Correct 2 ms 11864 KB Output is correct
22 Correct 3 ms 11864 KB Output is correct
23 Correct 2 ms 11864 KB Output is correct
24 Correct 2 ms 11864 KB Output is correct
25 Correct 2 ms 11864 KB Output is correct
26 Correct 2 ms 11864 KB Output is correct
27 Correct 2 ms 11864 KB Output is correct
28 Correct 3 ms 11864 KB Output is correct
29 Correct 2 ms 11864 KB Output is correct
30 Correct 2 ms 11864 KB Output is correct
31 Correct 2 ms 12120 KB Output is correct
32 Correct 3 ms 11864 KB Output is correct
33 Correct 2 ms 12036 KB Output is correct
34 Correct 3 ms 11864 KB Output is correct
35 Correct 2 ms 11864 KB Output is correct
36 Correct 2 ms 12120 KB Output is correct
37 Correct 2 ms 12120 KB Output is correct
38 Correct 2 ms 12120 KB Output is correct
39 Correct 2 ms 11864 KB Output is correct
40 Correct 2 ms 12040 KB Output is correct
41 Correct 3 ms 11864 KB Output is correct
42 Correct 2 ms 11864 KB Output is correct
43 Correct 384 ms 14096 KB Output is correct
44 Runtime error 19 ms 19288 KB Execution killed with signal 11
45 Halted 0 ms 0 KB -