Submission #737650

# Submission time Handle Problem Language Result Execution time Memory
737650 2023-05-07T13:23:08 Z minhcool Digital Circuit (IOI22_circuit) C++17
100 / 100
1644 ms 29260 KB
#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 2e5 + 5;
 
const int oo = 1e18 + 7, mod = 1000002022;
 
int n, m;
vector<int> Adj[N];
 
int arr[N];
 
long long coor[N];
long long pref[N], suff[N];
long long sav[N];

long long weight[N];
 
void dfs(int u){
	if(!Adj[u].size()) return;
	for(auto v : Adj[u]) dfs(v);
	pref[0] = coor[Adj[u][0]];
	for(int i = 1; i < Adj[u].size(); i++) pref[i] = (pref[i - 1] * coor[Adj[u][i]]) % mod;
	suff[Adj[u].size()] = 1;
	for(int i = Adj[u].size() - 1; i >= 0; i--) suff[i] = (suff[i + 1] * coor[Adj[u][i]]) % mod;
	//for(int i = 0; i < Adj[u].size(); i++) cout << pref[i] << " " << suff[i] << "\n";
	coor[u] = (pref[Adj[u].size() - 1] * Adj[u].size()) % mod;
	//cout << u << " " << coor[u] << "\n";
	for(int i = 0; i < Adj[u].size(); i++){
		sav[Adj[u][i]] = (i ? pref[i - 1] : 1);
		sav[Adj[u][i]] = (sav[Adj[u][i]] * suff[i + 1]) % mod;
	}
	//for(int i = 0; i <= m; i++) cout << u << " " << i << " " << coor[u][i] << "\n";
}

void dfs2(int u, int total){
	if(u >= n){
		weight[u - n] = total;
		return;
	}
	for(auto v : Adj[u]){
		dfs2(v, (total * sav[v]) % mod);
	}
}

long long IT[N << 2], tol_weight[N << 2], laz[N << 2];

void build(int id, int l, int r){
	if(l == r){
		tol_weight[id] = weight[l];
		IT[id] = arr[l] * tol_weight[id];
		laz[id] = 0;
		return;
	}
	int mid = (l + r) >> 1;
	build(id << 1, l, mid);
	build(id << 1 | 1, mid + 1, r);
	IT[id] = (IT[id << 1] + IT[id << 1 | 1]) % mod;
	tol_weight[id] = (tol_weight[id << 1] + tol_weight[id << 1 | 1]) % mod;
	laz[id] = 0; 
}

void lazy(int id){
	if(!laz[id]) return;
	IT[id << 1] = (tol_weight[id << 1] - IT[id << 1] + mod) % mod;
	IT[id << 1 | 1] = (tol_weight[id << 1 | 1] - IT[id << 1 | 1] + mod) % mod;
	laz[id << 1] ^= 1;
	laz[id << 1 | 1] ^= 1; 
	laz[id] = 0;
}

void upd(int id, int l, int r, int L, int R){
	if(l > R || r < L) return;
	if(l >= L && r <= R){
		IT[id] = (tol_weight[id] - IT[id] + mod) % mod;
		laz[id] ^= 1;
		return;
	}
	lazy(id);
	int mid = (l + r) >> 1;
	upd(id << 1, l, mid, L, R);
	upd(id << 1 | 1, mid + 1, r, L, R);
	IT[id] = (IT[id << 1] + IT[id << 1 | 1]) % mod;
}
 
void init(int N, int M, vector<int> P, vector<int> A){
	n = N, m = M;
	for(int i = 1; i < n + m; i++) Adj[P[i]].pb(i);
	for(int i = 0; i < m; i++) arr[i] = A[i];
	for(int i = n; i < n + m; i++) coor[i] = 1;
	dfs(0);
	sav[0] = 1;
	//for(int i = 1; i < n + m; i++) cout << i << " " << sav[i] << "\n";
	dfs2(0, 1);
	build(1, 0, m - 1);
	//for(int i = 0; i < m; i++) cout << coor[0][i] << " ";
	//cout << "\n";
}
 
int count_ways(int L, int R){
	L -= n, R -= n;
	upd(1, 0, m - 1, L, R);
	long long temp = IT[1];
	int temp2 = temp;
	return temp2;
	/*
	for(int i = L; i <= R; i++) arr[i] ^= 1;
	long long ans = 0;
	for(int i = 0; i < m; i++) if(arr[i]) ans += coor[0][i];
    ans %= mod;
	int ans2 = ans;
	return ans2;*/
}

