Submission #864529

# Submission time Handle Problem Language Result Execution time Memory
864529 2023-10-23T07:25:44 Z willychan Sprinkler (JOI22_sprinkler) C++14
100 / 100
794 ms 62036 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds

const int N = 2e5+5;
int ans[N];
const int D = 42;
int app[N][D];
vector<int> side[N];
int L = 0;
int p[N];
int n;
void dfs(int cur){
	for(auto i : side[cur]){
		if(!p[i]){
			p[i]=cur;
			dfs(i);
		}
	}
}
void debug(){
	cout<<"\n\n\n";
	for(int i=1;i<=n;i++){
		for(int j=0;j<(min(D,n+1));j++){
			cout<<app[i][j]<<" ";
		}
		cout<<"\n";
	}
	cout<<"\n\n\n";
}
int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>L;
	for(int i=0;i<n-1;i++){
		int a,b;cin>>a>>b;
		side[a].push_back(b);
		side[b].push_back(a);
	}
	for(int i=1;i<=n;i++){
		for(int d=0;d<D;d++) app[i][d]=1;
		int a;cin>>a;
		ans[i]=a;
	}
	p[1]=1;
	dfs(1);
	//for(int i=1;i<=n;i++) cout<<p[i]<<" ";
	//cout<<"p\n";
	int Q;cin>>Q;
	while(Q--){
		int t; cin>>t;
		if(t==1){
			int x,d,w;cin>>x>>d>>w;	
			int i = 0;
			for(;i<=d && x!=1;i++,x=p[x]){
				app[x][d-i] = (1LL*app[x][d-i]*w)%L;
				if(d-i>0) app[x][d-i-1] = (1LL*app[x][d-i-1]*w)%L;
			}
			for(;i<=d;i++) app[x][d-i] = (1LL*app[x][d-i]*w)%L;
			//debug();
		}else{
			int x;cin>>x;
			int rans = ans[x];
			bool works = 0;
			for(int i=0;i<=40;i++){
				if(works==1) break;
				if(x==1) works=1;
				rans = (1LL*rans*app[x][i])%L;
				x = p[x];
			}
			cout<<rans<<"\n";
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6628 KB Output is correct
8 Correct 2 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6592 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6628 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6488 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 1 ms 6624 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 2 ms 6644 KB Output is correct
24 Correct 2 ms 6620 KB Output is correct
25 Correct 1 ms 6488 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 2 ms 6488 KB Output is correct
28 Correct 1 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 355 ms 53988 KB Output is correct
3 Correct 235 ms 52308 KB Output is correct
4 Correct 347 ms 55676 KB Output is correct
5 Correct 288 ms 53072 KB Output is correct
6 Correct 260 ms 52724 KB Output is correct
7 Correct 222 ms 53320 KB Output is correct
8 Correct 183 ms 53944 KB Output is correct
9 Correct 487 ms 58052 KB Output is correct
10 Correct 242 ms 56148 KB Output is correct
11 Correct 339 ms 53844 KB Output is correct
12 Correct 248 ms 52312 KB Output is correct
13 Correct 171 ms 52872 KB Output is correct
14 Correct 183 ms 52936 KB Output is correct
15 Correct 163 ms 52688 KB Output is correct
16 Correct 176 ms 53072 KB Output is correct
17 Correct 172 ms 53416 KB Output is correct
18 Correct 1 ms 6488 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 1 ms 6576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 355 ms 53988 KB Output is correct
3 Correct 235 ms 52308 KB Output is correct
4 Correct 347 ms 55676 KB Output is correct
5 Correct 288 ms 53072 KB Output is correct
6 Correct 260 ms 52724 KB Output is correct
7 Correct 222 ms 53320 KB Output is correct
8 Correct 183 ms 53944 KB Output is correct
9 Correct 487 ms 58052 KB Output is correct
10 Correct 242 ms 56148 KB Output is correct
11 Correct 339 ms 53844 KB Output is correct
12 Correct 248 ms 52312 KB Output is correct
13 Correct 171 ms 52872 KB Output is correct
14 Correct 183 ms 52936 KB Output is correct
15 Correct 163 ms 52688 KB Output is correct
16 Correct 176 ms 53072 KB Output is correct
17 Correct 172 ms 53416 KB Output is correct
18 Correct 1 ms 6488 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 1 ms 6576 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 344 ms 53756 KB Output is correct
25 Correct 259 ms 58124 KB Output is correct
26 Correct 352 ms 61996 KB Output is correct
27 Correct 279 ms 57804 KB Output is correct
28 Correct 229 ms 58208 KB Output is correct
29 Correct 217 ms 57684 KB Output is correct
30 Correct 199 ms 58692 KB Output is correct
31 Correct 459 ms 60716 KB Output is correct
32 Correct 257 ms 62036 KB Output is correct
33 Correct 380 ms 57652 KB Output is correct
34 Correct 227 ms 58196 KB Output is correct
35 Correct 1 ms 6488 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 1 ms 6628 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6584 KB Output is correct
41 Correct 1 ms 6592 KB Output is correct
42 Correct 1 ms 6488 KB Output is correct
43 Correct 1 ms 6492 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Correct 1 ms 6492 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 525 ms 55160 KB Output is correct
3 Correct 573 ms 58704 KB Output is correct
4 Correct 425 ms 58192 KB Output is correct
5 Correct 357 ms 54864 KB Output is correct
6 Correct 239 ms 55136 KB Output is correct
7 Correct 227 ms 55176 KB Output is correct
8 Correct 185 ms 55752 KB Output is correct
9 Correct 495 ms 57820 KB Output is correct
10 Correct 539 ms 58964 KB Output is correct
11 Correct 341 ms 54540 KB Output is correct
12 Correct 419 ms 55636 KB Output is correct
13 Correct 295 ms 56300 KB Output is correct
14 Correct 302 ms 56784 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 512 ms 56580 KB Output is correct
3 Correct 564 ms 57816 KB Output is correct
4 Correct 430 ms 58960 KB Output is correct
5 Correct 330 ms 56508 KB Output is correct
6 Correct 260 ms 56592 KB Output is correct
7 Correct 247 ms 56404 KB Output is correct
8 Correct 188 ms 56772 KB Output is correct
9 Correct 499 ms 61260 KB Output is correct
10 Correct 571 ms 59816 KB Output is correct
11 Correct 353 ms 57188 KB Output is correct
12 Correct 373 ms 55612 KB Output is correct
13 Correct 314 ms 56532 KB Output is correct
14 Correct 299 ms 57036 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6488 KB Output is correct
19 Correct 1 ms 6744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6628 KB Output is correct
8 Correct 2 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6592 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6628 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6488 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 1 ms 6624 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 2 ms 6644 KB Output is correct
24 Correct 2 ms 6620 KB Output is correct
25 Correct 1 ms 6488 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 2 ms 6488 KB Output is correct
28 Correct 1 ms 6488 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 355 ms 53988 KB Output is correct
31 Correct 235 ms 52308 KB Output is correct
32 Correct 347 ms 55676 KB Output is correct
33 Correct 288 ms 53072 KB Output is correct
34 Correct 260 ms 52724 KB Output is correct
35 Correct 222 ms 53320 KB Output is correct
36 Correct 183 ms 53944 KB Output is correct
37 Correct 487 ms 58052 KB Output is correct
38 Correct 242 ms 56148 KB Output is correct
39 Correct 339 ms 53844 KB Output is correct
40 Correct 248 ms 52312 KB Output is correct
41 Correct 171 ms 52872 KB Output is correct
42 Correct 183 ms 52936 KB Output is correct
43 Correct 163 ms 52688 KB Output is correct
44 Correct 176 ms 53072 KB Output is correct
45 Correct 172 ms 53416 KB Output is correct
46 Correct 1 ms 6488 KB Output is correct
47 Correct 2 ms 6492 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 2 ms 6492 KB Output is correct
50 Correct 1 ms 6576 KB Output is correct
51 Correct 1 ms 6492 KB Output is correct
52 Correct 344 ms 53756 KB Output is correct
53 Correct 259 ms 58124 KB Output is correct
54 Correct 352 ms 61996 KB Output is correct
55 Correct 279 ms 57804 KB Output is correct
56 Correct 229 ms 58208 KB Output is correct
57 Correct 217 ms 57684 KB Output is correct
58 Correct 199 ms 58692 KB Output is correct
59 Correct 459 ms 60716 KB Output is correct
60 Correct 257 ms 62036 KB Output is correct
61 Correct 380 ms 57652 KB Output is correct
62 Correct 227 ms 58196 KB Output is correct
63 Correct 1 ms 6488 KB Output is correct
64 Correct 1 ms 6492 KB Output is correct
65 Correct 1 ms 6492 KB Output is correct
66 Correct 1 ms 6628 KB Output is correct
67 Correct 1 ms 6492 KB Output is correct
68 Correct 1 ms 6584 KB Output is correct
69 Correct 1 ms 6592 KB Output is correct
70 Correct 1 ms 6488 KB Output is correct
71 Correct 1 ms 6492 KB Output is correct
72 Correct 1 ms 6492 KB Output is correct
73 Correct 1 ms 6492 KB Output is correct
74 Correct 2 ms 6492 KB Output is correct
75 Correct 1 ms 6492 KB Output is correct
76 Correct 1 ms 6492 KB Output is correct
77 Correct 1 ms 6492 KB Output is correct
78 Correct 1 ms 6744 KB Output is correct
79 Correct 525 ms 55160 KB Output is correct
80 Correct 573 ms 58704 KB Output is correct
81 Correct 425 ms 58192 KB Output is correct
82 Correct 357 ms 54864 KB Output is correct
83 Correct 239 ms 55136 KB Output is correct
84 Correct 227 ms 55176 KB Output is correct
85 Correct 185 ms 55752 KB Output is correct
86 Correct 495 ms 57820 KB Output is correct
87 Correct 539 ms 58964 KB Output is correct
88 Correct 341 ms 54540 KB Output is correct
89 Correct 419 ms 55636 KB Output is correct
90 Correct 295 ms 56300 KB Output is correct
91 Correct 302 ms 56784 KB Output is correct
92 Correct 2 ms 6492 KB Output is correct
93 Correct 2 ms 6492 KB Output is correct
94 Correct 1 ms 6492 KB Output is correct
95 Correct 1 ms 6492 KB Output is correct
96 Correct 1 ms 6620 KB Output is correct
97 Correct 1 ms 6492 KB Output is correct
98 Correct 512 ms 56580 KB Output is correct
99 Correct 564 ms 57816 KB Output is correct
100 Correct 430 ms 58960 KB Output is correct
101 Correct 330 ms 56508 KB Output is correct
102 Correct 260 ms 56592 KB Output is correct
103 Correct 247 ms 56404 KB Output is correct
104 Correct 188 ms 56772 KB Output is correct
105 Correct 499 ms 61260 KB Output is correct
106 Correct 571 ms 59816 KB Output is correct
107 Correct 353 ms 57188 KB Output is correct
108 Correct 373 ms 55612 KB Output is correct
109 Correct 314 ms 56532 KB Output is correct
110 Correct 299 ms 57036 KB Output is correct
111 Correct 2 ms 6488 KB Output is correct
112 Correct 1 ms 6492 KB Output is correct
113 Correct 1 ms 6492 KB Output is correct
114 Correct 1 ms 6488 KB Output is correct
115 Correct 1 ms 6744 KB Output is correct
116 Correct 429 ms 55592 KB Output is correct
117 Correct 494 ms 58192 KB Output is correct
118 Correct 539 ms 61780 KB Output is correct
119 Correct 429 ms 57924 KB Output is correct
120 Correct 357 ms 57812 KB Output is correct
121 Correct 340 ms 58412 KB Output is correct
122 Correct 251 ms 58568 KB Output is correct
123 Correct 651 ms 61044 KB Output is correct
124 Correct 794 ms 60580 KB Output is correct
125 Correct 456 ms 56656 KB Output is correct
126 Correct 500 ms 58292 KB Output is correct
127 Correct 488 ms 58544 KB Output is correct
128 Correct 421 ms 59308 KB Output is correct
129 Correct 437 ms 60004 KB Output is correct