Submission #882882

# Submission time Handle Problem Language Result Execution time Memory
882882 2023-12-04T02:58:07 Z NK_ Sprinkler (JOI22_sprinkler) C++17
100 / 100
627 ms 110420 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define pb push_back

using ll = long long;
template<class T> using V = vector<T>;
using vi = V<int>;

const int DEP = 45;
using AR = array<ll, 45>;


int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, L; cin >> N >> L;

	V<vi> adj(N);
	for(int i = 0; i < N - 1; i++) {
		int u, v; cin >> u >> v; --u, --v;
		adj[u].pb(v);
		adj[v].pb(u);
	}	

	vi H(N); for(auto& x : H) cin >> x;

	V<AR> W(N); vi par(N, -1); 
	function<void(int)> gen = [&](int u) {
		W[u].fill(1);
		for(auto& v : adj[u]) if (v != par[u]) {
			par[v] = u; gen(v);
		}
	};

	gen(0);

	int Q; cin >> Q;
	for(int q = 0; q < Q; q++) {
		int t; cin >> t;
		if (t == 1) {
			int u, d; ll x; cin >> u >> d >> x; --u;
			while(u != -1 && d >= 0) {
				W[u][d] = (W[u][d] * x) % L;
				// cout << u << " " << d << " --> " << W[u][d] << endl;
				u = par[u], d--;
			}
		} else {
			int u, d = 0; cin >> u; --u;

			ll mul = H[u];
			while(u != -1 && d < DEP) {
				if (par[u] == -1) { // all ones that have pivot points above bounds
					for(int dx = d; dx < DEP; dx++) {
						mul = (mul * W[u][dx]) % L;
					}
				} else {
					mul = (mul * W[u][d]) % L;
					if (d + 1 < DEP) mul = (mul * W[u][d + 1]) % L;
				}

				// cout << "Q: " << u << " " << d << " => " << mul << endl;
				u = par[u]; d++;
			}

			cout << mul << nl;
		}
	}

	exit(0-0);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 680 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 452 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 459 ms 95304 KB Output is correct
