Submission #785342

# Submission time Handle Problem Language Result Execution time Memory
785342 2023-07-17T08:35:45 Z TakeMe Sprinkler (JOI22_sprinkler) C++14
100 / 100
836 ms 117652 KB
/* Quick Note :
 * Jangan Mikir Lama - lama, sampahin dulu aja kalo OI
 * Always Try to reset
*/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ld PI = 4*atan((ld)1);
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll nax = 2e5 + 5;

ll n, q, l;
ll a[nax], isZero[nax], par[nax];
ll mul[nax][55];
vector<vector<ll>> v(nax);

void find_par(ll idx, ll bfr){
	par[idx] = bfr;
	for(auto it : v[idx]){
		if(it != bfr){
			find_par(it, idx);
		}
	}
}

void upd_val(ll x, ll d, ll w){
	if(d < 0 || x == 0) return;
	if(x == 1){
		for(ll i = d; i >= 0; i--) mul[x][i] = (mul[x][i] * w) % l;
		return;
	}
	mul[x][d] *= w;
	mul[x][d] %= l;
	if(d - 1 >= 0){
		mul[x][d-1] *= w;
		mul[x][d-1] %= l;
	}
	upd_val(par[x], d - 1, w);
}

ll que_val(ll idx, ll d){
	if(idx == 0 || d > 45) return 1;
	return mul[idx][d] * que_val(par[idx], d + 1) % l;
}

