Submission #830462

# Submission time Handle Problem Language Result Execution time Memory
830462 2023-08-19T06:48:35 Z FatihSolak Digital Circuit (IOI22_circuit) C++17
100 / 100
912 ms 29780 KB
#include "circuit.h"
#include <bits/stdc++.h>
#define N 200005
using namespace std;
const int mod = 1e9 + 2022;
struct SegTree{
	vector<pair<int,int>> t;
	vector<int> lazy;
	int n;
	void init(int sz ,vector<pair<int,int>> a){
		n = sz;
		t.assign(4*n,{0,0});
		lazy.assign(4*n,0);
		build(1,0,n-1,a);
	}
	void build(int v,int tl,int tr,vector<pair<int,int>> &a){
		if(tl == tr){
			t[v].first = a[tl].first;
			t[v].second = a[tl].second; 
			return;
		}
		int tm = (tl + tr)/2;
		build(v*2,tl,tm,a);
		build(v*2+1,tm+1,tr,a);
		t[v].first = (t[v*2].first + t[v*2 + 1].first)%mod;
		t[v].second = (t[v*2].second + t[v*2 + 1].second)%mod;
	}
	void push(int v){
		if(lazy[v]){
			swap(t[v*2].first,t[v*2].second);
			lazy[v*2] ^= 1;
			swap(t[v*2+1].first,t[v*2+1].second);
			lazy[v*2 + 1] ^= 1;
			lazy[v] = 0;
		}
	}
	void upd(int v,int tl,int tr,int l,int r){
		if(tr < l || r < tl)
			return;
		if(l <= tl && tr <= r){
			swap(t[v].first,t[v].second);
			lazy[v] ^= 1;
			return;
		}
		push(v);
		int tm = (tl + tr)/2;
		upd(v*2,tl,tm,l,r);
		upd(v*2+1,tm+1,tr,l,r);
		t[v].first = (t[v*2].first + t[v*2 + 1].first)%mod;
		t[v].second = (t[v*2].second + t[v*2 + 1].second)%mod;
	}
	void upd(int l,int r){
		upd(1,0,n-1,l,r);
	}
};
vector<int> adj[N];
vector<pair<int,int>> xx;
int val[N];
int n,m;
void dfs1(int v){
	val[v] = max(1,(int)adj[v].size());
	for(auto u:adj[v]){
		dfs1(u);
		val[v] = (long long)val[v] * val[u] % mod;
	}
}
void dfs2(int v,int num){
	vector<int> x;
	for(auto u:adj[v]){
		x.push_back(val[u]);
	}
	for(int i = x.size()-2;i>=0;i--){
		x[i] = (long long)x[i] * x[i+1] % mod;
	}
	if(v >= n){
		xx[v - n].first = num;
	}
	int now = num;
	for(int i = 0;i<adj[v].size();i++){
		int tmp = now;
		if(i != adj[v].size() - 1)
			tmp = (long long)tmp * x[i+1]%mod;
		// cout << v << ' ' << adj[v][i] << ' ' << tmp << endl;
		dfs2(adj[v][i],tmp);
		now = (long long)now * val[adj[v][i]] % mod;
	}
}
SegTree t;
void init(int _n, int _m, vector<int> P, vector<int> A){
	n = _n;
	m = _m;
	xx.assign(m,{0,0});
	for(int i = 1;i<n+m;i++){
		adj[P[i]].push_back(i);
	}
	dfs1(0);
	dfs2(0,1);
	for(int i = 0;i<m;i++){
		// cout << i << ' ' << xx[i].first << endl;
		if(A[i] == 0)
			swap(xx[i].first,xx[i].second);
	}
	t.init(m,xx);
}

int count_ways(int L, int R) {
	t.upd(L-n,R-n);
	return t.t[1].first;
}

Compilation message

