Submission #544679

# Submission time Handle Problem Language Result Execution time Memory
544679 2022-04-02T14:21:26 Z blue Sprinkler (JOI22_sprinkler) C++17
100 / 100
2138 ms 97472 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define sz(x) int(x.size())

const int mx = 200'000;
const int lg = 19;

const int maxD = 40;

int N;
ll L;
vll H(1+mx);

vi edge[1+mx];

vi depth(1+mx, 1);
vi par(1+mx, 1);

ll mul(ll a, ll b)
{
	return (a*b)%L;
}

void dfs(int u, int p)
{
	par[u] = p;
	for(int v : edge[u])
	{
		if(v == p) continue;
		depth[v] = depth[u] + 1;
		dfs(v, u);
	}
}

vvll prop(1+mx, vll(1+maxD, 1)); //propagate this value in prop[u][d] at depth = depth[u]+d




int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> N >> L;

	for(int e = 1; e <= N-1; e++)
	{
		int a, b;
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	for(int i = 1; i <= N; i++) cin >> H[i];

	dfs(1, 0);

	
	int Q;
	cin >> Q;

	for(int q = 1; q <= Q; q++)
	{
		int t;
		cin >> t;

		if(t == 1)
		{
			int x, d;
			ll w;
			cin >> x >> d >> w;

			int y = x;

			for(int z = 0; z <= d; z++) //assign every level to the HIGHEST ancestor that can handle it.
			{
				if(y == 0) break;

				if(z >= 1)
					y = par[y];

				int dlo = depth[y];

				int dhi = depth[y] + (d - (depth[x] - depth[y]));

				if(z < d && y != 1)
					dlo = max(dlo, (depth[y]-1) + d - (depth[x] - (depth[y]-1)) + 1);

				dlo -= depth[y];
				dhi -= depth[y];

				for(int v = dlo; v <= dhi; v++)
					prop[y][v] = mul(prop[y][v], w);
			}
		}
		else
		{
			int x;
			cin >> x;
			ll res = H[x];
			for(int y = x; y != 0 && depth[x] - depth[y] <= 40; y = par[y])
				res = mul(res, prop[y][depth[x] - depth[y]]);

			cout << res << '\n';
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 97 ms 78656 KB Output is correct
2 Correct 93 ms 78548 KB Output is correct
3 Correct 89 ms 78484 KB Output is correct
4 Correct 91 ms 78540 KB Output is correct
5 Correct 99 ms 78556 KB Output is correct
6 Correct 92 ms 78564 KB Output is correct
7 Correct 91 ms 78548 KB Output is correct
8 Correct 93 ms 78568 KB Output is correct
9 Correct 96 ms 78580 KB Output is correct
10 Correct 93 ms 78560 KB Output is correct
11 Correct 90 ms 78508 KB Output is correct
12 Correct 91 ms 78612 KB Output is correct
13 Correct 93 ms 78544 KB Output is correct
14 Correct 91 ms 78688 KB Output is correct
15 Correct 90 ms 78524 KB Output is correct
16 Correct 91 ms 78540 KB Output is correct
17 Correct 93 ms 78608 KB Output is correct
18 Correct 91 ms 78532 KB Output is correct
19 Correct 93 ms 78508 KB Output is correct
20 Correct 92 ms 78540 KB Output is correct
21 Correct 92 ms 78568 KB Output is correct
22 Correct 97 ms 78668 KB Output is correct
23 Correct 95 ms 78560 KB Output is correct
24 Correct 91 ms 78576 KB Output is correct
25 Correct 102 ms 78588 KB Output is correct
26 Correct 94 ms 78588 KB Output is correct
27 Correct 100 ms 78656 KB Output is correct
28 Correct 100 ms 78492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 78484 KB Output is correct
2 Correct 870 ms 88504 KB Output is correct
3 Correct 537 ms 85372 KB Output is correct
4 Correct 936 ms 92840 KB Output is correct
5 Correct 704 ms 86908 KB Output is correct
6 Correct 543 ms 88020 KB Output is correct
7 Correct 445 ms 87192 KB Output is correct
8 Correct 375 ms 87616 KB Output is correct
9 Correct 793 ms 97472 KB Output is correct
10 Correct 480 ms 93516 KB Output is correct
11 Correct 732 ms 88488 KB Output is correct
12 Correct 487 ms 85360 KB Output is correct
13 Correct 302 ms 85832 KB Output is correct
14 Correct 301 ms 85876 KB Output is correct
15 Correct 296 ms 85944 KB Output is correct
16 Correct 305 ms 85704 KB Output is correct
17 Correct 317 ms 86288 KB Output is correct
18 Correct 91 ms 78536 KB Output is correct
19 Correct 95 ms 78612 KB Output is correct
20 Correct 92 ms 78588 KB Output is correct
21 Correct 90 ms 78520 KB Output is correct
22 Correct 92 ms 78584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 78484 KB Output is correct
2 Correct 870 ms 88504 KB Output is correct
3 Correct 537 ms 85372 KB Output is correct
4 Correct 936 ms 92840 KB Output is correct
5 Correct 704 ms 86908 KB Output is correct
6 Correct 543 ms 88020 KB Output is correct
7 Correct 445 ms 87192 KB Output is correct
8 Correct 375 ms 87616 KB Output is correct
9 Correct 793 ms 97472 KB Output is correct
10 Correct 480 ms 93516 KB Output is correct
11 Correct 732 ms 88488 KB Output is correct
12 Correct 487 ms 85360 KB Output is correct
13 Correct 302 ms 85832 KB Output is correct
14 Correct 301 ms 85876 KB Output is correct
15 Correct 296 ms 85944 KB Output is correct
16 Correct 305 ms 85704 KB Output is correct
17 Correct 317 ms 86288 KB Output is correct
18 Correct 91 ms 78536 KB Output is correct
19 Correct 95 ms 78612 KB Output is correct
20 Correct 92 ms 78588 KB Output is correct
21 Correct 90 ms 78520 KB Output is correct
22 Correct 92 ms 78584 KB Output is correct
23 Correct 90 ms 78596 KB Output is correct
24 Correct 733 ms 88420 KB Output is correct
25 Correct 569 ms 85532 KB Output is correct
26 Correct 753 ms 95648 KB Output is correct
27 Correct 576 ms 86988 KB Output is correct
28 Correct 450 ms 87036 KB Output is correct
29 Correct 417 ms 87116 KB Output is correct
30 Correct 347 ms 87684 KB Output is correct
31 Correct 745 ms 94812 KB Output is correct
32 Correct 580 ms 93648 KB Output is correct
33 Correct 872 ms 88520 KB Output is correct
34 Correct 579 ms 85324 KB Output is correct
35 Correct 108 ms 78564 KB Output is correct
36 Correct 103 ms 78480 KB Output is correct
37 Correct 101 ms 78540 KB Output is correct
38 Correct 104 ms 78592 KB Output is correct
39 Correct 100 ms 78540 KB Output is correct
40 Correct 90 ms 78544 KB Output is correct
41 Correct 95 ms 78640 KB Output is correct
42 Correct 99 ms 78516 KB Output is correct
43 Correct 97 ms 78520 KB Output is correct
44 Correct 96 ms 78552 KB Output is correct
45 Correct 100 ms 78504 KB Output is correct
46 Correct 112 ms 78588 KB Output is correct
47 Correct 106 ms 78604 KB Output is correct
48 Correct 96 ms 78600 KB Output is correct
49 Correct 115 ms 78556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 78508 KB Output is correct
2 Correct 988 ms 94676 KB Output is correct
3 Correct 1746 ms 91864 KB Output is correct
4 Correct 1004 ms 92516 KB Output is correct
5 Correct 843 ms 85432 KB Output is correct
6 Correct 502 ms 85452 KB Output is correct
7 Correct 468 ms 85520 KB Output is correct
8 Correct 355 ms 86056 KB Output is correct
9 Correct 940 ms 92056 KB Output is correct
10 Correct 1763 ms 93268 KB Output is correct
11 Correct 841 ms 85604 KB Output is correct
12 Correct 1350 ms 85256 KB Output is correct
13 Correct 810 ms 86284 KB Output is correct
14 Correct 868 ms 86476 KB Output is correct
15 Correct 92 ms 78608 KB Output is correct
16 Correct 102 ms 78584 KB Output is correct
17 Correct 96 ms 78704 KB Output is correct
18 Correct 93 ms 78608 KB Output is correct
19 Correct 98 ms 78580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 78496 KB Output is correct
2 Correct 951 ms 94372 KB Output is correct
3 Correct 1859 ms 89952 KB Output is correct
4 Correct 981 ms 92368 KB Output is correct
5 Correct 1012 ms 86988 KB Output is correct
6 Correct 586 ms 87032 KB Output is correct
7 Correct 563 ms 86900 KB Output is correct
8 Correct 461 ms 87400 KB Output is correct
9 Correct 1335 ms 96764 KB Output is correct
10 Correct 1946 ms 93716 KB Output is correct
11 Correct 823 ms 88444 KB Output is correct
12 Correct 1322 ms 85568 KB Output is correct
13 Correct 819 ms 86128 KB Output is correct
14 Correct 877 ms 86628 KB Output is correct
15 Correct 93 ms 78492 KB Output is correct
16 Correct 92 ms 78588 KB Output is correct
17 Correct 92 ms 78596 KB Output is correct
18 Correct 95 ms 78540 KB Output is correct
19 Correct 93 ms 78512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 78656 KB Output is correct
2 Correct 93 ms 78548 KB Output is correct
3 Correct 89 ms 78484 KB Output is correct
4 Correct 91 ms 78540 KB Output is correct
5 Correct 99 ms 78556 KB Output is correct
6 Correct 92 ms 78564 KB Output is correct
7 Correct 91 ms 78548 KB Output is correct
8 Correct 93 ms 78568 KB Output is correct
9 Correct 96 ms 78580 KB Output is correct
10 Correct 93 ms 78560 KB Output is correct
11 Correct 90 ms 78508 KB Output is correct
12 Correct 91 ms 78612 KB Output is correct
13 Correct 93 ms 78544 KB Output is correct
14 Correct 91 ms 78688 KB Output is correct
15 Correct 90 ms 78524 KB Output is correct
16 Correct 91 ms 78540 KB Output is correct
17 Correct 93 ms 78608 KB Output is correct
18 Correct 91 ms 78532 KB Output is correct
19 Correct 93 ms 78508 KB Output is correct
20 Correct 92 ms 78540 KB Output is correct
21 Correct 92 ms 78568 KB Output is correct
22 Correct 97 ms 78668 KB Output is correct
23 Correct 95 ms 78560 KB Output is correct
24 Correct 91 ms 78576 KB Output is correct
25 Correct 102 ms 78588 KB Output is correct
26 Correct 94 ms 78588 KB Output is correct
27 Correct 100 ms 78656 KB Output is correct
28 Correct 100 ms 78492 KB Output is correct
29 Correct 98 ms 78484 KB Output is correct
30 Correct 870 ms 88504 KB Output is correct
31 Correct 537 ms 85372 KB Output is correct
32 Correct 936 ms 92840 KB Output is correct
33 Correct 704 ms 86908 KB Output is correct
34 Correct 543 ms 88020 KB Output is correct
35 Correct 445 ms 87192 KB Output is correct
36 Correct 375 ms 87616 KB Output is correct
37 Correct 793 ms 97472 KB Output is correct
38 Correct 480 ms 93516 KB Output is correct
39 Correct 732 ms 88488 KB Output is correct
40 Correct 487 ms 85360 KB Output is correct
41 Correct 302 ms 85832 KB Output is correct
42 Correct 301 ms 85876 KB Output is correct
43 Correct 296 ms 85944 KB Output is correct
44 Correct 305 ms 85704 KB Output is correct
45 Correct 317 ms 86288 KB Output is correct
46 Correct 91 ms 78536 KB Output is correct
47 Correct 95 ms 78612 KB Output is correct
48 Correct 92 ms 78588 KB Output is correct
49 Correct 90 ms 78520 KB Output is correct
50 Correct 92 ms 78584 KB Output is correct
51 Correct 90 ms 78596 KB Output is correct
52 Correct 733 ms 88420 KB Output is correct
53 Correct 569 ms 85532 KB Output is correct
54 Correct 753 ms 95648 KB Output is correct
55 Correct 576 ms 86988 KB Output is correct
56 Correct 450 ms 87036 KB Output is correct
57 Correct 417 ms 87116 KB Output is correct
58 Correct 347 ms 87684 KB Output is correct
59 Correct 745 ms 94812 KB Output is correct
60 Correct 580 ms 93648 KB Output is correct
61 Correct 872 ms 88520 KB Output is correct
62 Correct 579 ms 85324 KB Output is correct
63 Correct 108 ms 78564 KB Output is correct
64 Correct 103 ms 78480 KB Output is correct
65 Correct 101 ms 78540 KB Output is correct
66 Correct 104 ms 78592 KB Output is correct
67 Correct 100 ms 78540 KB Output is correct
68 Correct 90 ms 78544 KB Output is correct
69 Correct 95 ms 78640 KB Output is correct
70 Correct 99 ms 78516 KB Output is correct
71 Correct 97 ms 78520 KB Output is correct
72 Correct 96 ms 78552 KB Output is correct
73 Correct 100 ms 78504 KB Output is correct
74 Correct 112 ms 78588 KB Output is correct
75 Correct 106 ms 78604 KB Output is correct
76 Correct 96 ms 78600 KB Output is correct
77 Correct 115 ms 78556 KB Output is correct
78 Correct 100 ms 78508 KB Output is correct
79 Correct 988 ms 94676 KB Output is correct
80 Correct 1746 ms 91864 KB Output is correct
81 Correct 1004 ms 92516 KB Output is correct
82 Correct 843 ms 85432 KB Output is correct
83 Correct 502 ms 85452 KB Output is correct
84 Correct 468 ms 85520 KB Output is correct
85 Correct 355 ms 86056 KB Output is correct
86 Correct 940 ms 92056 KB Output is correct
87 Correct 1763 ms 93268 KB Output is correct
88 Correct 841 ms 85604 KB Output is correct
89 Correct 1350 ms 85256 KB Output is correct
90 Correct 810 ms 86284 KB Output is correct
91 Correct 868 ms 86476 KB Output is correct
92 Correct 92 ms 78608 KB Output is correct
93 Correct 102 ms 78584 KB Output is correct
94 Correct 96 ms 78704 KB Output is correct
95 Correct 93 ms 78608 KB Output is correct
96 Correct 98 ms 78580 KB Output is correct
97 Correct 92 ms 78496 KB Output is correct
98 Correct 951 ms 94372 KB Output is correct
99 Correct 1859 ms 89952 KB Output is correct
100 Correct 981 ms 92368 KB Output is correct
101 Correct 1012 ms 86988 KB Output is correct
102 Correct 586 ms 87032 KB Output is correct
103 Correct 563 ms 86900 KB Output is correct
104 Correct 461 ms 87400 KB Output is correct
105 Correct 1335 ms 96764 KB Output is correct
106 Correct 1946 ms 93716 KB Output is correct
107 Correct 823 ms 88444 KB Output is correct
108 Correct 1322 ms 85568 KB Output is correct
109 Correct 819 ms 86128 KB Output is correct
110 Correct 877 ms 86628 KB Output is correct
111 Correct 93 ms 78492 KB Output is correct
112 Correct 92 ms 78588 KB Output is correct
113 Correct 92 ms 78596 KB Output is correct
114 Correct 95 ms 78540 KB Output is correct
115 Correct 93 ms 78512 KB Output is correct
116 Correct 883 ms 86492 KB Output is correct
117 Correct 1372 ms 85188 KB Output is correct
118 Correct 1018 ms 95560 KB Output is correct
119 Correct 875 ms 86876 KB Output is correct
120 Correct 571 ms 86904 KB Output is correct
121 Correct 524 ms 87116 KB Output is correct
122 Correct 389 ms 87548 KB Output is correct
123 Correct 1045 ms 95604 KB Output is correct
124 Correct 2138 ms 90836 KB Output is correct
125 Correct 978 ms 87880 KB Output is correct
126 Correct 1785 ms 85124 KB Output is correct
127 Correct 1629 ms 85288 KB Output is correct
128 Correct 926 ms 86112 KB Output is correct
129 Correct 967 ms 86472 KB Output is correct