Submission #637992

# Submission time Handle Problem Language Result Execution time Memory
637992 2022-09-04T03:35:44 Z LittleCube Sprinkler (JOI22_sprinkler) C++14
100 / 100
757 ms 87816 KB
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

ll N, Q, L, pre[200050], h[200055], mul[200055][41];
vector<int> E[200050];

void dfs(int u)
{
	for(int v : E[u])
		if(pre[u] != v)
		{
			pre[v] = u;
			dfs(v);
		}
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> N >> L;
	for(int i = 1; i <= N - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		E[u].emplace_back(v);
		E[v].emplace_back(u);
	}
	for(int i = 1; i <= 40; i++)
		E[N + i].emplace_back(N + i - 1);
	dfs(N + 40);
	for(int i = 1; i <= N; i++)
		cin >> h[i];
	for(int i = 1; i <= N + 40; i++)
		for(int j = 0; j <= 40; j++)
			mul[i][j] = 1;
	cin >> Q;
	while(Q--)
	{
		ll T, X, D, W;
		cin >> T;
		if(T == 1)
		{
			cin >> X >> D >> W;
			for(int i = D; i >= 0; i--)
			{
				mul[X][i] = mul[X][i] * W % L;
				if(i)
					mul[X][i - 1] = mul[X][i - 1] * W % L;
				X = pre[X];
			}
		}
		else
		{
			cin >> X;
			ll ans = h[X];
			for(int i = 0; i <= 40; i++)
			{
				ans = ans * mul[X][i] % L;
				X = pre[X];
			}
			cout << ans << '\n';
		}
	}

}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5028 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5460 KB Output is correct
5 Correct 5 ms 5424 KB Output is correct
6 Correct 4 ms 5460 KB Output is correct
7 Correct 4 ms 5460 KB Output is correct
8 Correct 4 ms 5460 KB Output is correct
9 Correct 4 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 3 ms 5000 KB Output is correct
15 Correct 4 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 5 ms 5028 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 4 ms 4984 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 5024 KB Output is correct
23 Correct 4 ms 4948 KB Output is correct
24 Correct 4 ms 5032 KB Output is correct
25 Correct 4 ms 5028 KB Output is correct
26 Correct 3 ms 5028 KB Output is correct
27 Correct 3 ms 5028 KB Output is correct
28 Correct 3 ms 5036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 639 ms 83856 KB Output is correct
3 Correct 410 ms 80964 KB Output is correct
4 Correct 555 ms 85532 KB Output is correct
5 Correct 584 ms 82632 KB Output is correct
6 Correct 357 ms 82536 KB Output is correct
7 Correct 356 ms 82764 KB Output is correct
8 Correct 308 ms 82908 KB Output is correct
9 Correct 709 ms 87004 KB Output is correct
10 Correct 384 ms 83980 KB Output is correct
11 Correct 635 ms 83764 KB Output is correct
12 Correct 374 ms 80004 KB Output is correct
13 Correct 271 ms 80692 KB Output is correct
14 Correct 251 ms 80712 KB Output is correct
15 Correct 229 ms 80776 KB Output is correct
16 Correct 236 ms 81000 KB Output is correct
17 Correct 248 ms 81144 KB Output is correct
18 Correct 3 ms 5040 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 639 ms 83856 KB Output is correct
3 Correct 410 ms 80964 KB Output is correct
4 Correct 555 ms 85532 KB Output is correct
5 Correct 584 ms 82632 KB Output is correct
6 Correct 357 ms 82536 KB Output is correct
7 Correct 356 ms 82764 KB Output is correct
8 Correct 308 ms 82908 KB Output is correct
9 Correct 709 ms 87004 KB Output is correct
10 Correct 384 ms 83980 KB Output is correct
11 Correct 635 ms 83764 KB Output is correct
12 Correct 374 ms 80004 KB Output is correct
13 Correct 271 ms 80692 KB Output is correct
14 Correct 251 ms 80712 KB Output is correct
15 Correct 229 ms 80776 KB Output is correct
16 Correct 236 ms 81000 KB Output is correct
17 Correct 248 ms 81144 KB Output is correct
18 Correct 3 ms 5040 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5024 KB Output is correct
24 Correct 601 ms 83308 KB Output is correct
25 Correct 420 ms 80132 KB Output is correct
26 Correct 541 ms 86600 KB Output is correct
27 Correct 495 ms 81660 KB Output is correct
28 Correct 364 ms 81808 KB Output is correct
29 Correct 347 ms 81860 KB Output is correct
30 Correct 327 ms 82468 KB Output is correct
31 Correct 718 ms 87816 KB Output is correct
32 Correct 376 ms 83148 KB Output is correct
33 Correct 657 ms 83156 KB Output is correct
34 Correct 384 ms 80080 KB Output is correct
35 Correct 4 ms 5072 KB Output is correct
36 Correct 3 ms 5036 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 4 ms 5076 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 3 ms 5032 KB Output is correct
42 Correct 4 ms 4948 KB Output is correct
43 Correct 3 ms 4960 KB Output is correct
44 Correct 3 ms 4948 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 3 ms 5028 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 3 ms 5032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 733 ms 84728 KB Output is correct
3 Correct 757 ms 84220 KB Output is correct
4 Correct 639 ms 85700 KB Output is correct
5 Correct 567 ms 80088 KB Output is correct
6 Correct 382 ms 80248 KB Output is correct
7 Correct 371 ms 80312 KB Output is correct
8 Correct 297 ms 80748 KB Output is correct
9 Correct 646 ms 83764 KB Output is correct
10 Correct 722 ms 84876 KB Output is correct
11 Correct 636 ms 80388 KB Output is correct
12 Correct 640 ms 79708 KB Output is correct
13 Correct 411 ms 80756 KB Output is correct
14 Correct 452 ms 81164 KB Output is correct
15 Correct 4 ms 5028 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 4 ms 5028 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5032 KB Output is correct
2 Correct 720 ms 87268 KB Output is correct
3 Correct 748 ms 82892 KB Output is correct
4 Correct 609 ms 85776 KB Output is correct
5 Correct 521 ms 81388 KB Output is correct
6 Correct 387 ms 81388 KB Output is correct
7 Correct 379 ms 81064 KB Output is correct
8 Correct 346 ms 81440 KB Output is correct
9 Correct 678 ms 87120 KB Output is correct
10 Correct 756 ms 83012 KB Output is correct
11 Correct 577 ms 82704 KB Output is correct
12 Correct 620 ms 79576 KB Output is correct
13 Correct 390 ms 80284 KB Output is correct
14 Correct 424 ms 80588 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 3 ms 5028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5028 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5460 KB Output is correct
5 Correct 5 ms 5424 KB Output is correct
6 Correct 4 ms 5460 KB Output is correct
7 Correct 4 ms 5460 KB Output is correct
8 Correct 4 ms 5460 KB Output is correct
9 Correct 4 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 3 ms 5000 KB Output is correct
15 Correct 4 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 5 ms 5028 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 4 ms 4984 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 5024 KB Output is correct
23 Correct 4 ms 4948 KB Output is correct
24 Correct 4 ms 5032 KB Output is correct
25 Correct 4 ms 5028 KB Output is correct
26 Correct 3 ms 5028 KB Output is correct
27 Correct 3 ms 5028 KB Output is correct
28 Correct 3 ms 5036 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 639 ms 83856 KB Output is correct
31 Correct 410 ms 80964 KB Output is correct
32 Correct 555 ms 85532 KB Output is correct
33 Correct 584 ms 82632 KB Output is correct
34 Correct 357 ms 82536 KB Output is correct
35 Correct 356 ms 82764 KB Output is correct
36 Correct 308 ms 82908 KB Output is correct
37 Correct 709 ms 87004 KB Output is correct
38 Correct 384 ms 83980 KB Output is correct
39 Correct 635 ms 83764 KB Output is correct
40 Correct 374 ms 80004 KB Output is correct
41 Correct 271 ms 80692 KB Output is correct
42 Correct 251 ms 80712 KB Output is correct
43 Correct 229 ms 80776 KB Output is correct
44 Correct 236 ms 81000 KB Output is correct
45 Correct 248 ms 81144 KB Output is correct
46 Correct 3 ms 5040 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 3 ms 5076 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5024 KB Output is correct
52 Correct 601 ms 83308 KB Output is correct
53 Correct 420 ms 80132 KB Output is correct
54 Correct 541 ms 86600 KB Output is correct
55 Correct 495 ms 81660 KB Output is correct
56 Correct 364 ms 81808 KB Output is correct
57 Correct 347 ms 81860 KB Output is correct
58 Correct 327 ms 82468 KB Output is correct
59 Correct 718 ms 87816 KB Output is correct
60 Correct 376 ms 83148 KB Output is correct
61 Correct 657 ms 83156 KB Output is correct
62 Correct 384 ms 80080 KB Output is correct
63 Correct 4 ms 5072 KB Output is correct
64 Correct 3 ms 5036 KB Output is correct
65 Correct 3 ms 5076 KB Output is correct
66 Correct 3 ms 5076 KB Output is correct
67 Correct 4 ms 5076 KB Output is correct
68 Correct 3 ms 4948 KB Output is correct
69 Correct 3 ms 5032 KB Output is correct
70 Correct 4 ms 4948 KB Output is correct
71 Correct 3 ms 4960 KB Output is correct
72 Correct 3 ms 4948 KB Output is correct
73 Correct 3 ms 5076 KB Output is correct
74 Correct 3 ms 5028 KB Output is correct
75 Correct 3 ms 5076 KB Output is correct
76 Correct 3 ms 5076 KB Output is correct
77 Correct 3 ms 5032 KB Output is correct
78 Correct 3 ms 4948 KB Output is correct
79 Correct 733 ms 84728 KB Output is correct
80 Correct 757 ms 84220 KB Output is correct
81 Correct 639 ms 85700 KB Output is correct
82 Correct 567 ms 80088 KB Output is correct
83 Correct 382 ms 80248 KB Output is correct
84 Correct 371 ms 80312 KB Output is correct
85 Correct 297 ms 80748 KB Output is correct
86 Correct 646 ms 83764 KB Output is correct
87 Correct 722 ms 84876 KB Output is correct
88 Correct 636 ms 80388 KB Output is correct
89 Correct 640 ms 79708 KB Output is correct
90 Correct 411 ms 80756 KB Output is correct
91 Correct 452 ms 81164 KB Output is correct
92 Correct 4 ms 5028 KB Output is correct
93 Correct 3 ms 5076 KB Output is correct
94 Correct 4 ms 5028 KB Output is correct
95 Correct 3 ms 4948 KB Output is correct
96 Correct 3 ms 4948 KB Output is correct
97 Correct 3 ms 5032 KB Output is correct
98 Correct 720 ms 87268 KB Output is correct
99 Correct 748 ms 82892 KB Output is correct
100 Correct 609 ms 85776 KB Output is correct
101 Correct 521 ms 81388 KB Output is correct
102 Correct 387 ms 81388 KB Output is correct
103 Correct 379 ms 81064 KB Output is correct
104 Correct 346 ms 81440 KB Output is correct
105 Correct 678 ms 87120 KB Output is correct
106 Correct 756 ms 83012 KB Output is correct
107 Correct 577 ms 82704 KB Output is correct
108 Correct 620 ms 79576 KB Output is correct
109 Correct 390 ms 80284 KB Output is correct
110 Correct 424 ms 80588 KB Output is correct
111 Correct 3 ms 4948 KB Output is correct
112 Correct 4 ms 4948 KB Output is correct
113 Correct 3 ms 4948 KB Output is correct
114 Correct 3 ms 5076 KB Output is correct
115 Correct 3 ms 5028 KB Output is correct
116 Correct 576 ms 80584 KB Output is correct
117 Correct 649 ms 79352 KB Output is correct
118 Correct 568 ms 85792 KB Output is correct
119 Correct 556 ms 80968 KB Output is correct
120 Correct 413 ms 80776 KB Output is correct
121 Correct 417 ms 81164 KB Output is correct
122 Correct 361 ms 81648 KB Output is correct
123 Correct 651 ms 85540 KB Output is correct
124 Correct 712 ms 82288 KB Output is correct
125 Correct 592 ms 81792 KB Output is correct
126 Correct 641 ms 79064 KB Output is correct
127 Correct 641 ms 78992 KB Output is correct
128 Correct 506 ms 80024 KB Output is correct
129 Correct 525 ms 80400 KB Output is correct