circuit.cpp: In function 'void dfs2(int, int)':
circuit.cpp:79:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |  for(int i = 0;i<adj[v].size();i++){
      |                ~^~~~~~~~~~~~~~
circuit.cpp:81:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |   if(i != adj[v].size() - 1)
      |      ~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 3 ms 5088 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5036 KB Output is correct
4 Correct 3 ms 5064 KB Output is correct
5 Correct 2 ms 4944 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 3 ms 5088 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5036 KB Output is correct
12 Correct 3 ms 5064 KB Output is correct
13 Correct 2 ms 4944 KB Output is correct
14 Correct 4 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 4 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 2 ms 5072 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 2 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 5076 KB Output is correct
30 Correct 2 ms 5072 KB Output is correct
31 Correct 2 ms 5072 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 2 ms 5072 KB Output is correct
35 Correct 4 ms 5200 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 2 ms 4996 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 2 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 520 ms 9100 KB Output is correct
2 Correct 594 ms 13212 KB Output is correct
3 Correct 663 ms 13192 KB Output is correct
4 Correct 585 ms 13260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 520 ms 9100 KB Output is correct
2 Correct 594 ms 13212 KB Output is correct
3 Correct 663 ms 13192 KB Output is correct
4 Correct 585 ms 13260 KB Output is correct
5 Correct 581 ms 9112 KB Output is correct
6 Correct 546 ms 13208 KB Output is correct
7 Correct 777 ms 13184 KB Output is correct
8 Correct 589 ms 13204 KB Output is correct
9 Correct 262 ms 5236 KB Output is correct
10 Correct 683 ms 5504 KB Output is correct
11 Correct 612 ms 5508 KB Output is correct
12 Correct 575 ms 5504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5036 KB Output is correct
4 Correct 3 ms 5064 KB Output is correct
5 Correct 2 ms 4944 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 520 ms 9100 KB Output is correct
14 Correct 594 ms 13212 KB Output is correct
15 Correct 663 ms 13192 KB Output is correct
16 Correct 585 ms 13260 KB Output is correct
17 Correct 581 ms 9112 KB Output is correct
18 Correct 546 ms 13208 KB Output is correct
19 Correct 777 ms 13184 KB Output is correct
20 Correct 589 ms 13204 KB Output is correct
21 Correct 262 ms 5236 KB Output is correct
22 Correct 683 ms 5504 KB Output is correct
23 Correct 612 ms 5508 KB Output is correct
24 Correct 575 ms 5504 KB Output is correct
25 Correct 665 ms 17276 KB Output is correct
26 Correct 761 ms 17480 KB Output is correct
27 Correct 824 ms 17532 KB Output is correct
28 Correct 532 ms 17440 KB Output is correct
29 Correct 826 ms 29308 KB Output is correct
30 Correct 765 ms 29204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 3 ms 5088 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5036 KB Output is correct
12 Correct 3 ms 5064 KB Output is correct
13 Correct 2 ms 4944 KB Output is correct
14 Correct 4 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 4 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 2 ms 5072 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 2 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 5076 KB Output is correct
30 Correct 2 ms 5072 KB Output is correct
31 Correct 2 ms 5072 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 2 ms 5072 KB Output is correct
35 Correct 4 ms 5200 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 2 ms 4996 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 2 ms 5072 KB Output is correct
43 Correct 597 ms 5332 KB Output is correct
44 Correct 633 ms 5360 KB Output is correct
45 Correct 594 ms 5360 KB Output is correct
46 Correct 651 ms 5632 KB Output is correct
47 Correct 604 ms 5624 KB Output is correct
48 Correct 773 ms 5636 KB Output is correct
49 Correct 636 ms 5624 KB Output is correct
50 Correct 611 ms 5628 KB Output is correct
51 Correct 791 ms 5456 KB Output is correct
52 Correct 622 ms 5456 KB Output is correct
53 Correct 775 ms 5888 KB Output is correct
54 Correct 641 ms 5624 KB Output is correct
55 Correct 666 ms 5512 KB Output is correct
56 Correct 662 ms 5484 KB Output is correct
57 Correct 628 ms 5432 KB Output is correct
58 Correct 828 ms 6096 KB Output is correct
59 Correct 638 ms 6224 KB Output is correct
60 Correct 545 ms 6224 KB Output is correct
61 Correct 740 ms 5496 KB Output is correct
62 Correct 745 ms 5356 KB Output is correct
63 Correct 750 ms 5352 KB Output is correct
64 Correct 680 ms 5456 KB Output is correct
65 Correct 360 ms 5232 KB Output is correct
66 Correct 733 ms 5508 KB Output is correct
67 Correct 593 ms 5508 KB Output is correct
68 Correct 625 ms 5504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 3 ms 5088 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5036 KB Output is correct
12 Correct 3 ms 5064 KB Output is correct
13 Correct 2 ms 4944 KB Output is correct
14 Correct 4 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 4 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 2 ms 5072 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 2 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 5076 KB Output is correct
30 Correct 2 ms 5072 KB Output is correct
31 Correct 2 ms 5072 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 2 ms 5072 KB Output is correct
35 Correct 4 ms 5200 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 2 ms 4996 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 2 ms 5072 KB Output is correct
43 Correct 520 ms 9100 KB Output is correct
44 Correct 594 ms 13212 KB Output is correct
45 Correct 663 ms 13192 KB Output is correct
46 Correct 585 ms 13260 KB Output is correct
47 Correct 581 ms 9112 KB Output is correct
48 Correct 546 ms 13208 KB Output is correct
49 Correct 777 ms 13184 KB Output is correct
50 Correct 589 ms 13204 KB Output is correct
51 Correct 262 ms 5236 KB Output is correct
52 Correct 683 ms 5504 KB Output is correct
53 Correct 612 ms 5508 KB Output is correct
54 Correct 575 ms 5504 KB Output is correct
55 Correct 665 ms 17276 KB Output is correct
56 Correct 761 ms 17480 KB Output is correct
57 Correct 824 ms 17532 KB Output is correct
58 Correct 532 ms 17440 KB Output is correct
59 Correct 826 ms 29308 KB Output is correct
60 Correct 765 ms 29204 KB Output is correct
61 Correct 597 ms 5332 KB Output is correct
62 Correct 633 ms 5360 KB Output is correct
63 Correct 594 ms 5360 KB Output is correct
64 Correct 651 ms 5632 KB Output is correct
65 Correct 604 ms 5624 KB Output is correct
66 Correct 773 ms 5636 KB Output is correct
67 Correct 636 ms 5624 KB Output is correct
68 Correct 611 ms 5628 KB Output is correct
69 Correct 791 ms 5456 KB Output is correct
70 Correct 622 ms 5456 KB Output is correct
71 Correct 775 ms 5888 KB Output is correct
72 Correct 641 ms 5624 KB Output is correct
73 Correct 666 ms 5512 KB Output is correct
74 Correct 662 ms 5484 KB Output is correct
75 Correct 628 ms 5432 KB Output is correct
76 Correct 828 ms 6096 KB Output is correct
77 Correct 638 ms 6224 KB Output is correct
78 Correct 545 ms 6224 KB Output is correct
79 Correct 740 ms 5496 KB Output is correct
80 Correct 745 ms 5356 KB Output is correct
81 Correct 750 ms 5352 KB Output is correct
82 Correct 680 ms 5456 KB Output is correct
83 Correct 360 ms 5232 KB Output is correct
84 Correct 733 ms 5508 KB Output is correct
85 Correct 593 ms 5508 KB Output is correct
86 Correct 625 ms 5504 KB Output is correct
87 Correct 2 ms 4944 KB Output is correct
88 Correct 543 ms 15860 KB Output is correct
89 Correct 706 ms 12356 KB Output is correct
90 Correct 819 ms 12540 KB Output is correct
91 Correct 818 ms 17556 KB Output is correct
92 Correct 668 ms 17528 KB Output is correct
93 Correct 825 ms 17528 KB Output is correct
94 Correct 748 ms 17560 KB Output is correct
95 Correct 912 ms 17524 KB Output is correct
96 Correct 675 ms 13680 KB Output is correct
97 Correct 799 ms 13668 KB Output is correct
98 Correct 665 ms 23292 KB Output is correct
99 Correct 742 ms 17480 KB Output is correct
100 Correct 882 ms 15380 KB Output is correct
101 Correct 667 ms 14696 KB Output is correct
102 Correct 898 ms 13640 KB Output is correct
103 Correct 807 ms 29180 KB Output is correct
104 Correct 898 ms 29780 KB Output is correct
105 Correct 836 ms 29712 KB Output is correct
106 Correct 723 ms 14476 KB Output is correct
107 Correct 777 ms 12216 KB Output is correct
108 Correct 711 ms 12644 KB Output is correct
109 Correct 889 ms 13764 KB Output is correct