Submission #837275

# Submission time Handle Problem Language Result Execution time Memory
837275 2023-08-25T09:02:14 Z ymm Digital Circuit (IOI22_circuit) C++17
100 / 100
904 ms 47656 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 {
	struct node {
		ll sum, sumr;
		bool swp;
	} t[4*N];
	int st, fi;

	void tag(int i) {
		swap(t[i].sum, t[i].sumr);
		t[i].swp ^= 1;
	}
	void ppg(int i) {
		if (t[i].swp) {
			tag(2*i+1);
			tag(2*i+2);
			t[i].swp = 0;
		}
	}
	void merge(int i) {
		t[i].sum = (t[2*i+1].sum + t[2*i+2].sum) % mod;
		t[i].sumr = (t[2*i+1].sumr + t[2*i+2].sumr) % mod;
	}

	void up(int l, int r, int i, int b, int e) {
		if (l <= b && e <= r)
			return tag(i);
		if (r <= b || e <= l)
			return;
		ppg(i);
		up(l, r, 2*i+1, b, (b+e)/2);
		up(l, r, 2*i+2, (b+e)/2, e);
		merge(i);
	}
	void up(int l, int r) { up(l, r, 0, st, fi); }

	void init(ll *v, int *s, int i, int b, int e) {
		if (e-b == 1) {
			t[i].sum = 0;
			t[i].sumr = v[b];
			if (s[b])
				swap(t[i].sum, t[i].sumr);
			return;
		}
		init(v, s, 2*i+1, b, (b+e)/2);
		init(v, s, 2*i+2, (b+e)/2, e);
		merge(i);
	}
	void init(int l, int r, ll *v, int *s) {
		st = l;
		fi = r;
		init(v, s, 0, st, fi);
	}

	ll get() { return t[0].sum; }
}
	

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 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 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 2 ms 4972 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 3 ms 5060 KB Output is correct
6 Correct 2 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 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 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 2 ms 4972 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 2 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 3 ms 5060 KB Output is correct
14 Correct 2 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 2 ms 5072 KB Output is correct
23 Correct 2 ms 5000 KB Output is correct
24 Correct 3 ms 5072 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 2 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 5452 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 2 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 511 ms 9080 KB Output is correct
2 Correct 688 ms 13276 KB Output is correct
3 Correct 764 ms 13128 KB Output is correct
4 Correct 685 ms 13180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 511 ms 9080 KB Output is correct
2 Correct 688 ms 13276 KB Output is correct
3 Correct 764 ms 13128 KB Output is correct
4 Correct 685 ms 13180 KB Output is correct
5 Correct 579 ms 9040 KB Output is correct
6 Correct 783 ms 13128 KB Output is correct
7 Correct 796 ms 13200 KB Output is correct
8 Correct 632 ms 13128 KB Output is correct
9 Correct 361 ms 5200 KB Output is correct
10 Correct 701 ms 5456 KB Output is correct
11 Correct 544 ms 5456 KB Output is correct
12 Correct 729 ms 5456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4972 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 3 ms 5060 KB Output is correct
6 Correct 2 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 Correct 511 ms 9080 KB Output is correct
14 Correct 688 ms 13276 KB Output is correct
15 Correct 764 ms 13128 KB Output is correct
16 Correct 685 ms 13180 KB Output is correct
17 Correct 579 ms 9040 KB Output is correct
18 Correct 783 ms 13128 KB Output is correct
19 Correct 796 ms 13200 KB Output is correct
20 Correct 632 ms 13128 KB Output is correct
21 Correct 361 ms 5200 KB Output is correct
22 Correct 701 ms 5456 KB Output is correct
23 Correct 544 ms 5456 KB Output is correct
24 Correct 729 ms 5456 KB Output is correct
25 Correct 904 ms 18796 KB Output is correct
26 Correct 821 ms 18968 KB Output is correct
27 Correct 588 ms 19068 KB Output is correct
28 Correct 545 ms 18968 KB Output is correct
29 Correct 733 ms 47124 KB Output is correct
30 Correct 820 ms 47048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 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 2 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 2 ms 4972 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 2 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 3 ms 5060 KB Output is correct
14 Correct 2 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 2 ms 5072 KB Output is correct
23 Correct 2 ms 5000 KB Output is correct
24 Correct 3 ms 5072 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 2 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 5452 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 2 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 431 ms 5328 KB Output is correct
44 Correct 707 ms 5456 KB Output is correct
45 Correct 631 ms 5328 KB Output is correct
46 Correct 681 ms 5712 KB Output is correct
47 Correct 751 ms 5712 KB Output is correct
48 Correct 646 ms 5692 KB Output is correct
49 Correct 650 ms 5712 KB Output is correct
50 Correct 614 ms 5712 KB Output is correct
51 Correct 438 ms 5688 KB Output is correct
52 Correct 670 ms 5692 KB Output is correct
53 Correct 508 ms 6608 KB Output is correct
54 Correct 631 ms 5712 KB Output is correct
55 Correct 689 ms 5556 KB Output is correct
56 Correct 537 ms 5584 KB Output is correct
57 Correct 641 ms 5584 KB Output is correct
58 Correct 559 ms 7112 KB Output is correct
59 Correct 667 ms 7264 KB Output is correct
60 Correct 574 ms 7260 KB Output is correct
61 Correct 557 ms 5712 KB Output is correct
62 Correct 578 ms 5328 KB Output is correct
63 Correct 633 ms 5328 KB Output is correct
64 Correct 582 ms 5584 KB Output is correct
65 Correct 307 ms 5200 KB Output is correct
66 Correct 587 ms 5456 KB Output is correct
67 Correct 644 ms 5456 KB Output is correct
68 Correct 581 ms 5456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 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 2 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 2 ms 4972 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 2 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 3 ms 5060 KB Output is correct
14 Correct 2 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 2 ms 5072 KB Output is correct
23 Correct 2 ms 5000 KB Output is correct
24 Correct 3 ms 5072 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 2 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 5452 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 2 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 511 ms 9080 KB Output is correct
44 Correct 688 ms 13276 KB Output is correct
45 Correct 764 ms 13128 KB Output is correct
46 Correct 685 ms 13180 KB Output is correct
47 Correct 579 ms 9040 KB Output is correct
48 Correct 783 ms 13128 KB Output is correct
49 Correct 796 ms 13200 KB Output is correct
50 Correct 632 ms 13128 KB Output is correct
51 Correct 361 ms 5200 KB Output is correct
52 Correct 701 ms 5456 KB Output is correct
53 Correct 544 ms 5456 KB Output is correct
54 Correct 729 ms 5456 KB Output is correct
55 Correct 904 ms 18796 KB Output is correct
56 Correct 821 ms 18968 KB Output is correct
57 Correct 588 ms 19068 KB Output is correct
58 Correct 545 ms 18968 KB Output is correct
59 Correct 733 ms 47124 KB Output is correct
60 Correct 820 ms 47048 KB Output is correct
61 Correct 431 ms 5328 KB Output is correct
62 Correct 707 ms 5456 KB Output is correct
63 Correct 631 ms 5328 KB Output is correct
64 Correct 681 ms 5712 KB Output is correct
65 Correct 751 ms 5712 KB Output is correct
66 Correct 646 ms 5692 KB Output is correct
67 Correct 650 ms 5712 KB Output is correct
68 Correct 614 ms 5712 KB Output is correct
69 Correct 438 ms 5688 KB Output is correct
70 Correct 670 ms 5692 KB Output is correct
71 Correct 508 ms 6608 KB Output is correct
72 Correct 631 ms 5712 KB Output is correct
73 Correct 689 ms 5556 KB Output is correct
74 Correct 537 ms 5584 KB Output is correct
75 Correct 641 ms 5584 KB Output is correct
76 Correct 559 ms 7112 KB Output is correct
77 Correct 667 ms 7264 KB Output is correct
78 Correct 574 ms 7260 KB Output is correct
79 Correct 557 ms 5712 KB Output is correct
80 Correct 578 ms 5328 KB Output is correct
81 Correct 633 ms 5328 KB Output is correct
82 Correct 582 ms 5584 KB Output is correct
83 Correct 307 ms 5200 KB Output is correct
84 Correct 587 ms 5456 KB Output is correct
85 Correct 644 ms 5456 KB Output is correct
86 Correct 581 ms 5456 KB Output is correct
87 Correct 2 ms 4944 KB Output is correct
88 Correct 466 ms 18172 KB Output is correct
89 Correct 688 ms 13304 KB Output is correct
90 Correct 666 ms 13052 KB Output is correct
91 Correct 440 ms 19072 KB Output is correct
92 Correct 773 ms 19088 KB Output is correct
93 Correct 705 ms 19072 KB Output is correct
94 Correct 739 ms 18976 KB Output is correct
95 Correct 648 ms 19072 KB Output is correct
96 Correct 598 ms 14720 KB Output is correct
97 Correct 659 ms 14692 KB Output is correct
98 Correct 636 ms 37876 KB Output is correct
99 Correct 808 ms 18972 KB Output is correct
100 Correct 720 ms 16616 KB Output is correct
101 Correct 669 ms 15932 KB Output is correct
102 Correct 654 ms 14756 KB Output is correct
103 Correct 628 ms 47132 KB Output is correct
104 Correct 644 ms 47600 KB Output is correct
105 Correct 648 ms 47656 KB Output is correct
106 Correct 637 ms 19316 KB Output is correct
107 Correct 724 ms 15152 KB Output is correct
108 Correct 762 ms 15112 KB Output is correct
109 Correct 796 ms 14976 KB Output is correct