답안 #896842

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
896842 2024-01-02T09:28:00 Z TAhmed33 Sprinkler (JOI22_sprinkler) C++
38 / 100
858 ms 35112 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 25;
vector <int> adj[MAXN];
int p[MAXN], h[MAXN], n, l, q;
int lazy[MAXN], lazy2[MAXN];
void fix (int pos, int par) {
	p[pos] = par;
	for (int j = 0; j < (int)adj[pos].size(); j++) {
		if (adj[pos][j] == par) {
			adj[pos].erase(adj[pos].begin() + j);
			break;
		}
	}
	for (auto j : adj[pos]) {
		fix(j, pos);
	}
}
int mul (int a, int b) {
	return (a * 1ll * b) % l;
}
int main () {
	cin >> n >> l;
	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for (int i = 1; i <= n; i++) cin >> h[i];
	for (int i = 1; i <= n; i++) lazy[i] = lazy2[i] = 1;
	fix(1, -1);
	cin >> q;
	while (q--) {
		int t;
		cin >> t;
		if (t == 1) {
			int x, d, w;
			cin >> x >> d >> w;
			if (d == 0) {
				h[x] = mul(h[x], w); 
			} else if (d == 1) {
				if (p[x] != -1) {
					h[p[x]] = mul(h[p[x]], w);
				}
				h[x] = mul(h[x], w);
				lazy[x] = mul(lazy[x], w);
			} else if (d == 2) {
				if (p[x] == -1) {
					lazy2[x] = mul(lazy2[x], w);
					h[x] = mul(h[x], w);
				} else if (p[p[x]] == -1) {
					lazy2[x] = mul(lazy2[x], w);
					h[p[x]] = mul(h[p[x]], w);
					lazy[p[x]] = mul(lazy[p[x]], w);
				} else {
					lazy2[x] = mul(lazy2[x], w);
					lazy[p[x]] = mul(lazy[p[x]], w);
					h[p[x]] = mul(h[p[x]], w);
					h[p[p[x]]] = mul(h[p[p[x]]], w);
				}
			}
		} else {
			int x;
			cin >> x;
			int z = h[x];
			if (p[x] != -1) {
				z = mul(z, lazy[p[x]]);
				z = mul(z, lazy2[p[x]]);
				if (p[p[x]] != -1) {
					z = mul(z, lazy2[p[p[x]]]);
				}
			}
			cout << z << '\n';
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 763 ms 18172 KB Output is correct
3 Correct 496 ms 15000 KB Output is correct
4 Correct 632 ms 22272 KB Output is correct
5 Correct 612 ms 16464 KB Output is correct
6 Correct 605 ms 16292 KB Output is correct
7 Correct 630 ms 16920 KB Output is correct
8 Correct 606 ms 17096 KB Output is correct
9 Correct 813 ms 26964 KB Output is correct
10 Correct 495 ms 23648 KB Output is correct
11 Correct 858 ms 18180 KB Output is correct
12 Correct 480 ms 15004 KB Output is correct
13 Correct 490 ms 15792 KB Output is correct
14 Correct 477 ms 15752 KB Output is correct
15 Correct 451 ms 15536 KB Output is correct
16 Correct 485 ms 15440 KB Output is correct
17 Correct 468 ms 15956 KB Output is correct
18 Correct 4 ms 8028 KB Output is correct
19 Correct 3 ms 8028 KB Output is correct
20 Correct 3 ms 8028 KB Output is correct
21 Correct 3 ms 8028 KB Output is correct
22 Correct 3 ms 8028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 763 ms 18172 KB Output is correct
3 Correct 496 ms 15000 KB Output is correct
4 Correct 632 ms 22272 KB Output is correct
5 Correct 612 ms 16464 KB Output is correct
6 Correct 605 ms 16292 KB Output is correct
7 Correct 630 ms 16920 KB Output is correct
8 Correct 606 ms 17096 KB Output is correct
9 Correct 813 ms 26964 KB Output is correct
10 Correct 495 ms 23648 KB Output is correct
11 Correct 858 ms 18180 KB Output is correct
12 Correct 480 ms 15004 KB Output is correct
13 Correct 490 ms 15792 KB Output is correct
14 Correct 477 ms 15752 KB Output is correct
15 Correct 451 ms 15536 KB Output is correct
16 Correct 485 ms 15440 KB Output is correct
17 Correct 468 ms 15956 KB Output is correct
18 Correct 4 ms 8028 KB Output is correct
19 Correct 3 ms 8028 KB Output is correct
20 Correct 3 ms 8028 KB Output is correct
21 Correct 3 ms 8028 KB Output is correct
22 Correct 3 ms 8028 KB Output is correct
23 Correct 2 ms 8028 KB Output is correct
24 Correct 761 ms 17948 KB Output is correct
25 Correct 491 ms 26744 KB Output is correct
26 Correct 662 ms 35112 KB Output is correct
27 Correct 639 ms 26732 KB Output is correct
28 Correct 639 ms 26708 KB Output is correct
29 Correct 610 ms 26604 KB Output is correct
30 Correct 595 ms 27304 KB Output is correct
31 Correct 759 ms 32460 KB Output is correct
32 Correct 495 ms 34896 KB Output is correct
33 Correct 767 ms 26280 KB Output is correct
34 Correct 487 ms 26896 KB Output is correct
35 Correct 3 ms 8040 KB Output is correct
36 Correct 3 ms 8108 KB Output is correct
37 Correct 3 ms 7892 KB Output is correct
38 Correct 3 ms 8092 KB Output is correct
39 Correct 3 ms 8028 KB Output is correct
40 Correct 3 ms 8028 KB Output is correct
41 Correct 3 ms 8028 KB Output is correct
42 Correct 3 ms 8028 KB Output is correct
43 Correct 3 ms 8028 KB Output is correct
44 Correct 3 ms 8028 KB Output is correct
45 Correct 4 ms 8024 KB Output is correct
46 Correct 3 ms 8028 KB Output is correct
47 Correct 3 ms 8084 KB Output is correct
48 Correct 3 ms 8028 KB Output is correct
49 Correct 3 ms 8028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Incorrect 754 ms 27152 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8024 KB Output isn't correct
2 Halted 0 ms 0 KB -