답안 #800683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
800683 2023-08-01T18:07:59 Z dxz05 디지털 회로 (IOI22_circuit) C++17
46 / 100
3000 ms 16472 KB
#include "circuit.h"
#include <bits/stdc++.h>
 
using namespace std;
 
const int MaxN = 200005;
const int MOD = 1e9 + 2022;
 
int N, M;
vector<int> A;
 
int contribution[MaxN];
 
struct node{
	int sum;
	int sum2;
	bool flag;
	
	node(){
		sum = sum2 = 0;
		flag = false;
	};
};
 
node tree[4 * MaxN];
 
void flip(int v){
	swap(tree[v].sum, tree[v].sum2);
	tree[v].flag ^= 1;
}
 
void push(int v, int tl, int tr){
	if (tl == tr || !tree[v].flag) return;
	flip(v << 1);
	flip(v << 1 | 1);
	tree[v].flag = false;
}
 
void build(int v, int tl, int tr){
	if (tl == tr){
		tree[v].sum = A[tl - N] * contribution[tl];
		tree[v].sum2 = (!A[tl - N]) * contribution[tl];
		return;
	}
	int tm = (tl + tr) >> 1;
	build(v << 1, tl, tm);
	build(v << 1 | 1, tm + 1, tr);
	
	tree[v].sum = (tree[v << 1].sum + tree[v << 1 | 1].sum) % MOD;
	tree[v].sum2 = (tree[v << 1].sum2 + tree[v << 1 | 1].sum2) % MOD;
}
 
void update(int v, int tl, int tr, int l, int r){
	push(v, tl, tr);
	if (l <= tl && tr <= r){
		flip(v);
		return;
	}
	if (tl > r || tr < l) return;
	int tm = (tl + tr) >> 1;
	update(v << 1, tl, tm, l, r);
	update(v << 1 | 1, tm + 1, tr, l, r);
	
	tree[v].sum = (tree[v << 1].sum + tree[v << 1 | 1].sum) % MOD;
	tree[v].sum2 = (tree[v << 1].sum2 + tree[v << 1 | 1].sum2) % MOD;
}
 
void update(int l, int r){
	update(1, N, N + M - 1, l, r);
}
 
int get(){
	return tree[1].sum;
}
 
vector<int> g[MaxN];
 
int dep[MaxN];

void dfs(int v, int p, map<int, int> mp){	
	int sz = (int) g[v].size();
	if (sz == 0){
		int &res = contribution[v];	
		res = 1;
		for (auto [d, cnt] : mp){
			while (cnt--) res = 1LL * res * d % MOD;
		}
	} else {
		mp[sz]--;
	}
	
	for (int u : g[v]){
		if (u != p){
			dfs(u, v, mp);
		}
	}
}
 
void init(int _N, int _M, vector<int> P, vector<int> _A) {
    N = _N, M = _M, A = _A;
    for (int i = 1; i < N + M; i++){
        g[P[i]].push_back(i);
    }
    
    map<int, int> mp;
    for (int i = 0; i < N; i++){
		mp[(int) g[i].size()]++;
	}
	
    dfs(0, -1, mp);
        
    build(1, N, N + M - 1);
}
 
