답안 #638659

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638659 2022-09-06T17:08:42 Z valerikk Sprinkler (JOI22_sprinkler) C++17
100 / 100
867 ms 98800 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e5 + 100;
const int D = 44;

int n;
ll L;
vector<int> g[N];
ll h[N];
int par[N];
ll a[N][D];

void dfs(int u, int p) {
	par[u] = p;
	for (int v : g[u]) {
		if (v != p) {
			dfs(v, u);
		}
	}
}

void upd(int v, int d, ll w) {
	for (int i = 0; i <= d; ++i, v = par[v]) {
		(a[v][d - i] *= w) %= L;
		if (v == n + D) break;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> L;
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for (int i = 0; i < n; ++i) {
		cin >> h[i];
	}
	for (int i = n; i < n + D; ++i) {
		g[i].push_back(i + 1);
		g[i + 1].push_back(i);
	}
	g[0].push_back(n);
	g[n].push_back(0);
	dfs(n + D, n + D);
	for (int i = 0; i <= n + D; ++i) {
		for (int j = 0; j < D; ++j) {
			a[i][j] = 1;
		}
	}
	int q;
	cin >> q;
	while (q--) {
		int t;
		cin >> t;
		if (t == 1) {
			int x, d;
			ll w;
			cin >> x >> d >> w;
			--x;
			upd(x, d, w); 
			upd(x, d - 1, w);
		}
		if (t == 2) {
			int v;
			cin >> v;
			--v;
			ll ans = h[v];
			for (int i = 0; i < D; ++i, v = par[v]) {
				(ans *= a[v][i]) %= L;
				if (v == n + D) break;
			}
			cout << ans << "\n";
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 4 ms 5460 KB Output is correct
5 Correct 4 ms 5460 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 5072 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 4 ms 5032 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5028 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 3 ms 5004 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5032 KB Output is correct
24 Correct 4 ms 5032 KB Output is correct
25 Correct 3 ms 5028 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 519 ms 86144 KB Output is correct
3 Correct 357 ms 94876 KB Output is correct
4 Correct 484 ms 97364 KB Output is correct
5 Correct 505 ms 94548 KB Output is correct
6 Correct 361 ms 94268 KB Output is correct
7 Correct 352 ms 94888 KB Output is correct
8 Correct 293 ms 95508 KB Output is correct
9 Correct 590 ms 98596 KB Output is correct
10 Correct 380 ms 98800 KB Output is correct
11 Correct 545 ms 94352 KB Output is correct
12 Correct 339 ms 94752 KB Output is correct
13 Correct 248 ms 95152 KB Output is correct
14 Correct 244 ms 95544 KB Output is correct
15 Correct 252 ms 94896 KB Output is correct
16 Correct 302 ms 95512 KB Output is correct
17 Correct 255 ms 95948 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 4 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 4 ms 5012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 519 ms 86144 KB Output is correct
3 Correct 357 ms 94876 KB Output is correct
4 Correct 484 ms 97364 KB Output is correct
5 Correct 505 ms 94548 KB Output is correct
6 Correct 361 ms 94268 KB Output is correct
7 Correct 352 ms 94888 KB Output is correct
8 Correct 293 ms 95508 KB Output is correct
9 Correct 590 ms 98596 KB Output is correct
10 Correct 380 ms 98800 KB Output is correct
11 Correct 545 ms 94352 KB Output is correct
12 Correct 339 ms 94752 KB Output is correct
13 Correct 248 ms 95152 KB Output is correct
14 Correct 244 ms 95544 KB Output is correct
15 Correct 252 ms 94896 KB Output is correct
16 Correct 302 ms 95512 KB Output is correct
17 Correct 255 ms 95948 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 4 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 4 ms 5012 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 542 ms 94388 KB Output is correct
25 Correct 379 ms 94912 KB Output is correct
26 Correct 535 ms 98696 KB Output is correct
27 Correct 458 ms 94676 KB Output is correct
28 Correct 430 ms 94736 KB Output is correct
29 Correct 397 ms 94384 KB Output is correct
30 Correct 331 ms 95456 KB Output is correct
31 Correct 597 ms 97332 KB Output is correct
32 Correct 411 ms 98756 KB Output is correct
33 Correct 587 ms 94256 KB Output is correct
34 Correct 386 ms 94792 KB Output is correct
35 Correct 4 ms 4948 KB Output is correct
36 Correct 4 ms 5032 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 4 ms 5176 KB Output is correct
39 Correct 4 ms 5116 KB Output is correct
40 Correct 4 ms 5008 KB Output is correct
41 Correct 3 ms 4948 KB Output is correct
42 Correct 3 ms 5032 KB Output is correct
43 Correct 4 ms 5028 KB Output is correct
44 Correct 5 ms 4948 KB Output is correct
45 Correct 4 ms 5032 KB Output is correct
46 Correct 5 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 4 ms 5032 KB Output is correct
49 Correct 4 ms 5036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 700 ms 87608 KB Output is correct
3 Correct 867 ms 85992 KB Output is correct
4 Correct 686 ms 86488 KB Output is correct
5 Correct 608 ms 82980 KB Output is correct
6 Correct 479 ms 83064 KB Output is correct
7 Correct 391 ms 83276 KB Output is correct
8 Correct 358 ms 83596 KB Output is correct
9 Correct 682 ms 86444 KB Output is correct
10 Correct 808 ms 86672 KB Output is correct
11 Correct 687 ms 83244 KB Output is correct
12 Correct 735 ms 82648 KB Output is correct
13 Correct 489 ms 83604 KB Output is correct
14 Correct 463 ms 83952 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 604 ms 88904 KB Output is correct
3 Correct 749 ms 85176 KB Output is correct
4 Correct 563 ms 95600 KB Output is correct
5 Correct 528 ms 93304 KB Output is correct
6 Correct 457 ms 93344 KB Output is correct
7 Correct 386 ms 93120 KB Output is correct
8 Correct 336 ms 93376 KB Output is correct
9 Correct 609 ms 98020 KB Output is correct
10 Correct 727 ms 96452 KB Output is correct
11 Correct 541 ms 93960 KB Output is correct
12 Correct 601 ms 92468 KB Output is correct
13 Correct 449 ms 93136 KB Output is correct
14 Correct 477 ms 93704 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 2 ms 5032 KB Output is correct
18 Correct 3 ms 5032 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 4 ms 5460 KB Output is correct
5 Correct 4 ms 5460 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 5072 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 4 ms 5032 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5028 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 3 ms 5004 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5032 KB Output is correct
24 Correct 4 ms 5032 KB Output is correct
25 Correct 3 ms 5028 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 519 ms 86144 KB Output is correct
31 Correct 357 ms 94876 KB Output is correct
32 Correct 484 ms 97364 KB Output is correct
33 Correct 505 ms 94548 KB Output is correct
34 Correct 361 ms 94268 KB Output is correct
35 Correct 352 ms 94888 KB Output is correct
36 Correct 293 ms 95508 KB Output is correct
37 Correct 590 ms 98596 KB Output is correct
38 Correct 380 ms 98800 KB Output is correct
39 Correct 545 ms 94352 KB Output is correct
40 Correct 339 ms 94752 KB Output is correct
41 Correct 248 ms 95152 KB Output is correct
42 Correct 244 ms 95544 KB Output is correct
43 Correct 252 ms 94896 KB Output is correct
44 Correct 302 ms 95512 KB Output is correct
45 Correct 255 ms 95948 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 4 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 4 ms 5012 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 542 ms 94388 KB Output is correct
53 Correct 379 ms 94912 KB Output is correct
54 Correct 535 ms 98696 KB Output is correct
55 Correct 458 ms 94676 KB Output is correct
56 Correct 430 ms 94736 KB Output is correct
57 Correct 397 ms 94384 KB Output is correct
58 Correct 331 ms 95456 KB Output is correct
59 Correct 597 ms 97332 KB Output is correct
60 Correct 411 ms 98756 KB Output is correct
61 Correct 587 ms 94256 KB Output is correct
62 Correct 386 ms 94792 KB Output is correct
63 Correct 4 ms 4948 KB Output is correct
64 Correct 4 ms 5032 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 4 ms 5176 KB Output is correct
67 Correct 4 ms 5116 KB Output is correct
68 Correct 4 ms 5008 KB Output is correct
69 Correct 3 ms 4948 KB Output is correct
70 Correct 3 ms 5032 KB Output is correct
71 Correct 4 ms 5028 KB Output is correct
72 Correct 5 ms 4948 KB Output is correct
73 Correct 4 ms 5032 KB Output is correct
74 Correct 5 ms 4948 KB Output is correct
75 Correct 3 ms 4948 KB Output is correct
76 Correct 4 ms 5032 KB Output is correct
77 Correct 4 ms 5036 KB Output is correct
78 Correct 3 ms 4948 KB Output is correct
79 Correct 700 ms 87608 KB Output is correct
80 Correct 867 ms 85992 KB Output is correct
81 Correct 686 ms 86488 KB Output is correct
82 Correct 608 ms 82980 KB Output is correct
83 Correct 479 ms 83064 KB Output is correct
84 Correct 391 ms 83276 KB Output is correct
85 Correct 358 ms 83596 KB Output is correct
86 Correct 682 ms 86444 KB Output is correct
87 Correct 808 ms 86672 KB Output is correct
88 Correct 687 ms 83244 KB Output is correct
89 Correct 735 ms 82648 KB Output is correct
90 Correct 489 ms 83604 KB Output is correct
91 Correct 463 ms 83952 KB Output is correct
92 Correct 3 ms 4948 KB Output is correct
93 Correct 3 ms 4948 KB Output is correct
94 Correct 3 ms 4948 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 4948 KB Output is correct
98 Correct 604 ms 88904 KB Output is correct
99 Correct 749 ms 85176 KB Output is correct
100 Correct 563 ms 95600 KB Output is correct
101 Correct 528 ms 93304 KB Output is correct
102 Correct 457 ms 93344 KB Output is correct
103 Correct 386 ms 93120 KB Output is correct
104 Correct 336 ms 93376 KB Output is correct
105 Correct 609 ms 98020 KB Output is correct
106 Correct 727 ms 96452 KB Output is correct
107 Correct 541 ms 93960 KB Output is correct
108 Correct 601 ms 92468 KB Output is correct
109 Correct 449 ms 93136 KB Output is correct
110 Correct 477 ms 93704 KB Output is correct
111 Correct 3 ms 5076 KB Output is correct
112 Correct 3 ms 4948 KB Output is correct
113 Correct 2 ms 5032 KB Output is correct
114 Correct 3 ms 5032 KB Output is correct
115 Correct 3 ms 4948 KB Output is correct
116 Correct 547 ms 92336 KB Output is correct
117 Correct 670 ms 92244 KB Output is correct
118 Correct 579 ms 98064 KB Output is correct
119 Correct 546 ms 94104 KB Output is correct
120 Correct 416 ms 94152 KB Output is correct
121 Correct 493 ms 94344 KB Output is correct
122 Correct 376 ms 94696 KB Output is correct
123 Correct 665 ms 97748 KB Output is correct
124 Correct 798 ms 95084 KB Output is correct
125 Correct 634 ms 93660 KB Output is correct
126 Correct 680 ms 92156 KB Output is correct
127 Correct 721 ms 92020 KB Output is correct
128 Correct 551 ms 92984 KB Output is correct
129 Correct 561 ms 93576 KB Output is correct