int main(){ 
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    
    cin >> n >> l;
    for(ll i = 1; i <= n; i++){
		for(ll j = 0; j <= 45; j++){
			mul[i][j] = 1;
		}
	}
    for(ll i = 1; i < n; i++){
		ll x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
    for(ll i = 1; i <= n; i++){
		cin >> a[i];
	}
	find_par(1, 0);
	cin >> q;
	while(q--){
		ll tp, x, d, w;
		cin >> tp;
		if(tp == 1){
			cin >> x >> d >> w;
			upd_val(x, d, w);
		}
		else{
			cin >> x;
			cout << a[x] * que_val(x, 0) % l << '\n';
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 5460 KB Output is correct
5 Correct 3 ms 5460 KB Output is correct
6 Correct 3 ms 5460 KB Output is correct
7 Correct 3 ms 5508 KB Output is correct
8 Correct 3 ms 5460 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 4 ms 5028 KB Output is correct
16 Correct 3 ms 5060 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 5036 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 4 ms 4944 KB Output is correct
26 Correct 3 ms 5052 KB Output is correct
27 Correct 2 ms 4948 KB Output is correct
28 Correct 2 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5032 KB Output is correct
2 Correct 610 ms 105076 KB Output is correct
3 Correct 333 ms 101964 KB Output is correct
4 Correct 517 ms 106032 KB Output is correct
5 Correct 496 ms 103508 KB Output is correct
6 Correct 353 ms 103424 KB Output is correct
7 Correct 322 ms 103924 KB Output is correct
8 Correct 268 ms 104012 KB Output is correct
9 Correct 770 ms 109292 KB Output is correct
10 Correct 353 ms 105804 KB Output is correct
11 Correct 700 ms 105060 KB Output is correct
12 Correct 384 ms 101860 KB Output is correct
13 Correct 248 ms 102332 KB Output is correct
14 Correct 214 ms 102300 KB Output is correct
15 Correct 240 ms 102156 KB Output is correct
16 Correct 285 ms 102248 KB Output is correct
17 Correct 297 ms 102776 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5032 KB Output is correct
2 Correct 610 ms 105076 KB Output is correct
3 Correct 333 ms 101964 KB Output is correct
4 Correct 517 ms 106032 KB Output is correct
5 Correct 496 ms 103508 KB Output is correct
6 Correct 353 ms 103424 KB Output is correct
7 Correct 322 ms 103924 KB Output is correct
8 Correct 268 ms 104012 KB Output is correct
9 Correct 770 ms 109292 KB Output is correct
10 Correct 353 ms 105804 KB Output is correct
11 Correct 700 ms 105060 KB Output is correct
12 Correct 384 ms 101860 KB Output is correct
13 Correct 248 ms 102332 KB Output is correct
14 Correct 214 ms 102300 KB Output is correct
15 Correct 240 ms 102156 KB Output is correct
16 Correct 285 ms 102248 KB Output is correct
17 Correct 297 ms 102776 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 716 ms 105096 KB Output is correct
25 Correct 441 ms 101896 KB Output is correct
26 Correct 592 ms 107632 KB Output is correct
27 Correct 471 ms 103468 KB Output is correct
28 Correct 409 ms 103640 KB Output is correct
29 Correct 373 ms 103724 KB Output is correct
30 Correct 233 ms 103968 KB Output is correct
31 Correct 725 ms 107776 KB Output is correct
32 Correct 373 ms 105772 KB Output is correct
33 Correct 644 ms 105064 KB Output is correct
34 Correct 416 ms 101980 KB Output is correct
35 Correct 3 ms 4992 KB Output is correct
36 Correct 3 ms 4992 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 4 ms 4964 KB Output is correct
41 Correct 2 ms 4948 KB Output is correct
42 Correct 2 ms 4948 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 3 ms 4948 KB Output is correct
45 Correct 2 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 2 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 2 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 836 ms 106684 KB Output is correct
3 Correct 792 ms 104608 KB Output is correct
4 Correct 752 ms 105188 KB Output is correct
5 Correct 665 ms 101920 KB Output is correct
6 Correct 327 ms 106108 KB Output is correct
7 Correct 295 ms 110932 KB Output is correct
8 Correct 251 ms 111252 KB Output is correct
9 Correct 805 ms 113096 KB Output is correct
10 Correct 789 ms 114684 KB Output is correct
11 Correct 710 ms 110248 KB Output is correct
12 Correct 699 ms 111120 KB Output is correct
13 Correct 384 ms 112012 KB Output is correct
14 Correct 479 ms 112924 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5012 KB Output is correct
18 Correct 3 ms 5060 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 805 ms 107644 KB Output is correct
3 Correct 832 ms 103620 KB Output is correct
4 Correct 682 ms 105708 KB Output is correct
5 Correct 584 ms 103448 KB Output is correct
6 Correct 354 ms 107672 KB Output is correct
7 Correct 390 ms 112180 KB Output is correct
8 Correct 238 ms 112216 KB Output is correct
9 Correct 773 ms 116944 KB Output is correct
10 Correct 758 ms 115424 KB Output is correct
11 Correct 648 ms 112888 KB Output is correct
12 Correct 652 ms 111432 KB Output is correct
13 Correct 389 ms 112212 KB Output is correct
14 Correct 388 ms 113040 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 4 ms 5004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 5460 KB Output is correct
5 Correct 3 ms 5460 KB Output is correct
6 Correct 3 ms 5460 KB Output is correct
7 Correct 3 ms 5508 KB Output is correct
8 Correct 3 ms 5460 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 4 ms 5028 KB Output is correct
16 Correct 3 ms 5060 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 5036 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 4 ms 4944 KB Output is correct
26 Correct 3 ms 5052 KB Output is correct
27 Correct 2 ms 4948 KB Output is correct
28 Correct 2 ms 4948 KB Output is correct
29 Correct 4 ms 5032 KB Output is correct
30 Correct 610 ms 105076 KB Output is correct
31 Correct 333 ms 101964 KB Output is correct
32 Correct 517 ms 106032 KB Output is correct
33 Correct 496 ms 103508 KB Output is correct
34 Correct 353 ms 103424 KB Output is correct
35 Correct 322 ms 103924 KB Output is correct
36 Correct 268 ms 104012 KB Output is correct
37 Correct 770 ms 109292 KB Output is correct
38 Correct 353 ms 105804 KB Output is correct
39 Correct 700 ms 105060 KB Output is correct
40 Correct 384 ms 101860 KB Output is correct
41 Correct 248 ms 102332 KB Output is correct
42 Correct 214 ms 102300 KB Output is correct
43 Correct 240 ms 102156 KB Output is correct
44 Correct 285 ms 102248 KB Output is correct
45 Correct 297 ms 102776 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 2 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 2 ms 4948 KB Output is correct
52 Correct 716 ms 105096 KB Output is correct
53 Correct 441 ms 101896 KB Output is correct
54 Correct 592 ms 107632 KB Output is correct
55 Correct 471 ms 103468 KB Output is correct
56 Correct 409 ms 103640 KB Output is correct
57 Correct 373 ms 103724 KB Output is correct
58 Correct 233 ms 103968 KB Output is correct
59 Correct 725 ms 107776 KB Output is correct
60 Correct 373 ms 105772 KB Output is correct
61 Correct 644 ms 105064 KB Output is correct
62 Correct 416 ms 101980 KB Output is correct
63 Correct 3 ms 4992 KB Output is correct
64 Correct 3 ms 4992 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 3 ms 4948 KB Output is correct
67 Correct 3 ms 4948 KB Output is correct
68 Correct 4 ms 4964 KB Output is correct
69 Correct 2 ms 4948 KB Output is correct
70 Correct 2 ms 4948 KB Output is correct
71 Correct 3 ms 4948 KB Output is correct
72 Correct 3 ms 4948 KB Output is correct
73 Correct 2 ms 4948 KB Output is correct
74 Correct 3 ms 4948 KB Output is correct
75 Correct 2 ms 4948 KB Output is correct
76 Correct 3 ms 4948 KB Output is correct
77 Correct 2 ms 4948 KB Output is correct
78 Correct 3 ms 4948 KB Output is correct
79 Correct 836 ms 106684 KB Output is correct
80 Correct 792 ms 104608 KB Output is correct
81 Correct 752 ms 105188 KB Output is correct
82 Correct 665 ms 101920 KB Output is correct
83 Correct 327 ms 106108 KB Output is correct
84 Correct 295 ms 110932 KB Output is correct
85 Correct 251 ms 111252 KB Output is correct
86 Correct 805 ms 113096 KB Output is correct
87 Correct 789 ms 114684 KB Output is correct
88 Correct 710 ms 110248 KB Output is correct
89 Correct 699 ms 111120 KB Output is correct
90 Correct 384 ms 112012 KB Output is correct
91 Correct 479 ms 112924 KB Output is correct
92 Correct 3 ms 4948 KB Output is correct
93 Correct 3 ms 4948 KB Output is correct
94 Correct 3 ms 5012 KB Output is correct
95 Correct 3 ms 5060 KB Output is correct
96 Correct 3 ms 4948 KB Output is correct
97 Correct 2 ms 4948 KB Output is correct
98 Correct 805 ms 107644 KB Output is correct
99 Correct 832 ms 103620 KB Output is correct
100 Correct 682 ms 105708 KB Output is correct
101 Correct 584 ms 103448 KB Output is correct
102 Correct 354 ms 107672 KB Output is correct
103 Correct 390 ms 112180 KB Output is correct
104 Correct 238 ms 112216 KB Output is correct
105 Correct 773 ms 116944 KB Output is correct
106 Correct 758 ms 115424 KB Output is correct
107 Correct 648 ms 112888 KB Output is correct
108 Correct 652 ms 111432 KB Output is correct
109 Correct 389 ms 112212 KB Output is correct
110 Correct 388 ms 113040 KB Output is correct
111 Correct 3 ms 4948 KB Output is correct
112 Correct 2 ms 4948 KB Output is correct
113 Correct 3 ms 4948 KB Output is correct
114 Correct 2 ms 4948 KB Output is correct
115 Correct 4 ms 5004 KB Output is correct
116 Correct 640 ms 111320 KB Output is correct
117 Correct 610 ms 113960 KB Output is correct
118 Correct 637 ms 117652 KB Output is correct
119 Correct 595 ms 113640 KB Output is correct
120 Correct 345 ms 113224 KB Output is correct
121 Correct 352 ms 114080 KB Output is correct
122 Correct 257 ms 114144 KB Output is correct
123 Correct 754 ms 116596 KB Output is correct
124 Correct 795 ms 115828 KB Output is correct
125 Correct 682 ms 112496 KB Output is correct
126 Correct 564 ms 113784 KB Output is correct
127 Correct 609 ms 114228 KB Output is correct
128 Correct 501 ms 114936 KB Output is correct
129 Correct 488 ms 115832 KB Output is correct