Compilation message

circuit.cpp:16:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   16 | const int oo = 1e18 + 7, mod = 1000002022;
      |                ~~~~~^~~
circuit.cpp: In function 'void dfs(int)':
circuit.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |  for(int i = 1; i < Adj[u].size(); i++) pref[i] = (pref[i - 1] * coor[Adj[u][i]]) % mod;
      |                 ~~^~~~~~~~~~~~~~~
circuit.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i = 0; i < Adj[u].size(); i++){
      |                 ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 4 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5200 KB Output is correct
9 Correct 3 ms 5200 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 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 4 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5200 KB Output is correct
17 Correct 3 ms 5200 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 4 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5200 KB Output is correct
25 Correct 4 ms 5200 KB Output is correct
26 Correct 4 ms 5132 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5072 KB Output is correct
32 Correct 3 ms 5200 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 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 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 488 ms 9720 KB Output is correct
2 Correct 975 ms 14484 KB Output is correct
3 Correct 932 ms 14536 KB Output is correct
4 Correct 768 ms 14456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 488 ms 9720 KB Output is correct
2 Correct 975 ms 14484 KB Output is correct
3 Correct 932 ms 14536 KB Output is correct
4 Correct 768 ms 14456 KB Output is correct
5 Correct 742 ms 9728 KB Output is correct
6 Correct 852 ms 14540 KB Output is correct
7 Correct 967 ms 14480 KB Output is correct
8 Correct 1031 ms 14456 KB Output is correct
9 Correct 481 ms 5328 KB Output is correct
10 Correct 805 ms 5584 KB Output is correct
11 Correct 891 ms 5584 KB Output is correct
12 Correct 1024 ms 5628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 4 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5200 KB Output is correct
9 Correct 3 ms 5200 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 488 ms 9720 KB Output is correct
14 Correct 975 ms 14484 KB Output is correct
15 Correct 932 ms 14536 KB Output is correct
16 Correct 768 ms 14456 KB Output is correct
17 Correct 742 ms 9728 KB Output is correct
18 Correct 852 ms 14540 KB Output is correct
19 Correct 967 ms 14480 KB Output is correct
20 Correct 1031 ms 14456 KB Output is correct
21 Correct 481 ms 5328 KB Output is correct
22 Correct 805 ms 5584 KB Output is correct
23 Correct 891 ms 5584 KB Output is correct
24 Correct 1024 ms 5628 KB Output is correct
25 Correct 1067 ms 20732 KB Output is correct
26 Correct 969 ms 20860 KB Output is correct
27 Correct 1037 ms 20860 KB Output is correct
28 Correct 861 ms 20860 KB Output is correct
29 Correct 1644 ms 27108 KB Output is correct
30 Correct 784 ms 27156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 4 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5200 KB Output is correct
17 Correct 3 ms 5200 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 4 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5200 KB Output is correct
25 Correct 4 ms 5200 KB Output is correct
26 Correct 4 ms 5132 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5072 KB Output is correct
32 Correct 3 ms 5200 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 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 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 594 ms 5456 KB Output is correct
44 Correct 772 ms 5456 KB Output is correct
45 Correct 961 ms 5500 KB Output is correct
46 Correct 786 ms 5840 KB Output is correct
47 Correct 910 ms 5840 KB Output is correct
48 Correct 900 ms 5840 KB Output is correct
49 Correct 1008 ms 5840 KB Output is correct
50 Correct 642 ms 5924 KB Output is correct
51 Correct 949 ms 5712 KB Output is correct
52 Correct 824 ms 5712 KB Output is correct
53 Correct 602 ms 5584 KB Output is correct
54 Correct 831 ms 5840 KB Output is correct
55 Correct 657 ms 5712 KB Output is correct
56 Correct 713 ms 5712 KB Output is correct
57 Correct 1031 ms 5584 KB Output is correct
58 Correct 1102 ms 6224 KB Output is correct
59 Correct 923 ms 6364 KB Output is correct
60 Correct 983 ms 6356 KB Output is correct
61 Correct 1090 ms 5540 KB Output is correct
62 Correct 897 ms 5456 KB Output is correct
63 Correct 1032 ms 5456 KB Output is correct
64 Correct 1060 ms 5584 KB Output is correct
65 Correct 509 ms 5328 KB Output is correct
66 Correct 1032 ms 5584 KB Output is correct
67 Correct 994 ms 5584 KB Output is correct
68 Correct 955 ms 5584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 4 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5200 KB Output is correct
17 Correct 3 ms 5200 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 4 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5200 KB Output is correct
25 Correct 4 ms 5200 KB Output is correct
26 Correct 4 ms 5132 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5072 KB Output is correct
32 Correct 3 ms 5200 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 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 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 488 ms 9720 KB Output is correct
44 Correct 975 ms 14484 KB Output is correct
45 Correct 932 ms 14536 KB Output is correct
46 Correct 768 ms 14456 KB Output is correct
47 Correct 742 ms 9728 KB Output is correct
48 Correct 852 ms 14540 KB Output is correct
49 Correct 967 ms 14480 KB Output is correct
50 Correct 1031 ms 14456 KB Output is correct
51 Correct 481 ms 5328 KB Output is correct
52 Correct 805 ms 5584 KB Output is correct
53 Correct 891 ms 5584 KB Output is correct
54 Correct 1024 ms 5628 KB Output is correct
55 Correct 1067 ms 20732 KB Output is correct
56 Correct 969 ms 20860 KB Output is correct
57 Correct 1037 ms 20860 KB Output is correct
58 Correct 861 ms 20860 KB Output is correct
59 Correct 1644 ms 27108 KB Output is correct
60 Correct 784 ms 27156 KB Output is correct
61 Correct 594 ms 5456 KB Output is correct
62 Correct 772 ms 5456 KB Output is correct
63 Correct 961 ms 5500 KB Output is correct
64 Correct 786 ms 5840 KB Output is correct
65 Correct 910 ms 5840 KB Output is correct
66 Correct 900 ms 5840 KB Output is correct
67 Correct 1008 ms 5840 KB Output is correct
68 Correct 642 ms 5924 KB Output is correct
69 Correct 949 ms 5712 KB Output is correct
70 Correct 824 ms 5712 KB Output is correct
71 Correct 602 ms 5584 KB Output is correct
72 Correct 831 ms 5840 KB Output is correct
73 Correct 657 ms 5712 KB Output is correct
74 Correct 713 ms 5712 KB Output is correct
75 Correct 1031 ms 5584 KB Output is correct
76 Correct 1102 ms 6224 KB Output is correct
77 Correct 923 ms 6364 KB Output is correct
78 Correct 983 ms 6356 KB Output is correct
79 Correct 1090 ms 5540 KB Output is correct
80 Correct 897 ms 5456 KB Output is correct
81 Correct 1032 ms 5456 KB Output is correct
82 Correct 1060 ms 5584 KB Output is correct
83 Correct 509 ms 5328 KB Output is correct
84 Correct 1032 ms 5584 KB Output is correct
85 Correct 994 ms 5584 KB Output is correct
86 Correct 955 ms 5584 KB Output is correct
87 Correct 3 ms 4944 KB Output is correct
88 Correct 740 ms 19828 KB Output is correct
89 Correct 1084 ms 14484 KB Output is correct
90 Correct 1071 ms 14200 KB Output is correct
91 Correct 1040 ms 21064 KB Output is correct
92 Correct 924 ms 21064 KB Output is correct
93 Correct 1192 ms 20992 KB Output is correct
94 Correct 1208 ms 21016 KB Output is correct
95 Correct 836 ms 20988 KB Output is correct
96 Correct 925 ms 17552 KB Output is correct
97 Correct 920 ms 17548 KB Output is correct
98 Correct 694 ms 16712 KB Output is correct
99 Correct 568 ms 21064 KB Output is correct
100 Correct 878 ms 18168 KB Output is correct
101 Correct 984 ms 17272 KB Output is correct
102 Correct 826 ms 15996 KB Output is correct
103 Correct 910 ms 27128 KB Output is correct
104 Correct 1008 ms 29260 KB Output is correct
105 Correct 947 ms 29256 KB Output is correct
106 Correct 1025 ms 15432 KB Output is correct
107 Correct 1064 ms 16200 KB Output is correct
108 Correct 1033 ms 16192 KB Output is correct
109 Correct 824 ms 16072 KB Output is correct