int count_ways(int L, int R) {
    update(L, R);
    return get();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14288 KB Output is correct
2 Correct 6 ms 14368 KB Output is correct
3 Correct 6 ms 14416 KB Output is correct
4 Correct 6 ms 14416 KB Output is correct
5 Correct 6 ms 14324 KB Output is correct
6 Correct 6 ms 14416 KB Output is correct
7 Correct 6 ms 14416 KB Output is correct
8 Correct 6 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14288 KB Output is correct
2 Correct 6 ms 14416 KB Output is correct
3 Correct 9 ms 14416 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 8 ms 14364 KB Output is correct
6 Correct 9 ms 14448 KB Output is correct
7 Correct 11 ms 14464 KB Output is correct
8 Correct 11 ms 14464 KB Output is correct
9 Correct 11 ms 14416 KB Output is correct
10 Correct 9 ms 14544 KB Output is correct
11 Correct 9 ms 14544 KB Output is correct
12 Correct 9 ms 14460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14288 KB Output is correct
2 Correct 6 ms 14368 KB Output is correct
3 Correct 6 ms 14416 KB Output is correct
4 Correct 6 ms 14416 KB Output is correct
5 Correct 6 ms 14324 KB Output is correct
6 Correct 6 ms 14416 KB Output is correct
7 Correct 6 ms 14416 KB Output is correct
8 Correct 6 ms 14416 KB Output is correct
9 Correct 7 ms 14288 KB Output is correct
10 Correct 6 ms 14416 KB Output is correct
11 Correct 9 ms 14416 KB Output is correct
12 Correct 8 ms 14416 KB Output is correct
13 Correct 8 ms 14364 KB Output is correct
14 Correct 9 ms 14448 KB Output is correct
15 Correct 11 ms 14464 KB Output is correct
16 Correct 11 ms 14464 KB Output is correct
17 Correct 11 ms 14416 KB Output is correct
18 Correct 9 ms 14544 KB Output is correct
19 Correct 9 ms 14544 KB Output is correct
20 Correct 9 ms 14460 KB Output is correct
21 Correct 9 ms 14456 KB Output is correct
22 Correct 8 ms 14416 KB Output is correct
23 Correct 8 ms 14416 KB Output is correct
24 Correct 11 ms 14416 KB Output is correct
25 Correct 11 ms 14404 KB Output is correct
26 Correct 12 ms 14416 KB Output is correct
27 Correct 11 ms 14436 KB Output is correct
28 Correct 12 ms 14472 KB Output is correct
29 Correct 7 ms 14416 KB Output is correct
30 Correct 7 ms 14416 KB Output is correct
31 Correct 6 ms 14544 KB Output is correct
32 Correct 11 ms 14408 KB Output is correct
33 Correct 9 ms 14416 KB Output is correct
34 Correct 7 ms 14416 KB Output is correct
35 Correct 6 ms 14416 KB Output is correct
36 Correct 9 ms 14672 KB Output is correct
37 Correct 7 ms 14672 KB Output is correct
38 Correct 7 ms 14672 KB Output is correct
39 Correct 8 ms 14420 KB Output is correct
40 Correct 10 ms 14416 KB Output is correct
41 Correct 8 ms 14416 KB Output is correct
42 Correct 8 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3043 ms 16472 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3043 ms 16472 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14288 KB Output is correct
2 Correct 6 ms 14416 KB Output is correct
3 Correct 9 ms 14416 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 8 ms 14364 KB Output is correct
6 Correct 9 ms 14448 KB Output is correct
7 Correct 11 ms 14464 KB Output is correct
8 Correct 11 ms 14464 KB Output is correct
9 Correct 11 ms 14416 KB Output is correct
10 Correct 9 ms 14544 KB Output is correct
11 Correct 9 ms 14544 KB Output is correct
12 Correct 9 ms 14460 KB Output is correct
13 Execution timed out 3043 ms 16472 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14288 KB Output is correct
2 Correct 6 ms 14368 KB Output is correct
3 Correct 6 ms 14416 KB Output is correct
4 Correct 6 ms 14416 KB Output is correct
5 Correct 6 ms 14324 KB Output is correct
6 Correct 6 ms 14416 KB Output is correct
7 Correct 6 ms 14416 KB Output is correct
8 Correct 6 ms 14416 KB Output is correct
9 Correct 7 ms 14288 KB Output is correct
10 Correct 6 ms 14416 KB Output is correct
11 Correct 9 ms 14416 KB Output is correct
12 Correct 8 ms 14416 KB Output is correct
13 Correct 8 ms 14364 KB Output is correct
14 Correct 9 ms 14448 KB Output is correct
15 Correct 11 ms 14464 KB Output is correct
16 Correct 11 ms 14464 KB Output is correct
17 Correct 11 ms 14416 KB Output is correct
18 Correct 9 ms 14544 KB Output is correct
19 Correct 9 ms 14544 KB Output is correct
20 Correct 9 ms 14460 KB Output is correct
21 Correct 9 ms 14456 KB Output is correct
22 Correct 8 ms 14416 KB Output is correct
23 Correct 8 ms 14416 KB Output is correct
24 Correct 11 ms 14416 KB Output is correct
25 Correct 11 ms 14404 KB Output is correct
26 Correct 12 ms 14416 KB Output is correct
27 Correct 11 ms 14436 KB Output is correct
28 Correct 12 ms 14472 KB Output is correct
29 Correct 7 ms 14416 KB Output is correct
30 Correct 7 ms 14416 KB Output is correct
31 Correct 6 ms 14544 KB Output is correct
32 Correct 11 ms 14408 KB Output is correct
33 Correct 9 ms 14416 KB Output is correct
34 Correct 7 ms 14416 KB Output is correct
35 Correct 6 ms 14416 KB Output is correct
36 Correct 9 ms 14672 KB Output is correct
37 Correct 7 ms 14672 KB Output is correct
38 Correct 7 ms 14672 KB Output is correct
39 Correct 8 ms 14420 KB Output is correct
40 Correct 10 ms 14416 KB Output is correct
41 Correct 8 ms 14416 KB Output is correct
42 Correct 8 ms 14416 KB Output is correct
43 Correct 464 ms 14500 KB Output is correct
44 Correct 672 ms 14560 KB Output is correct
45 Correct 766 ms 14596 KB Output is correct
46 Correct 799 ms 14712 KB Output is correct
47 Correct 768 ms 14672 KB Output is correct
48 Correct 883 ms 14728 KB Output is correct
49 Correct 791 ms 14728 KB Output is correct
50 Correct 843 ms 14720 KB Output is correct
51 Correct 695 ms 14544 KB Output is correct
52 Correct 754 ms 14500 KB Output is correct
53 Correct 449 ms 15568 KB Output is correct
54 Correct 903 ms 14696 KB Output is correct
55 Correct 747 ms 14544 KB Output is correct
56 Correct 804 ms 14608 KB Output is correct
57 Correct 841 ms 14528 KB Output is correct
58 Correct 894 ms 15940 KB Output is correct
59 Correct 573 ms 15952 KB Output is correct
60 Correct 602 ms 15952 KB Output is correct
61 Correct 583 ms 14928 KB Output is correct
62 Correct 786 ms 14544 KB Output is correct
63 Correct 1002 ms 14564 KB Output is correct
64 Correct 710 ms 14612 KB Output is correct
65 Correct 377 ms 14640 KB Output is correct
66 Correct 864 ms 14644 KB Output is correct
67 Correct 867 ms 14644 KB Output is correct
68 Correct 672 ms 14648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14288 KB Output is correct
2 Correct 6 ms 14368 KB Output is correct
3 Correct 6 ms 14416 KB Output is correct
4 Correct 6 ms 14416 KB Output is correct
5 Correct 6 ms 14324 KB Output is correct
6 Correct 6 ms 14416 KB Output is correct
7 Correct 6 ms 14416 KB Output is correct
8 Correct 6 ms 14416 KB Output is correct
9 Correct 7 ms 14288 KB Output is correct
10 Correct 6 ms 14416 KB Output is correct
11 Correct 9 ms 14416 KB Output is correct
12 Correct 8 ms 14416 KB Output is correct
13 Correct 8 ms 14364 KB Output is correct
14 Correct 9 ms 14448 KB Output is correct
15 Correct 11 ms 14464 KB Output is correct
16 Correct 11 ms 14464 KB Output is correct
17 Correct 11 ms 14416 KB Output is correct
18 Correct 9 ms 14544 KB Output is correct
19 Correct 9 ms 14544 KB Output is correct
20 Correct 9 ms 14460 KB Output is correct
21 Correct 9 ms 14456 KB Output is correct
22 Correct 8 ms 14416 KB Output is correct
23 Correct 8 ms 14416 KB Output is correct
24 Correct 11 ms 14416 KB Output is correct
25 Correct 11 ms 14404 KB Output is correct
26 Correct 12 ms 14416 KB Output is correct
27 Correct 11 ms 14436 KB Output is correct
28 Correct 12 ms 14472 KB Output is correct
29 Correct 7 ms 14416 KB Output is correct
30 Correct 7 ms 14416 KB Output is correct
31 Correct 6 ms 14544 KB Output is correct
32 Correct 11 ms 14408 KB Output is correct
33 Correct 9 ms 14416 KB Output is correct
34 Correct 7 ms 14416 KB Output is correct
35 Correct 6 ms 14416 KB Output is correct
36 Correct 9 ms 14672 KB Output is correct
37 Correct 7 ms 14672 KB Output is correct
38 Correct 7 ms 14672 KB Output is correct
39 Correct 8 ms 14420 KB Output is correct
40 Correct 10 ms 14416 KB Output is correct
41 Correct 8 ms 14416 KB Output is correct
42 Correct 8 ms 14416 KB Output is correct
43 Execution timed out 3043 ms 16472 KB Time limit exceeded
44 Halted 0 ms 0 KB -