Submission #837272

# Submission time Handle Problem Language Result Execution time Memory
837272 2023-08-25T08:55:03 Z ymm Digital Circuit (IOI22_circuit) C++17
46 / 100
3000 ms 7888 KB
#include "circuit.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < ll(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= ll(l); --x)
typedef long long ll;
using namespace std;

const int mod = 1'000'002'022;
const int N = 200'010;
vector<int> A[N];
ll kol[N];
ll val[N];

void dfskol(int v)
{
	if (A[v].empty()) {
		kol[v] = 1;
		return;
	}
	kol[v] = A[v].size();
	for (int u : A[v]) {
		dfskol(u);
		kol[v] = kol[v] * kol[u] % mod;
	}
}
void dfsval(int v, ll val)
{
	if (A[v].empty()) {
		::val[v] = val;
		return;
	}
	vector<ll> vec;
	for (int u : A[v])
		vec.push_back(kol[u]);
	vector<ll> pre = {1}, suf = {1};
	Loop (i,0,vec.size()-1)
		pre.push_back(pre.back() * vec[i] % mod);
	LoopR (i,1,vec.size())
		suf.push_back(suf.back() * vec[i] % mod);
	reverse(suf.begin(), suf.end());
	Loop (i,0,A[v].size())
		dfsval(A[v][i], val * pre[i] % mod * suf[i] % mod);
}

namespace seg {
	ll val[N];
	bool state[N];
	int st, fi;

	void init(int l, int r, ll *v, int *s) {
		st = l;
		fi = r;
		Loop (i,st,fi) {
			val[i] = v[i];
			state[i] = s[i];
		}
	}

	void up(int l, int r) {
		Loop (i,l,r)
			state[i] = !state[i];
	}
	ll get() {
		ll ans = 0;
		Loop (i,st,fi) {
			ans += state[i]? val[i]: 0;
			ans %= mod;
		}
		return ans;
	}
}
	

void init(int n, int m, std::vector<int> P, std::vector<int> A) {
	Loop (i,1,n+m)
		::A[P[i]].push_back(i);
	dfskol(0);
	dfsval(0, 1);
	seg::init(n, n+m, val, A.data() - n);
}

int count_ways(int L, int R) {
	seg::up(L, R+1);
	return seg::get();
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 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 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 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 4944 KB Output is correct
3 Correct 3 ms 4964 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 3 ms 4944 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 5072 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 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 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 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4964 KB Output is correct
12 Correct 2 ms 4944 KB Output is correct
13 Correct 3 ms 4944 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 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 2 ms 4944 KB Output is correct
24 Correct 3 ms 5120 KB Output is correct
25 Correct 3 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 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5328 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 2 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 3 ms 5328 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 4944 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3095 ms 7888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3095 ms 7888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4964 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 3 ms 4944 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 5072 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Execution timed out 3095 ms 7888 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 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 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4964 KB Output is correct
12 Correct 2 ms 4944 KB Output is correct
13 Correct 3 ms 4944 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 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 2 ms 4944 KB Output is correct
24 Correct 3 ms 5120 KB Output is correct
25 Correct 3 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 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5328 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 2 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 3 ms 5328 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 4944 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 1194 ms 5200 KB Output is correct
44 Correct 1607 ms 5200 KB Output is correct
45 Correct 1407 ms 5200 KB Output is correct
46 Correct 2037 ms 5456 KB Output is correct
47 Correct 2345 ms 5456 KB Output is correct
48 Correct 2407 ms 5456 KB Output is correct
49 Correct 2332 ms 5456 KB Output is correct
50 Correct 2573 ms 5456 KB Output is correct
51 Correct 2543 ms 5420 KB Output is correct
52 Correct 2294 ms 5356 KB Output is correct
53 Correct 440 ms 6608 KB Output is correct
54 Correct 2331 ms 5456 KB Output is correct
55 Correct 2678 ms 5328 KB Output is correct
56 Correct 2434 ms 5264 KB Output is correct
57 Correct 2431 ms 5200 KB Output is correct
58 Correct 2303 ms 6736 KB Output is correct
59 Correct 2193 ms 6992 KB Output is correct
60 Correct 2610 ms 7012 KB Output is correct
61 Correct 1519 ms 5584 KB Output is correct
62 Correct 1860 ms 5200 KB Output is correct
63 Correct 2068 ms 5200 KB Output is correct
64 Correct 2474 ms 5200 KB Output is correct
65 Correct 759 ms 5072 KB Output is correct
66 Correct 2143 ms 5348 KB Output is correct
67 Correct 2051 ms 5328 KB Output is correct
68 Correct 1967 ms 5328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 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 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4964 KB Output is correct
12 Correct 2 ms 4944 KB Output is correct
13 Correct 3 ms 4944 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 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 2 ms 4944 KB Output is correct
24 Correct 3 ms 5120 KB Output is correct
25 Correct 3 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 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5328 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 2 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 3 ms 5328 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 4944 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Execution timed out 3095 ms 7888 KB Time limit exceeded
44 Halted 0 ms 0 KB -