3 Correct 304 ms 95784 KB Output is correct
4 Correct 462 ms 105296 KB Output is correct
5 Correct 386 ms 95568 KB Output is correct
6 Correct 326 ms 95532 KB Output is correct
7 Correct 322 ms 95648 KB Output is correct
8 Correct 266 ms 96196 KB Output is correct
9 Correct 622 ms 110420 KB Output is correct
10 Correct 324 ms 109500 KB Output is correct
11 Correct 460 ms 95228 KB Output is correct
12 Correct 323 ms 95752 KB Output is correct
13 Correct 203 ms 95940 KB Output is correct
14 Correct 208 ms 96456 KB Output is correct
15 Correct 218 ms 96008 KB Output is correct
16 Correct 220 ms 96272 KB Output is correct
17 Correct 235 ms 96852 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 459 ms 95304 KB Output is correct
3 Correct 304 ms 95784 KB Output is correct
4 Correct 462 ms 105296 KB Output is correct
5 Correct 386 ms 95568 KB Output is correct
6 Correct 326 ms 95532 KB Output is correct
7 Correct 322 ms 95648 KB Output is correct
8 Correct 266 ms 96196 KB Output is correct
9 Correct 622 ms 110420 KB Output is correct
10 Correct 324 ms 109500 KB Output is correct
11 Correct 460 ms 95228 KB Output is correct
12 Correct 323 ms 95752 KB Output is correct
13 Correct 203 ms 95940 KB Output is correct
14 Correct 208 ms 96456 KB Output is correct
15 Correct 218 ms 96008 KB Output is correct
16 Correct 220 ms 96272 KB Output is correct
17 Correct 235 ms 96852 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 443 ms 95352 KB Output is correct
25 Correct 329 ms 95820 KB Output is correct
26 Correct 461 ms 109956 KB Output is correct
27 Correct 379 ms 95336 KB Output is correct
28 Correct 328 ms 95720 KB Output is correct
29 Correct 311 ms 95184 KB Output is correct
30 Correct 261 ms 96384 KB Output is correct
31 Correct 613 ms 105732 KB Output is correct
32 Correct 360 ms 109556 KB Output is correct
33 Correct 457 ms 95420 KB Output is correct
34 Correct 315 ms 95820 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 344 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 460 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 456 KB Output is correct
2 Correct 627 ms 107092 KB Output is correct
3 Correct 558 ms 104528 KB Output is correct
4 Correct 532 ms 104440 KB Output is correct
5 Correct 407 ms 92500 KB Output is correct
6 Correct 338 ms 92864 KB Output is correct
7 Correct 307 ms 92696 KB Output is correct
8 Correct 254 ms 93704 KB Output is correct
9 Correct 623 ms 102736 KB Output is correct
10 Correct 533 ms 106316 KB Output is correct
11 Correct 473 ms 92128 KB Output is correct
12 Correct 447 ms 93012 KB Output is correct
13 Correct 331 ms 93996 KB Output is correct
14 Correct 315 ms 94528 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 623 ms 104852 KB Output is correct
3 Correct 531 ms 100948 KB Output is correct
4 Correct 514 ms 103252 KB Output is correct
5 Correct 412 ms 94164 KB Output is correct
6 Correct 376 ms 94140 KB Output is correct
7 Correct 345 ms 93908 KB Output is correct
8 Correct 277 ms 94252 KB Output is correct
9 Correct 622 ms 108724 KB Output is correct
10 Correct 562 ms 107552 KB Output is correct
11 Correct 463 ms 94804 KB Output is correct
12 Correct 415 ms 93264 KB Output is correct
13 Correct 318 ms 94176 KB Output is correct
14 Correct 313 ms 94544 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 680 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 452 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 459 ms 95304 KB Output is correct
31 Correct 304 ms 95784 KB Output is correct
32 Correct 462 ms 105296 KB Output is correct
33 Correct 386 ms 95568 KB Output is correct
34 Correct 326 ms 95532 KB Output is correct
35 Correct 322 ms 95648 KB Output is correct
36 Correct 266 ms 96196 KB Output is correct
37 Correct 622 ms 110420 KB Output is correct
38 Correct 324 ms 109500 KB Output is correct
39 Correct 460 ms 95228 KB Output is correct
40 Correct 323 ms 95752 KB Output is correct
41 Correct 203 ms 95940 KB Output is correct
42 Correct 208 ms 96456 KB Output is correct
43 Correct 218 ms 96008 KB Output is correct
44 Correct 220 ms 96272 KB Output is correct
45 Correct 235 ms 96852 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 443 ms 95352 KB Output is correct
53 Correct 329 ms 95820 KB Output is correct
54 Correct 461 ms 109956 KB Output is correct
55 Correct 379 ms 95336 KB Output is correct
56 Correct 328 ms 95720 KB Output is correct
57 Correct 311 ms 95184 KB Output is correct
58 Correct 261 ms 96384 KB Output is correct
59 Correct 613 ms 105732 KB Output is correct
60 Correct 360 ms 109556 KB Output is correct
61 Correct 457 ms 95420 KB Output is correct
62 Correct 315 ms 95820 KB Output is correct
63 Correct 1 ms 344 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 1 ms 344 KB Output is correct
74 Correct 1 ms 348 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 1 ms 460 KB Output is correct
77 Correct 1 ms 348 KB Output is correct
78 Correct 1 ms 456 KB Output is correct
79 Correct 627 ms 107092 KB Output is correct
80 Correct 558 ms 104528 KB Output is correct
81 Correct 532 ms 104440 KB Output is correct
82 Correct 407 ms 92500 KB Output is correct
83 Correct 338 ms 92864 KB Output is correct
84 Correct 307 ms 92696 KB Output is correct
85 Correct 254 ms 93704 KB Output is correct
86 Correct 623 ms 102736 KB Output is correct
87 Correct 533 ms 106316 KB Output is correct
88 Correct 473 ms 92128 KB Output is correct
89 Correct 447 ms 93012 KB Output is correct
90 Correct 331 ms 93996 KB Output is correct
91 Correct 315 ms 94528 KB Output is correct
92 Correct 1 ms 344 KB Output is correct
93 Correct 1 ms 348 KB Output is correct
94 Correct 1 ms 604 KB Output is correct
95 Correct 1 ms 348 KB Output is correct
96 Correct 1 ms 348 KB Output is correct
97 Correct 0 ms 348 KB Output is correct
98 Correct 623 ms 104852 KB Output is correct
99 Correct 531 ms 100948 KB Output is correct
100 Correct 514 ms 103252 KB Output is correct
101 Correct 412 ms 94164 KB Output is correct
102 Correct 376 ms 94140 KB Output is correct
103 Correct 345 ms 93908 KB Output is correct
104 Correct 277 ms 94252 KB Output is correct
105 Correct 622 ms 108724 KB Output is correct
106 Correct 562 ms 107552 KB Output is correct
107 Correct 463 ms 94804 KB Output is correct
108 Correct 415 ms 93264 KB Output is correct
109 Correct 318 ms 94176 KB Output is correct
110 Correct 313 ms 94544 KB Output is correct
111 Correct 1 ms 348 KB Output is correct
112 Correct 0 ms 348 KB Output is correct
113 Correct 1 ms 348 KB Output is correct
114 Correct 1 ms 348 KB Output is correct
115 Correct 1 ms 348 KB Output is correct
116 Correct 512 ms 93144 KB Output is correct
117 Correct 469 ms 95872 KB Output is correct
118 Correct 521 ms 109724 KB Output is correct
119 Correct 431 ms 95704 KB Output is correct
120 Correct 367 ms 95068 KB Output is correct
121 Correct 379 ms 95876 KB Output is correct
122 Correct 302 ms 96296 KB Output is correct
123 Correct 626 ms 107088 KB Output is correct
124 Correct 578 ms 104604 KB Output is correct
125 Correct 520 ms 94360 KB Output is correct
126 Correct 465 ms 95680 KB Output is correct
127 Correct 450 ms 96184 KB Output is correct
128 Correct 362 ms 96820 KB Output is correct
129 Correct 368 ms 97356 KB Output is correct