Submission #557581

# Submission time Handle Problem Language Result Execution time Memory
557581 2022-05-05T14:02:22 Z Arvin Sprinkler (JOI22_sprinkler) C++11
100 / 100
886 ms 108236 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
 
const int maxN = 2e5 + 5;
const int maxD = 45;
const int logN = log2(maxN)+1;
 
ll l;

vector<int> adj[maxN];
ll val[maxN][maxD];
int level[maxN];
int parent[maxN];
 
void dfs(int curNode, int prvNode = 0){
	parent[curNode] = prvNode;
	
	for(auto nxt : adj[curNode]){
		if(nxt != prvNode){
			level[nxt] = level[curNode]+1;
			dfs(nxt, curNode);
		}
	}
}

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	
	int n;
	cin >> n >> l;
	
	for(int x=0;x<n-1;x++){
		int a, b;
		cin >> a >> b;
		
		a--; b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	ll h[n];
	for(int x=0;x<n;x++){
		cin >> h[x];
	}
	
	level[0] = 0;
	dfs(0, -1);
	
	fill(val[0], val[maxN], 1);
	
	int q;
	cin >> q;
	
	while(q--){
		int t;
		cin >> t;
		
		if(t == 1){
			int x, d, w;
			cin >> x >> d >> w;
			
			x--;
			
			int node = x;
			while(node != 0 && d >= 0){
				val[node][d] *= w;
				val[node][d] %= l;
				
				d--;
				node = parent[node];
			}
			if(d >= 0){
				for(int x=0;x<min(d+1, maxD);x++){
					val[0][x] *= w;
					val[0][x] %= l;
				}
			}
			
		} else if(t == 2){
			int x;
			cin >> x;
			
			x--;
			
			ll ans = h[x];
			int d = 0;
			int node = x;
			
			while(node != -1 && d <= 40){
				ans *= val[node][d];
				ans %= l;
				
				if(node != 0 && d < 40) ans *= val[node][d+1];
				ans %= l;
				
				d++;
				node = parent[node];
			}
			
			cout << ans << "\n";
		} else {
			assert(false);
		}
	}
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 32 ms 75436 KB Output is correct
2 Correct 33 ms 75456 KB Output is correct
3 Correct 42 ms 75344 KB Output is correct
4 Correct 42 ms 75480 KB Output is correct
5 Correct 32 ms 75468 KB Output is correct
6 Correct 32 ms 75488 KB Output is correct
7 Correct 36 ms 75488 KB Output is correct
8 Correct 35 ms 75440 KB Output is correct
9 Correct 32 ms 75420 KB Output is correct
10 Correct 35 ms 75388 KB Output is correct
11 Correct 34 ms 75468 KB Output is correct
12 Correct 37 ms 75428 KB Output is correct
13 Correct 33 ms 75412 KB Output is correct
14 Correct 31 ms 75452 KB Output is correct
15 Correct 31 ms 75444 KB Output is correct
16 Correct 31 ms 75384 KB Output is correct
17 Correct 32 ms 75440 KB Output is correct
18 Correct 33 ms 75468 KB Output is correct
19 Correct 31 ms 75468 KB Output is correct
20 Correct 34 ms 75416 KB Output is correct
21 Correct 34 ms 75416 KB Output is correct
22 Correct 32 ms 75380 KB Output is correct
23 Correct 39 ms 75464 KB Output is correct
24 Correct 32 ms 75432 KB Output is correct
25 Correct 35 ms 75384 KB Output is correct
26 Correct 33 ms 75388 KB Output is correct
27 Correct 33 ms 75372 KB Output is correct
28 Correct 37 ms 75376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 75408 KB Output is correct
2 Correct 601 ms 88824 KB Output is correct
3 Correct 415 ms 85452 KB Output is correct
4 Correct 591 ms 94940 KB Output is correct
5 Correct 547 ms 87136 KB Output is correct
6 Correct 365 ms 86924 KB Output is correct
7 Correct 375 ms 87300 KB Output is correct
8 Correct 256 ms 87652 KB Output is correct
9 Correct 749 ms 100708 KB Output is correct
10 Correct 407 ms 96416 KB Output is correct
11 Correct 685 ms 88632 KB Output is correct
12 Correct 375 ms 93520 KB Output is correct
13 Correct 322 ms 97352 KB Output is correct
14 Correct 267 ms 97544 KB Output is correct
15 Correct 289 ms 87252 KB Output is correct
16 Correct 245 ms 91728 KB Output is correct
17 Correct 286 ms 92952 KB Output is correct
18 Correct 38 ms 75440 KB Output is correct
19 Correct 48 ms 75468 KB Output is correct
20 Correct 37 ms 75412 KB Output is correct
21 Correct 32 ms 75468 KB Output is correct
22 Correct 31 ms 75468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 75408 KB Output is correct
2 Correct 601 ms 88824 KB Output is correct
3 Correct 415 ms 85452 KB Output is correct
4 Correct 591 ms 94940 KB Output is correct
5 Correct 547 ms 87136 KB Output is correct
6 Correct 365 ms 86924 KB Output is correct
7 Correct 375 ms 87300 KB Output is correct
8 Correct 256 ms 87652 KB Output is correct
9 Correct 749 ms 100708 KB Output is correct
10 Correct 407 ms 96416 KB Output is correct
11 Correct 685 ms 88632 KB Output is correct
12 Correct 375 ms 93520 KB Output is correct
13 Correct 322 ms 97352 KB Output is correct
14 Correct 267 ms 97544 KB Output is correct
15 Correct 289 ms 87252 KB Output is correct
16 Correct 245 ms 91728 KB Output is correct
17 Correct 286 ms 92952 KB Output is correct
18 Correct 38 ms 75440 KB Output is correct
19 Correct 48 ms 75468 KB Output is correct
20 Correct 37 ms 75412 KB Output is correct
21 Correct 32 ms 75468 KB Output is correct
22 Correct 31 ms 75468 KB Output is correct
23 Correct 30 ms 75456 KB Output is correct
24 Correct 630 ms 96672 KB Output is correct
25 Correct 403 ms 95972 KB Output is correct
26 Correct 653 ms 108236 KB Output is correct
27 Correct 589 ms 96192 KB Output is correct
28 Correct 396 ms 96676 KB Output is correct
29 Correct 385 ms 96384 KB Output is correct
30 Correct 280 ms 96824 KB Output is correct
31 Correct 758 ms 104528 KB Output is correct
32 Correct 450 ms 107400 KB Output is correct
33 Correct 723 ms 96368 KB Output is correct
34 Correct 413 ms 96584 KB Output is correct
35 Correct 34 ms 75460 KB Output is correct
36 Correct 33 ms 75424 KB Output is correct
37 Correct 31 ms 75404 KB Output is correct
38 Correct 37 ms 75428 KB Output is correct
39 Correct 33 ms 75412 KB Output is correct
40 Correct 34 ms 75408 KB Output is correct
41 Correct 38 ms 75484 KB Output is correct
42 Correct 37 ms 75464 KB Output is correct
43 Correct 32 ms 75416 KB Output is correct
44 Correct 32 ms 75376 KB Output is correct
45 Correct 33 ms 75452 KB Output is correct
46 Correct 33 ms 75364 KB Output is correct
47 Correct 35 ms 75396 KB Output is correct
48 Correct 42 ms 75432 KB Output is correct
49 Correct 35 ms 75420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 75416 KB Output is correct
2 Correct 886 ms 97900 KB Output is correct
3 Correct 728 ms 94488 KB Output is correct
4 Correct 644 ms 95492 KB Output is correct
5 Correct 537 ms 85992 KB Output is correct
6 Correct 398 ms 85744 KB Output is correct
7 Correct 335 ms 85984 KB Output is correct
8 Correct 316 ms 86372 KB Output is correct
9 Correct 839 ms 94524 KB Output is correct
10 Correct 680 ms 96108 KB Output is correct
11 Correct 592 ms 86072 KB Output is correct
12 Correct 621 ms 85244 KB Output is correct
13 Correct 396 ms 86308 KB Output is correct
14 Correct 411 ms 86672 KB Output is correct
15 Correct 32 ms 75340 KB Output is correct
16 Correct 33 ms 75468 KB Output is correct
17 Correct 33 ms 75436 KB Output is correct
18 Correct 32 ms 75432 KB Output is correct
19 Correct 31 ms 75460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 75340 KB Output is correct
2 Correct 775 ms 96608 KB Output is correct
3 Correct 670 ms 100480 KB Output is correct
4 Correct 677 ms 102136 KB Output is correct
5 Correct 509 ms 95028 KB Output is correct
6 Correct 446 ms 94984 KB Output is correct
7 Correct 420 ms 94820 KB Output is correct
8 Correct 335 ms 95312 KB Output is correct
9 Correct 797 ms 107220 KB Output is correct
10 Correct 704 ms 104980 KB Output is correct
11 Correct 718 ms 95748 KB Output is correct
12 Correct 625 ms 94112 KB Output is correct
13 Correct 466 ms 95216 KB Output is correct
14 Correct 416 ms 95708 KB Output is correct
15 Correct 42 ms 75436 KB Output is correct
16 Correct 39 ms 75476 KB Output is correct
17 Correct 32 ms 75404 KB Output is correct
18 Correct 32 ms 75416 KB Output is correct
19 Correct 32 ms 75436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 75436 KB Output is correct
2 Correct 33 ms 75456 KB Output is correct
3 Correct 42 ms 75344 KB Output is correct
4 Correct 42 ms 75480 KB Output is correct
5 Correct 32 ms 75468 KB Output is correct
6 Correct 32 ms 75488 KB Output is correct
7 Correct 36 ms 75488 KB Output is correct
8 Correct 35 ms 75440 KB Output is correct
9 Correct 32 ms 75420 KB Output is correct
10 Correct 35 ms 75388 KB Output is correct
11 Correct 34 ms 75468 KB Output is correct
12 Correct 37 ms 75428 KB Output is correct
13 Correct 33 ms 75412 KB Output is correct
14 Correct 31 ms 75452 KB Output is correct
15 Correct 31 ms 75444 KB Output is correct
16 Correct 31 ms 75384 KB Output is correct
17 Correct 32 ms 75440 KB Output is correct
18 Correct 33 ms 75468 KB Output is correct
19 Correct 31 ms 75468 KB Output is correct
20 Correct 34 ms 75416 KB Output is correct
21 Correct 34 ms 75416 KB Output is correct
22 Correct 32 ms 75380 KB Output is correct
23 Correct 39 ms 75464 KB Output is correct
24 Correct 32 ms 75432 KB Output is correct
25 Correct 35 ms 75384 KB Output is correct
26 Correct 33 ms 75388 KB Output is correct
27 Correct 33 ms 75372 KB Output is correct
28 Correct 37 ms 75376 KB Output is correct
29 Correct 36 ms 75408 KB Output is correct
30 Correct 601 ms 88824 KB Output is correct
31 Correct 415 ms 85452 KB Output is correct
32 Correct 591 ms 94940 KB Output is correct
33 Correct 547 ms 87136 KB Output is correct
34 Correct 365 ms 86924 KB Output is correct
35 Correct 375 ms 87300 KB Output is correct
36 Correct 256 ms 87652 KB Output is correct
37 Correct 749 ms 100708 KB Output is correct
38 Correct 407 ms 96416 KB Output is correct
39 Correct 685 ms 88632 KB Output is correct
40 Correct 375 ms 93520 KB Output is correct
41 Correct 322 ms 97352 KB Output is correct
42 Correct 267 ms 97544 KB Output is correct
43 Correct 289 ms 87252 KB Output is correct
44 Correct 245 ms 91728 KB Output is correct
45 Correct 286 ms 92952 KB Output is correct
46 Correct 38 ms 75440 KB Output is correct
47 Correct 48 ms 75468 KB Output is correct
48 Correct 37 ms 75412 KB Output is correct
49 Correct 32 ms 75468 KB Output is correct
50 Correct 31 ms 75468 KB Output is correct
51 Correct 30 ms 75456 KB Output is correct
52 Correct 630 ms 96672 KB Output is correct
53 Correct 403 ms 95972 KB Output is correct
54 Correct 653 ms 108236 KB Output is correct
55 Correct 589 ms 96192 KB Output is correct
56 Correct 396 ms 96676 KB Output is correct
57 Correct 385 ms 96384 KB Output is correct
58 Correct 280 ms 96824 KB Output is correct
59 Correct 758 ms 104528 KB Output is correct
60 Correct 450 ms 107400 KB Output is correct
61 Correct 723 ms 96368 KB Output is correct
62 Correct 413 ms 96584 KB Output is correct
63 Correct 34 ms 75460 KB Output is correct
64 Correct 33 ms 75424 KB Output is correct
65 Correct 31 ms 75404 KB Output is correct
66 Correct 37 ms 75428 KB Output is correct
67 Correct 33 ms 75412 KB Output is correct
68 Correct 34 ms 75408 KB Output is correct
69 Correct 38 ms 75484 KB Output is correct
70 Correct 37 ms 75464 KB Output is correct
71 Correct 32 ms 75416 KB Output is correct
72 Correct 32 ms 75376 KB Output is correct
73 Correct 33 ms 75452 KB Output is correct
74 Correct 33 ms 75364 KB Output is correct
75 Correct 35 ms 75396 KB Output is correct
76 Correct 42 ms 75432 KB Output is correct
77 Correct 35 ms 75420 KB Output is correct
78 Correct 32 ms 75416 KB Output is correct
79 Correct 886 ms 97900 KB Output is correct
80 Correct 728 ms 94488 KB Output is correct
81 Correct 644 ms 95492 KB Output is correct
82 Correct 537 ms 85992 KB Output is correct
83 Correct 398 ms 85744 KB Output is correct
84 Correct 335 ms 85984 KB Output is correct
85 Correct 316 ms 86372 KB Output is correct
86 Correct 839 ms 94524 KB Output is correct
87 Correct 680 ms 96108 KB Output is correct
88 Correct 592 ms 86072 KB Output is correct
89 Correct 621 ms 85244 KB Output is correct
90 Correct 396 ms 86308 KB Output is correct
91 Correct 411 ms 86672 KB Output is correct
92 Correct 32 ms 75340 KB Output is correct
93 Correct 33 ms 75468 KB Output is correct
94 Correct 33 ms 75436 KB Output is correct
95 Correct 32 ms 75432 KB Output is correct
96 Correct 31 ms 75460 KB Output is correct
97 Correct 30 ms 75340 KB Output is correct
98 Correct 775 ms 96608 KB Output is correct
99 Correct 670 ms 100480 KB Output is correct
100 Correct 677 ms 102136 KB Output is correct
101 Correct 509 ms 95028 KB Output is correct
102 Correct 446 ms 94984 KB Output is correct
103 Correct 420 ms 94820 KB Output is correct
104 Correct 335 ms 95312 KB Output is correct
105 Correct 797 ms 107220 KB Output is correct
106 Correct 704 ms 104980 KB Output is correct
107 Correct 718 ms 95748 KB Output is correct
108 Correct 625 ms 94112 KB Output is correct
109 Correct 466 ms 95216 KB Output is correct
110 Correct 416 ms 95708 KB Output is correct
111 Correct 42 ms 75436 KB Output is correct
112 Correct 39 ms 75476 KB Output is correct
113 Correct 32 ms 75404 KB Output is correct
114 Correct 32 ms 75416 KB Output is correct
115 Correct 32 ms 75436 KB Output is correct
116 Correct 762 ms 94288 KB Output is correct
117 Correct 642 ms 96888 KB Output is correct
118 Correct 679 ms 107244 KB Output is correct
119 Correct 560 ms 96320 KB Output is correct
120 Correct 454 ms 95784 KB Output is correct
121 Correct 502 ms 96772 KB Output is correct
122 Correct 307 ms 96968 KB Output is correct
123 Correct 826 ms 105888 KB Output is correct
124 Correct 712 ms 103956 KB Output is correct
125 Correct 714 ms 94800 KB Output is correct
126 Correct 624 ms 96560 KB Output is correct
127 Correct 642 ms 97100 KB Output is correct
128 Correct 493 ms 94448 KB Output is correct
129 Correct 519 ms 86632 KB Output is correct