답안 #547416

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547416 2022-04-10T16:13:23 Z skittles1412 Sprinkler (JOI22_sprinkler) C++17
100 / 100
2072 ms 81516 KB
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
	cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
	cerr << t << " | ";
	dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
	cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
		 << ": ";                                          \
	dbgh(__VA_ARGS__)
#else
#define cerr   \
	if (false) \
	cerr
#define dbg(...)
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())

const int maxn = 2e5 + 5;

int p[maxn];
vector<int> graph[maxn];

void dfs(int u, int par = -1) {
	p[u] = par;
	for (auto& v : graph[u]) {
		if (v != par) {
			dfs(v, u);
		}
	}
}

void solve() {
	int n;
	long mod;
	cin >> n >> mod;
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	long arr[n];
	for (auto& a : arr) {
		cin >> a;
	}
	dfs(0);
	long mul[n][41];
	for (auto& a : mul) {
		fill(begin(a), end(a), 1);
	}
	int q;
	cin >> q;
	while (q--) {
		int t;
		cin >> t;
		if (t == 1) {
			int u, d;
			long w;
			cin >> u >> d >> w;
			u--;
			for (int i = 0; i <= d; i++) {
				for (int j = 0; j + i <= d; j++) {
					if (i < d && p[u] != -1 && i + j + 2 <= d) {
						continue;
					}
					dbg(u, j, w);
					mul[u][j] = (mul[u][j] * w) % mod;
				}
				u = p[u];
				if (u == -1) {
					break;
				}
			}
		} else {
			int u;
			cin >> u;
			u--;
			long ans = arr[u];
			for (int i = 0; i <= 40; i++) {
				ans = (ans * mul[u][i]) % mod;
				u = p[u];
				if (u == -1) {
					break;
				}
			}
			cout << ans << endl;
		}
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cin.exceptions(ios::failbit);
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5332 KB Output is correct
5 Correct 4 ms 5332 KB Output is correct
6 Correct 4 ms 5332 KB Output is correct
7 Correct 4 ms 5332 KB Output is correct
8 Correct 3 ms 5332 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4996 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 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
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 5024 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 483 ms 81516 KB Output is correct
3 Correct 348 ms 78248 KB Output is correct
4 Correct 457 ms 79704 KB Output is correct
5 Correct 422 ms 79820 KB Output is correct
6 Correct 320 ms 79824 KB Output is correct
7 Correct 395 ms 80124 KB Output is correct
8 Correct 265 ms 80460 KB Output is correct
9 Correct 563 ms 81208 KB Output is correct
10 Correct 356 ms 78060 KB Output is correct
11 Correct 496 ms 81296 KB Output is correct
12 Correct 340 ms 78360 KB Output is correct
13 Correct 246 ms 78884 KB Output is correct
14 Correct 240 ms 78896 KB Output is correct
15 Correct 233 ms 78876 KB Output is correct
16 Correct 244 ms 78728 KB Output is correct
17 Correct 249 ms 79300 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4948 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 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 483 ms 81516 KB Output is correct
3 Correct 348 ms 78248 KB Output is correct
4 Correct 457 ms 79704 KB Output is correct
5 Correct 422 ms 79820 KB Output is correct
6 Correct 320 ms 79824 KB Output is correct
7 Correct 395 ms 80124 KB Output is correct
8 Correct 265 ms 80460 KB Output is correct
9 Correct 563 ms 81208 KB Output is correct
10 Correct 356 ms 78060 KB Output is correct
11 Correct 496 ms 81296 KB Output is correct
12 Correct 340 ms 78360 KB Output is correct
13 Correct 246 ms 78884 KB Output is correct
14 Correct 240 ms 78896 KB Output is correct
15 Correct 233 ms 78876 KB Output is correct
16 Correct 244 ms 78728 KB Output is correct
17 Correct 249 ms 79300 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4948 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 4948 KB Output is correct
23 Correct 2 ms 4936 KB Output is correct
24 Correct 484 ms 81428 KB Output is correct
25 Correct 352 ms 78196 KB Output is correct
26 Correct 441 ms 79708 KB Output is correct
27 Correct 422 ms 79864 KB Output is correct
28 Correct 339 ms 79956 KB Output is correct
29 Correct 362 ms 80004 KB Output is correct
30 Correct 268 ms 80480 KB Output is correct
31 Correct 544 ms 81312 KB Output is correct
32 Correct 364 ms 78208 KB Output is correct
33 Correct 495 ms 81380 KB Output is correct
34 Correct 347 ms 78172 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 3 ms 4948 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 3 ms 4948 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 744 ms 78804 KB Output is correct
3 Correct 1811 ms 78100 KB Output is correct
4 Correct 906 ms 78340 KB Output is correct
5 Correct 732 ms 78276 KB Output is correct
6 Correct 481 ms 78408 KB Output is correct
7 Correct 456 ms 78492 KB Output is correct
8 Correct 285 ms 78956 KB Output is correct
9 Correct 772 ms 78640 KB Output is correct
10 Correct 2072 ms 77944 KB Output is correct
11 Correct 701 ms 78528 KB Output is correct
12 Correct 1471 ms 77912 KB Output is correct
13 Correct 825 ms 78828 KB Output is correct
14 Correct 862 ms 79216 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 4 ms 5028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 754 ms 81256 KB Output is correct
3 Correct 1909 ms 78116 KB Output is correct
4 Correct 823 ms 79580 KB Output is correct
5 Correct 712 ms 79820 KB Output is correct
6 Correct 524 ms 79872 KB Output is correct
7 Correct 439 ms 79840 KB Output is correct
8 Correct 290 ms 80296 KB Output is correct
9 Correct 728 ms 81308 KB Output is correct
10 Correct 1936 ms 78192 KB Output is correct
11 Correct 628 ms 81364 KB Output is correct
12 Correct 1360 ms 78452 KB Output is correct
13 Correct 759 ms 78924 KB Output is correct
14 Correct 787 ms 79304 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 2 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 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5332 KB Output is correct
5 Correct 4 ms 5332 KB Output is correct
6 Correct 4 ms 5332 KB Output is correct
7 Correct 4 ms 5332 KB Output is correct
8 Correct 3 ms 5332 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4996 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 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
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 5024 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 483 ms 81516 KB Output is correct
31 Correct 348 ms 78248 KB Output is correct
32 Correct 457 ms 79704 KB Output is correct
33 Correct 422 ms 79820 KB Output is correct
34 Correct 320 ms 79824 KB Output is correct
35 Correct 395 ms 80124 KB Output is correct
36 Correct 265 ms 80460 KB Output is correct
37 Correct 563 ms 81208 KB Output is correct
38 Correct 356 ms 78060 KB Output is correct
39 Correct 496 ms 81296 KB Output is correct
40 Correct 340 ms 78360 KB Output is correct
41 Correct 246 ms 78884 KB Output is correct
42 Correct 240 ms 78896 KB Output is correct
43 Correct 233 ms 78876 KB Output is correct
44 Correct 244 ms 78728 KB Output is correct
45 Correct 249 ms 79300 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 4 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 2 ms 4936 KB Output is correct
52 Correct 484 ms 81428 KB Output is correct
53 Correct 352 ms 78196 KB Output is correct
54 Correct 441 ms 79708 KB Output is correct
55 Correct 422 ms 79864 KB Output is correct
56 Correct 339 ms 79956 KB Output is correct
57 Correct 362 ms 80004 KB Output is correct
58 Correct 268 ms 80480 KB Output is correct
59 Correct 544 ms 81312 KB Output is correct
60 Correct 364 ms 78208 KB Output is correct
61 Correct 495 ms 81380 KB Output is correct
62 Correct 347 ms 78172 KB Output is correct
63 Correct 3 ms 4948 KB Output is correct
64 Correct 3 ms 4948 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 3 ms 4948 KB Output is correct
67 Correct 3 ms 4948 KB Output is correct
68 Correct 3 ms 4948 KB Output is correct
69 Correct 3 ms 4948 KB Output is correct
70 Correct 3 ms 4948 KB Output is correct
71 Correct 3 ms 4948 KB Output is correct
72 Correct 3 ms 4948 KB Output is correct
73 Correct 3 ms 4948 KB Output is correct
74 Correct 3 ms 4948 KB Output is correct
75 Correct 3 ms 4948 KB Output is correct
76 Correct 3 ms 4948 KB Output is correct
77 Correct 3 ms 4948 KB Output is correct
78 Correct 3 ms 4948 KB Output is correct
79 Correct 744 ms 78804 KB Output is correct
80 Correct 1811 ms 78100 KB Output is correct
81 Correct 906 ms 78340 KB Output is correct
82 Correct 732 ms 78276 KB Output is correct
83 Correct 481 ms 78408 KB Output is correct
84 Correct 456 ms 78492 KB Output is correct
85 Correct 285 ms 78956 KB Output is correct
86 Correct 772 ms 78640 KB Output is correct
87 Correct 2072 ms 77944 KB Output is correct
88 Correct 701 ms 78528 KB Output is correct
89 Correct 1471 ms 77912 KB Output is correct
90 Correct 825 ms 78828 KB Output is correct
91 Correct 862 ms 79216 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 4 ms 5028 KB Output is correct
97 Correct 4 ms 4948 KB Output is correct
98 Correct 754 ms 81256 KB Output is correct
99 Correct 1909 ms 78116 KB Output is correct
100 Correct 823 ms 79580 KB Output is correct
101 Correct 712 ms 79820 KB Output is correct
102 Correct 524 ms 79872 KB Output is correct
103 Correct 439 ms 79840 KB Output is correct
104 Correct 290 ms 80296 KB Output is correct
105 Correct 728 ms 81308 KB Output is correct
106 Correct 1936 ms 78192 KB Output is correct
107 Correct 628 ms 81364 KB Output is correct
108 Correct 1360 ms 78452 KB Output is correct
109 Correct 759 ms 78924 KB Output is correct
110 Correct 787 ms 79304 KB Output is correct
111 Correct 3 ms 4948 KB Output is correct
112 Correct 3 ms 4948 KB Output is correct
113 Correct 2 ms 4948 KB Output is correct
114 Correct 3 ms 4948 KB Output is correct
115 Correct 3 ms 4948 KB Output is correct
116 Correct 609 ms 79384 KB Output is correct
117 Correct 1361 ms 77868 KB Output is correct
118 Correct 786 ms 79768 KB Output is correct
119 Correct 707 ms 79792 KB Output is correct
120 Correct 472 ms 79724 KB Output is correct
121 Correct 462 ms 80204 KB Output is correct
122 Correct 310 ms 80556 KB Output is correct
123 Correct 716 ms 81300 KB Output is correct
124 Correct 1867 ms 78140 KB Output is correct
125 Correct 636 ms 80836 KB Output is correct
126 Correct 1490 ms 78108 KB Output is correct
127 Correct 1450 ms 78080 KB Output is correct
128 Correct 881 ms 79028 KB Output is correct
129 Correct 908 ms 79536 KB Output is correct