Submission #892473

# Submission time Handle Problem Language Result Execution time Memory
892473 2023-12-25T11:43:23 Z Minbaev Sprinkler (JOI22_sprinkler) C++17
100 / 100
601 ms 117028 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("Ofast,unroll-loops")
#define pii pair<int,int>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
#define f first
#define s second
#define pii pair<int,int>
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
	tree_order_statistics_node_update> ordered_set;
const int mod= 1e9 +7;
const int N=1e5*4;

int binpow (int a, int n) {
	if (n == 0)
		return 1;
	if (n % 2 == 1)
		return binpow (a, n-1) * a;
	else {
		int b = binpow (a, n/2);
		return b * b;
	}
}
int n,m,k,l;
vector<int>v[N],pr(N);
int dp[N][50];

void dfs(int x,int prad){
	pr[x] = prad;
	for(auto to:v[x]){
		if(prad==to)continue;
		dfs(to,x);
	}
	return;
}

int md(int a,int b)	{
	return (a*b)%l;
}
	


void solve(){
	
	cin>>n>>l;
	
	for(int i = 0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	
	for(int i = 1;i<=n;i++){
		for(int j = 0;j<41;j++){
			dp[i][j] = 1;
		}
	}
	
	for(int i = 1;i<=n;i++){
		int a;
		cin>>a;
		dp[i][0] = a;
	}
	
	dfs(1,-1);
	int q;
	cin>>q;
	//~ cout<<pr[2]<<endl;
	while(q--){
		int a,x,dist,cst;
		cin>>a>>x;
		if(a==1){
			cin>>dist>>cst;
			while(true){
				dp[x][dist] = md(dp[x][dist],cst);	
				if(dist-- == 0)break;
				//~ cout<<x<<" "<<dist<<endl;
				dp[x][dist] = md(dp[x][dist],cst);
				if(x>1)x = pr[x];
				else if(dist--==0)break;
			}
		
		}
		else{
			int ans = 1;
			for(int d = 0;d<=40&&x>0;d++,x = pr[x])
				ans = md(ans,dp[x][d]);
			cout<<ans<<"\n";
		}
		
		
	}
	
}

 signed main()
{
//	freopen("seq.in", "r", stdin);
//  freopen("seq.out", "w", stdout);
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int tt=1;//cin>>tt;
	while(tt--)solve();

}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 13404 KB Output is correct
2 Correct 4 ms 13404 KB Output is correct
3 Correct 4 ms 13404 KB Output is correct
4 Correct 4 ms 15708 KB Output is correct
5 Correct 5 ms 15708 KB Output is correct
6 Correct 5 ms 15548 KB Output is correct
7 Correct 5 ms 15704 KB Output is correct
8 Correct 5 ms 15708 KB Output is correct
9 Correct 4 ms 13404 KB Output is correct
10 Correct 4 ms 13656 KB Output is correct
11 Correct 4 ms 13404 KB Output is correct
12 Correct 4 ms 13404 KB Output is correct
13 Correct 5 ms 13656 KB Output is correct
14 Correct 4 ms 13404 KB Output is correct
15 Correct 4 ms 13404 KB Output is correct
16 Correct 3 ms 13404 KB Output is correct
17 Correct 4 ms 13400 KB Output is correct
18 Correct 3 ms 13404 KB Output is correct
19 Correct 4 ms 13404 KB Output is correct
20 Correct 5 ms 13400 KB Output is correct
21 Correct 4 ms 13404 KB Output is correct
22 Correct 4 ms 13404 KB Output is correct
23 Correct 4 ms 13400 KB Output is correct
24 Correct 4 ms 13404 KB Output is correct
25 Correct 4 ms 13404 KB Output is correct
26 Correct 4 ms 13404 KB Output is correct
27 Correct 4 ms 13404 KB Output is correct
28 Correct 5 ms 13404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 13404 KB Output is correct
2 Correct 398 ms 112028 KB Output is correct
3 Correct 283 ms 111956 KB Output is correct
4 Correct 361 ms 114512 KB Output is correct
5 Correct 323 ms 111956 KB Output is correct
6 Correct 243 ms 111956 KB Output is correct
7 Correct 224 ms 112464 KB Output is correct
8 Correct 195 ms 112468 KB Output is correct
9 Correct 448 ms 116048 KB Output is correct
10 Correct 276 ms 115896 KB Output is correct
11 Correct 374 ms 111932 KB Output is correct
12 Correct 270 ms 112212 KB Output is correct
13 Correct 167 ms 112420 KB Output is correct
14 Correct 172 ms 112332 KB Output is correct
15 Correct 170 ms 112164 KB Output is correct
16 Correct 171 ms 112212 KB Output is correct
17 Correct 179 ms 112828 KB Output is correct
18 Correct 4 ms 13404 KB Output is correct
19 Correct 5 ms 13404 KB Output is correct
20 Correct 3 ms 13404 KB Output is correct
21 Correct 4 ms 13404 KB Output is correct
22 Correct 4 ms 13404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 13404 KB Output is correct
2 Correct 398 ms 112028 KB Output is correct
3 Correct 283 ms 111956 KB Output is correct
4 Correct 361 ms 114512 KB Output is correct
5 Correct 323 ms 111956 KB Output is correct
6 Correct 243 ms 111956 KB Output is correct
7 Correct 224 ms 112464 KB Output is correct
8 Correct 195 ms 112468 KB Output is correct
9 Correct 448 ms 116048 KB Output is correct
10 Correct 276 ms 115896 KB Output is correct
11 Correct 374 ms 111932 KB Output is correct
12 Correct 270 ms 112212 KB Output is correct
13 Correct 167 ms 112420 KB Output is correct
14 Correct 172 ms 112332 KB Output is correct
15 Correct 170 ms 112164 KB Output is correct
16 Correct 171 ms 112212 KB Output is correct
17 Correct 179 ms 112828 KB Output is correct
18 Correct 4 ms 13404 KB Output is correct
19 Correct 5 ms 13404 KB Output is correct
20 Correct 3 ms 13404 KB Output is correct
21 Correct 4 ms 13404 KB Output is correct
22 Correct 4 ms 13404 KB Output is correct
23 Correct 4 ms 13404 KB Output is correct
24 Correct 389 ms 111956 KB Output is correct
25 Correct 275 ms 113492 KB Output is correct
26 Correct 374 ms 117028 KB Output is correct
27 Correct 324 ms 112724 KB Output is correct
28 Correct 235 ms 113012 KB Output is correct
29 Correct 229 ms 113084 KB Output is correct
30 Correct 188 ms 113580 KB Output is correct
31 Correct 456 ms 115668 KB Output is correct
32 Correct 283 ms 116816 KB Output is correct
33 Correct 351 ms 113020 KB Output is correct
34 Correct 251 ms 113096 KB Output is correct
35 Correct 3 ms 13404 KB Output is correct
36 Correct 4 ms 13404 KB Output is correct
37 Correct 4 ms 13404 KB Output is correct
38 Correct 4 ms 13404 KB Output is correct
39 Correct 3 ms 13432 KB Output is correct
40 Correct 4 ms 13324 KB Output is correct
41 Correct 5 ms 13404 KB Output is correct
42 Correct 4 ms 13404 KB Output is correct
43 Correct 4 ms 13404 KB Output is correct
44 Correct 3 ms 13404 KB Output is correct
45 Correct 4 ms 13404 KB Output is correct
46 Correct 3 ms 13404 KB Output is correct
47 Correct 4 ms 13404 KB Output is correct
48 Correct 4 ms 13404 KB Output is correct
49 Correct 4 ms 13404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 13404 KB Output is correct
2 Correct 475 ms 113092 KB Output is correct
3 Correct 601 ms 112976 KB Output is correct
4 Correct 450 ms 112468 KB Output is correct
5 Correct 370 ms 109296 KB Output is correct
6 Correct 257 ms 109796 KB Output is correct
7 Correct 242 ms 110164 KB Output is correct
8 Correct 195 ms 110528 KB Output is correct
9 Correct 487 ms 112832 KB Output is correct
10 Correct 595 ms 113968 KB Output is correct
11 Correct 398 ms 109652 KB Output is correct
12 Correct 424 ms 110420 KB Output is correct
13 Correct 314 ms 111208 KB Output is correct
14 Correct 312 ms 112128 KB Output is correct
15 Correct 3 ms 13400 KB Output is correct
16 Correct 3 ms 13404 KB Output is correct
17 Correct 3 ms 13404 KB Output is correct
18 Correct 3 ms 13404 KB Output is correct
19 Correct 4 ms 13404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 13404 KB Output is correct
2 Correct 479 ms 113480 KB Output is correct
3 Correct 581 ms 112084 KB Output is correct
4 Correct 419 ms 112752 KB Output is correct
5 Correct 363 ms 110676 KB Output is correct
6 Correct 286 ms 111444 KB Output is correct
7 Correct 269 ms 111556 KB Output is correct
8 Correct 199 ms 111556 KB Output is correct
9 Correct 497 ms 116064 KB Output is correct
10 Correct 579 ms 114812 KB Output is correct
11 Correct 386 ms 112212 KB Output is correct
12 Correct 449 ms 110740 KB Output is correct
13 Correct 343 ms 111548 KB Output is correct
14 Correct 337 ms 112060 KB Output is correct
15 Correct 3 ms 13404 KB Output is correct
16 Correct 3 ms 13404 KB Output is correct
17 Correct 4 ms 13404 KB Output is correct
18 Correct 4 ms 13404 KB Output is correct
19 Correct 3 ms 13404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 13404 KB Output is correct
2 Correct 4 ms 13404 KB Output is correct
3 Correct 4 ms 13404 KB Output is correct
4 Correct 4 ms 15708 KB Output is correct
5 Correct 5 ms 15708 KB Output is correct
6 Correct 5 ms 15548 KB Output is correct
7 Correct 5 ms 15704 KB Output is correct
8 Correct 5 ms 15708 KB Output is correct
9 Correct 4 ms 13404 KB Output is correct
10 Correct 4 ms 13656 KB Output is correct
11 Correct 4 ms 13404 KB Output is correct
12 Correct 4 ms 13404 KB Output is correct
13 Correct 5 ms 13656 KB Output is correct
14 Correct 4 ms 13404 KB Output is correct
15 Correct 4 ms 13404 KB Output is correct
16 Correct 3 ms 13404 KB Output is correct
17 Correct 4 ms 13400 KB Output is correct
18 Correct 3 ms 13404 KB Output is correct
19 Correct 4 ms 13404 KB Output is correct
20 Correct 5 ms 13400 KB Output is correct
21 Correct 4 ms 13404 KB Output is correct
22 Correct 4 ms 13404 KB Output is correct
23 Correct 4 ms 13400 KB Output is correct
24 Correct 4 ms 13404 KB Output is correct
25 Correct 4 ms 13404 KB Output is correct
26 Correct 4 ms 13404 KB Output is correct
27 Correct 4 ms 13404 KB Output is correct
28 Correct 5 ms 13404 KB Output is correct
29 Correct 5 ms 13404 KB Output is correct
30 Correct 398 ms 112028 KB Output is correct
31 Correct 283 ms 111956 KB Output is correct
32 Correct 361 ms 114512 KB Output is correct
33 Correct 323 ms 111956 KB Output is correct
34 Correct 243 ms 111956 KB Output is correct
35 Correct 224 ms 112464 KB Output is correct
36 Correct 195 ms 112468 KB Output is correct
37 Correct 448 ms 116048 KB Output is correct
38 Correct 276 ms 115896 KB Output is correct
39 Correct 374 ms 111932 KB Output is correct
40 Correct 270 ms 112212 KB Output is correct
41 Correct 167 ms 112420 KB Output is correct
42 Correct 172 ms 112332 KB Output is correct
43 Correct 170 ms 112164 KB Output is correct
44 Correct 171 ms 112212 KB Output is correct
45 Correct 179 ms 112828 KB Output is correct
46 Correct 4 ms 13404 KB Output is correct
47 Correct 5 ms 13404 KB Output is correct
48 Correct 3 ms 13404 KB Output is correct
49 Correct 4 ms 13404 KB Output is correct
50 Correct 4 ms 13404 KB Output is correct
51 Correct 4 ms 13404 KB Output is correct
52 Correct 389 ms 111956 KB Output is correct
53 Correct 275 ms 113492 KB Output is correct
54 Correct 374 ms 117028 KB Output is correct
55 Correct 324 ms 112724 KB Output is correct
56 Correct 235 ms 113012 KB Output is correct
57 Correct 229 ms 113084 KB Output is correct
58 Correct 188 ms 113580 KB Output is correct
59 Correct 456 ms 115668 KB Output is correct
60 Correct 283 ms 116816 KB Output is correct
61 Correct 351 ms 113020 KB Output is correct
62 Correct 251 ms 113096 KB Output is correct
63 Correct 3 ms 13404 KB Output is correct
64 Correct 4 ms 13404 KB Output is correct
65 Correct 4 ms 13404 KB Output is correct
66 Correct 4 ms 13404 KB Output is correct
67 Correct 3 ms 13432 KB Output is correct
68 Correct 4 ms 13324 KB Output is correct
69 Correct 5 ms 13404 KB Output is correct
70 Correct 4 ms 13404 KB Output is correct
71 Correct 4 ms 13404 KB Output is correct
72 Correct 3 ms 13404 KB Output is correct
73 Correct 4 ms 13404 KB Output is correct
74 Correct 3 ms 13404 KB Output is correct
75 Correct 4 ms 13404 KB Output is correct
76 Correct 4 ms 13404 KB Output is correct
77 Correct 4 ms 13404 KB Output is correct
78 Correct 4 ms 13404 KB Output is correct
79 Correct 475 ms 113092 KB Output is correct
80 Correct 601 ms 112976 KB Output is correct
81 Correct 450 ms 112468 KB Output is correct
82 Correct 370 ms 109296 KB Output is correct
83 Correct 257 ms 109796 KB Output is correct
84 Correct 242 ms 110164 KB Output is correct
85 Correct 195 ms 110528 KB Output is correct
86 Correct 487 ms 112832 KB Output is correct
87 Correct 595 ms 113968 KB Output is correct
88 Correct 398 ms 109652 KB Output is correct
89 Correct 424 ms 110420 KB Output is correct
90 Correct 314 ms 111208 KB Output is correct
91 Correct 312 ms 112128 KB Output is correct
92 Correct 3 ms 13400 KB Output is correct
93 Correct 3 ms 13404 KB Output is correct
94 Correct 3 ms 13404 KB Output is correct
95 Correct 3 ms 13404 KB Output is correct
96 Correct 4 ms 13404 KB Output is correct
97 Correct 3 ms 13404 KB Output is correct
98 Correct 479 ms 113480 KB Output is correct
99 Correct 581 ms 112084 KB Output is correct
100 Correct 419 ms 112752 KB Output is correct
101 Correct 363 ms 110676 KB Output is correct
102 Correct 286 ms 111444 KB Output is correct
103 Correct 269 ms 111556 KB Output is correct
104 Correct 199 ms 111556 KB Output is correct
105 Correct 497 ms 116064 KB Output is correct
106 Correct 579 ms 114812 KB Output is correct
107 Correct 386 ms 112212 KB Output is correct
108 Correct 449 ms 110740 KB Output is correct
109 Correct 343 ms 111548 KB Output is correct
110 Correct 337 ms 112060 KB Output is correct
111 Correct 3 ms 13404 KB Output is correct
112 Correct 3 ms 13404 KB Output is correct
113 Correct 4 ms 13404 KB Output is correct
114 Correct 4 ms 13404 KB Output is correct
115 Correct 3 ms 13404 KB Output is correct
116 Correct 452 ms 110556 KB Output is correct
117 Correct 498 ms 113268 KB Output is correct
118 Correct 515 ms 116892 KB Output is correct
119 Correct 436 ms 112956 KB Output is correct
120 Correct 318 ms 112464 KB Output is correct
121 Correct 338 ms 113356 KB Output is correct
122 Correct 230 ms 113472 KB Output is correct
123 Correct 461 ms 116012 KB Output is correct
124 Correct 597 ms 115092 KB Output is correct
125 Correct 400 ms 111696 KB Output is correct
126 Correct 487 ms 112980 KB Output is correct
127 Correct 571 ms 113484 KB Output is correct
128 Correct 479 ms 114148 KB Output is correct
129 Correct 487 ms 115172 KB Output is correct