Submission #785307

# Submission time Handle Problem Language Result Execution time Memory
785307 2023-07-17T08:14:28 Z TakeMe Sprinkler (JOI22_sprinkler) C++14
38 / 100
308 ms 39380 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][5];
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);
}



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 < 5; 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;
			ll ans = a[x] * mul[x][0] % l;
			if(par[x] == 1){
				ans = (ans * mul[par[x]][1]) % l;
				//ans = (ans * mul[par[x]][2]) % l;
			}
			else if(par[x] == 0){
				//ans = (ans * mul[x][1]) % l;
				//ans = (ans * mul[x][2]) % l;
			}
			else{
				ans = (ans * mul[par[x]][1]) % l;
				//ans = (ans * mul[par[par[x]]][2]) % l;
				ans = (ans * mul[par[par[x]]][2]) % l;
				
			}
			cout << ans << '\n';
		}
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 255 ms 26760 KB Output is correct
3 Correct 215 ms 23628 KB Output is correct
4 Correct 262 ms 27756 KB Output is correct
5 Correct 219 ms 25228 KB Output is correct
6 Correct 232 ms 25172 KB Output is correct
7 Correct 198 ms 25552 KB Output is correct
8 Correct 172 ms 25752 KB Output is correct
9 Correct 308 ms 31012 KB Output is correct
10 Correct 224 ms 27504 KB Output is correct
11 Correct 214 ms 26948 KB Output is correct
12 Correct 280 ms 23604 KB Output is correct
13 Correct 177 ms 30968 KB Output is correct
14 Correct 181 ms 36068 KB Output is correct
15 Correct 191 ms 35336 KB Output is correct
16 Correct 171 ms 35952 KB Output is correct
17 Correct 189 ms 36476 KB Output is correct
18 Correct 3 ms 5044 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5040 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 3 ms 4948 KB Output is correct
2 Correct 255 ms 26760 KB Output is correct
3 Correct 215 ms 23628 KB Output is correct
4 Correct 262 ms 27756 KB Output is correct
5 Correct 219 ms 25228 KB Output is correct
6 Correct 232 ms 25172 KB Output is correct
7 Correct 198 ms 25552 KB Output is correct
8 Correct 172 ms 25752 KB Output is correct
9 Correct 308 ms 31012 KB Output is correct
10 Correct 224 ms 27504 KB Output is correct
11 Correct 214 ms 26948 KB Output is correct
12 Correct 280 ms 23604 KB Output is correct
13 Correct 177 ms 30968 KB Output is correct
14 Correct 181 ms 36068 KB Output is correct
15 Correct 191 ms 35336 KB Output is correct
16 Correct 171 ms 35952 KB Output is correct
17 Correct 189 ms 36476 KB Output is correct
18 Correct 3 ms 5044 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5040 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 5036 KB Output is correct
24 Correct 195 ms 35076 KB Output is correct
25 Correct 229 ms 35636 KB Output is correct
26 Correct 219 ms 39380 KB Output is correct
27 Correct 218 ms 35256 KB Output is correct
28 Correct 228 ms 35456 KB Output is correct
29 Correct 207 ms 35172 KB Output is correct
30 Correct 170 ms 35900 KB Output is correct
31 Correct 230 ms 37776 KB Output is correct
32 Correct 220 ms 39336 KB Output is correct
33 Correct 212 ms 35020 KB Output is correct
34 Correct 209 ms 35596 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 5044 KB Output is correct
37 Correct 6 ms 5032 KB Output is correct
38 Correct 3 ms 5048 KB Output is correct
39 Correct 3 ms 5052 KB Output is correct
40 Correct 3 ms 5044 KB Output is correct
41 Correct 3 ms 4948 KB Output is correct
42 Correct 3 ms 4988 KB Output is correct
43 Correct 4 ms 5084 KB Output is correct
44 Correct 3 ms 5044 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 5040 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 2 ms 4948 KB Output is correct
2 Incorrect 213 ms 28572 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -