답안 #956892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956892 2024-04-02T15:55:00 Z pcc Sprinkler (JOI22_sprinkler) C++17
100 / 100
705 ms 102104 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>


const int mxn = 2e5+10;
const int mxd = 45;
ll L;
ll dp[mxn][mxd];
ll arr[mxn];
int N;
vector<int> tree[mxn];
int par[mxn];

void dfs(int now){
	for(auto nxt:tree[now]){
		if(nxt == par[now])continue;
		par[nxt] = now;
		dfs(nxt);
	}
	return;
}

//d(a,p)+d(b,p) = r -> d(a,p) = r-d(b,p)
void modify(int now,int r,int val){
	int d = 0;
	while(r-d>=0&&now){
		if(!par[now]){
			for(int j = 0;j<=r-d;j++)dp[now][j] = dp[now][j]*val%L;
		}
		else{
			dp[now][r-d] = dp[now][r-d]*val%L;
			if(r-d)dp[now][r-d-1] = dp[now][r-d-1]*val%L;
		}
		now = par[now];
		d++;
	}
	return;
}

ll getans(int now){
	int d = 0;
	ll re = arr[now];
	while(d<mxd&&now){
		re = re*dp[now][d]%L;
		now = par[now];
		d++;
	}
	return re;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	for(auto &i:dp)for(auto &j:i)j = 1;
	cin>>N>>L;
	for(int i = 1;i<N;i++){
		int a,b;
		cin>>a>>b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	for(int i = 1;i<=N;i++)cin>>arr[i];
	dfs(1);
	int Q;
	cin>>Q;
	while(Q--){
		int tp;
		cin>>tp;
		if(tp == 1){
			int a,b,v;
			cin>>a>>b>>v;
			modify(a,b,v);
		}
		else{
			int k;
			cin>>k;
			cout<<getans(k)<<'\n';
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 77660 KB Output is correct
2 Correct 16 ms 77660 KB Output is correct
3 Correct 13 ms 77568 KB Output is correct
4 Correct 13 ms 77660 KB Output is correct
5 Correct 14 ms 77660 KB Output is correct
6 Correct 14 ms 77656 KB Output is correct
7 Correct 13 ms 77656 KB Output is correct
8 Correct 13 ms 77660 KB Output is correct
9 Correct 12 ms 77660 KB Output is correct
10 Correct 13 ms 77660 KB Output is correct
11 Correct 13 ms 77600 KB Output is correct
12 Correct 13 ms 77780 KB Output is correct
13 Correct 16 ms 77660 KB Output is correct
14 Correct 17 ms 77636 KB Output is correct
15 Correct 13 ms 77656 KB Output is correct
16 Correct 13 ms 77660 KB Output is correct
17 Correct 13 ms 77660 KB Output is correct
18 Correct 12 ms 77660 KB Output is correct
19 Correct 14 ms 77660 KB Output is correct
20 Correct 14 ms 77660 KB Output is correct
21 Correct 13 ms 77912 KB Output is correct
22 Correct 13 ms 77776 KB Output is correct
23 Correct 13 ms 77632 KB Output is correct
24 Correct 13 ms 77656 KB Output is correct
25 Correct 13 ms 77660 KB Output is correct
26 Correct 13 ms 77656 KB Output is correct
27 Correct 13 ms 77660 KB Output is correct
28 Correct 13 ms 77660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 77660 KB Output is correct
2 Correct 443 ms 95876 KB Output is correct
3 Correct 272 ms 96480 KB Output is correct
4 Correct 413 ms 99972 KB Output is correct
5 Correct 345 ms 96240 KB Output is correct
6 Correct 230 ms 95788 KB Output is correct
7 Correct 237 ms 96632 KB Output is correct
8 Correct 217 ms 96964 KB Output is correct
9 Correct 589 ms 101796 KB Output is correct
10 Correct 301 ms 102104 KB Output is correct
11 Correct 412 ms 95828 KB Output is correct
12 Correct 273 ms 96568 KB Output is correct
13 Correct 179 ms 96692 KB Output is correct
14 Correct 179 ms 97204 KB Output is correct
15 Correct 174 ms 96592 KB Output is correct
16 Correct 182 ms 97104 KB Output is correct
17 Correct 188 ms 97712 KB Output is correct
18 Correct 13 ms 77660 KB Output is correct
19 Correct 13 ms 77660 KB Output is correct
20 Correct 13 ms 77784 KB Output is correct
21 Correct 13 ms 77732 KB Output is correct
22 Correct 14 ms 77656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 77660 KB Output is correct
2 Correct 443 ms 95876 KB Output is correct
3 Correct 272 ms 96480 KB Output is correct
4 Correct 413 ms 99972 KB Output is correct
5 Correct 345 ms 96240 KB Output is correct
6 Correct 230 ms 95788 KB Output is correct
7 Correct 237 ms 96632 KB Output is correct
8 Correct 217 ms 96964 KB Output is correct
9 Correct 589 ms 101796 KB Output is correct
10 Correct 301 ms 102104 KB Output is correct
11 Correct 412 ms 95828 KB Output is correct
12 Correct 273 ms 96568 KB Output is correct
13 Correct 179 ms 96692 KB Output is correct
14 Correct 179 ms 97204 KB Output is correct
15 Correct 174 ms 96592 KB Output is correct
16 Correct 182 ms 97104 KB Output is correct
17 Correct 188 ms 97712 KB Output is correct
18 Correct 13 ms 77660 KB Output is correct
19 Correct 13 ms 77660 KB Output is correct
20 Correct 13 ms 77784 KB Output is correct
21 Correct 13 ms 77732 KB Output is correct
22 Correct 14 ms 77656 KB Output is correct
23 Correct 14 ms 77604 KB Output is correct
24 Correct 430 ms 96256 KB Output is correct
25 Correct 282 ms 96552 KB Output is correct
26 Correct 445 ms 101808 KB Output is correct
27 Correct 369 ms 96084 KB Output is correct
28 Correct 263 ms 96500 KB Output is correct
29 Correct 247 ms 96040 KB Output is correct
30 Correct 213 ms 97224 KB Output is correct
31 Correct 527 ms 100028 KB Output is correct
32 Correct 321 ms 101936 KB Output is correct
33 Correct 437 ms 95884 KB Output is correct
34 Correct 286 ms 96380 KB Output is correct
35 Correct 13 ms 77784 KB Output is correct
36 Correct 13 ms 77660 KB Output is correct
37 Correct 14 ms 77912 KB Output is correct
38 Correct 13 ms 77660 KB Output is correct
39 Correct 13 ms 77644 KB Output is correct
40 Correct 13 ms 77656 KB Output is correct
41 Correct 13 ms 77656 KB Output is correct
42 Correct 12 ms 77596 KB Output is correct
43 Correct 14 ms 77656 KB Output is correct
44 Correct 13 ms 77660 KB Output is correct
45 Correct 13 ms 77660 KB Output is correct
46 Correct 13 ms 77660 KB Output is correct
47 Correct 13 ms 77660 KB Output is correct
48 Correct 13 ms 77660 KB Output is correct
49 Correct 14 ms 77660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 77584 KB Output is correct
2 Correct 592 ms 99240 KB Output is correct
3 Correct 699 ms 98116 KB Output is correct
4 Correct 535 ms 97872 KB Output is correct
5 Correct 394 ms 93264 KB Output is correct
6 Correct 308 ms 93576 KB Output is correct
7 Correct 270 ms 93612 KB Output is correct
8 Correct 223 ms 94148 KB Output is correct
9 Correct 604 ms 97236 KB Output is correct
10 Correct 695 ms 99156 KB Output is correct
11 Correct 438 ms 92804 KB Output is correct
12 Correct 470 ms 93776 KB Output is correct
13 Correct 333 ms 94592 KB Output is correct
14 Correct 338 ms 95268 KB Output is correct
15 Correct 13 ms 77660 KB Output is correct
16 Correct 13 ms 77660 KB Output is correct
17 Correct 13 ms 77632 KB Output is correct
18 Correct 16 ms 77644 KB Output is correct
19 Correct 13 ms 77660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 77600 KB Output is correct
2 Correct 642 ms 99872 KB Output is correct
3 Correct 689 ms 97360 KB Output is correct
4 Correct 553 ms 98388 KB Output is correct
5 Correct 438 ms 94936 KB Output is correct
6 Correct 309 ms 94988 KB Output is correct
7 Correct 263 ms 94692 KB Output is correct
8 Correct 227 ms 95168 KB Output is correct
9 Correct 622 ms 101072 KB Output is correct
10 Correct 705 ms 99920 KB Output is correct
11 Correct 449 ms 95556 KB Output is correct
12 Correct 424 ms 93956 KB Output is correct
13 Correct 331 ms 94700 KB Output is correct
14 Correct 329 ms 95240 KB Output is correct
15 Correct 13 ms 77780 KB Output is correct
16 Correct 13 ms 77660 KB Output is correct
17 Correct 13 ms 77648 KB Output is correct
18 Correct 14 ms 77912 KB Output is correct
19 Correct 13 ms 77656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 77660 KB Output is correct
2 Correct 16 ms 77660 KB Output is correct
3 Correct 13 ms 77568 KB Output is correct
4 Correct 13 ms 77660 KB Output is correct
5 Correct 14 ms 77660 KB Output is correct
6 Correct 14 ms 77656 KB Output is correct
7 Correct 13 ms 77656 KB Output is correct
8 Correct 13 ms 77660 KB Output is correct
9 Correct 12 ms 77660 KB Output is correct
10 Correct 13 ms 77660 KB Output is correct
11 Correct 13 ms 77600 KB Output is correct
12 Correct 13 ms 77780 KB Output is correct
13 Correct 16 ms 77660 KB Output is correct
14 Correct 17 ms 77636 KB Output is correct
15 Correct 13 ms 77656 KB Output is correct
16 Correct 13 ms 77660 KB Output is correct
17 Correct 13 ms 77660 KB Output is correct
18 Correct 12 ms 77660 KB Output is correct
19 Correct 14 ms 77660 KB Output is correct
20 Correct 14 ms 77660 KB Output is correct
21 Correct 13 ms 77912 KB Output is correct
22 Correct 13 ms 77776 KB Output is correct
23 Correct 13 ms 77632 KB Output is correct
24 Correct 13 ms 77656 KB Output is correct
25 Correct 13 ms 77660 KB Output is correct
26 Correct 13 ms 77656 KB Output is correct
27 Correct 13 ms 77660 KB Output is correct
28 Correct 13 ms 77660 KB Output is correct
29 Correct 12 ms 77660 KB Output is correct
30 Correct 443 ms 95876 KB Output is correct
31 Correct 272 ms 96480 KB Output is correct
32 Correct 413 ms 99972 KB Output is correct
33 Correct 345 ms 96240 KB Output is correct
34 Correct 230 ms 95788 KB Output is correct
35 Correct 237 ms 96632 KB Output is correct
36 Correct 217 ms 96964 KB Output is correct
37 Correct 589 ms 101796 KB Output is correct
38 Correct 301 ms 102104 KB Output is correct
39 Correct 412 ms 95828 KB Output is correct
40 Correct 273 ms 96568 KB Output is correct
41 Correct 179 ms 96692 KB Output is correct
42 Correct 179 ms 97204 KB Output is correct
43 Correct 174 ms 96592 KB Output is correct
44 Correct 182 ms 97104 KB Output is correct
45 Correct 188 ms 97712 KB Output is correct
46 Correct 13 ms 77660 KB Output is correct
47 Correct 13 ms 77660 KB Output is correct
48 Correct 13 ms 77784 KB Output is correct
49 Correct 13 ms 77732 KB Output is correct
50 Correct 14 ms 77656 KB Output is correct
51 Correct 14 ms 77604 KB Output is correct
52 Correct 430 ms 96256 KB Output is correct
53 Correct 282 ms 96552 KB Output is correct
54 Correct 445 ms 101808 KB Output is correct
55 Correct 369 ms 96084 KB Output is correct
56 Correct 263 ms 96500 KB Output is correct
57 Correct 247 ms 96040 KB Output is correct
58 Correct 213 ms 97224 KB Output is correct
59 Correct 527 ms 100028 KB Output is correct
60 Correct 321 ms 101936 KB Output is correct
61 Correct 437 ms 95884 KB Output is correct
62 Correct 286 ms 96380 KB Output is correct
63 Correct 13 ms 77784 KB Output is correct
64 Correct 13 ms 77660 KB Output is correct
65 Correct 14 ms 77912 KB Output is correct
66 Correct 13 ms 77660 KB Output is correct
67 Correct 13 ms 77644 KB Output is correct
68 Correct 13 ms 77656 KB Output is correct
69 Correct 13 ms 77656 KB Output is correct
70 Correct 12 ms 77596 KB Output is correct
71 Correct 14 ms 77656 KB Output is correct
72 Correct 13 ms 77660 KB Output is correct
73 Correct 13 ms 77660 KB Output is correct
74 Correct 13 ms 77660 KB Output is correct
75 Correct 13 ms 77660 KB Output is correct
76 Correct 13 ms 77660 KB Output is correct
77 Correct 14 ms 77660 KB Output is correct
78 Correct 13 ms 77584 KB Output is correct
79 Correct 592 ms 99240 KB Output is correct
80 Correct 699 ms 98116 KB Output is correct
81 Correct 535 ms 97872 KB Output is correct
82 Correct 394 ms 93264 KB Output is correct
83 Correct 308 ms 93576 KB Output is correct
84 Correct 270 ms 93612 KB Output is correct
85 Correct 223 ms 94148 KB Output is correct
86 Correct 604 ms 97236 KB Output is correct
87 Correct 695 ms 99156 KB Output is correct
88 Correct 438 ms 92804 KB Output is correct
89 Correct 470 ms 93776 KB Output is correct
90 Correct 333 ms 94592 KB Output is correct
91 Correct 338 ms 95268 KB Output is correct
92 Correct 13 ms 77660 KB Output is correct
93 Correct 13 ms 77660 KB Output is correct
94 Correct 13 ms 77632 KB Output is correct
95 Correct 16 ms 77644 KB Output is correct
96 Correct 13 ms 77660 KB Output is correct
97 Correct 13 ms 77600 KB Output is correct
98 Correct 642 ms 99872 KB Output is correct
99 Correct 689 ms 97360 KB Output is correct
100 Correct 553 ms 98388 KB Output is correct
101 Correct 438 ms 94936 KB Output is correct
102 Correct 309 ms 94988 KB Output is correct
103 Correct 263 ms 94692 KB Output is correct
104 Correct 227 ms 95168 KB Output is correct
105 Correct 622 ms 101072 KB Output is correct
106 Correct 705 ms 99920 KB Output is correct
107 Correct 449 ms 95556 KB Output is correct
108 Correct 424 ms 93956 KB Output is correct
109 Correct 331 ms 94700 KB Output is correct
110 Correct 329 ms 95240 KB Output is correct
111 Correct 13 ms 77780 KB Output is correct
112 Correct 13 ms 77660 KB Output is correct
113 Correct 13 ms 77648 KB Output is correct
114 Correct 14 ms 77912 KB Output is correct
115 Correct 13 ms 77656 KB Output is correct
116 Correct 468 ms 94048 KB Output is correct
117 Correct 463 ms 96596 KB Output is correct
118 Correct 576 ms 101836 KB Output is correct
119 Correct 426 ms 96340 KB Output is correct
120 Correct 296 ms 95832 KB Output is correct
121 Correct 319 ms 96688 KB Output is correct
122 Correct 230 ms 96960 KB Output is correct
123 Correct 618 ms 100692 KB Output is correct
124 Correct 701 ms 99884 KB Output is correct
125 Correct 429 ms 95188 KB Output is correct
126 Correct 504 ms 96380 KB Output is correct
127 Correct 519 ms 96916 KB Output is correct
128 Correct 435 ms 97616 KB Output is correct
129 Correct 449 ms 98248 KB Output is correct