답안 #894555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894555 2023-12-28T12:43:33 Z vjudge1 Sprinkler (JOI22_sprinkler) C++14
100 / 100
701 ms 92628 KB
#include <bits/stdc++.h>
using namespace std;/*
<<<<It's never too late for a new beginning in your life>>>>
Today is hard
  tomorrow will worse
  but the day after tomorrow will be the sunshine..
 
HARD WORK BEATS TALENT WHEN TALENT DOESN'T WORK HARD............
Never give up  */
///*                                                    __                    __                        __                    */
///*        ======     _      /| /|  __   _            /   |  |   /|  |   @  |    |  |  | /   /| |\  | /   |  |  @ | /        */
///* \-       ||  |_| |_     / |/ | |  | |_  |-        |   |--|  /-|  |   |  \ \  |==|  |-   /=| | \ | |   |--|  | |-         */
///*          ||  | | |_    /     | |__|  _| |_        \__ |  | /  |  |__ |  __|  |  |  | \ /  | |  \| \__ |  |  | | \        */
///*                                                                                                                          */
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vii;
const long long N = 2e5+50, inf = 1e18, mod = 1e9+7;
vi g[N];
int pre[N];
void dfs(int i, int pr){
	pre[i] = pr;
	for(auto to:g[i])if(to!=pr)dfs(to, i);
}
void solve(){
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n-1; i++){
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(0, -1);
	int dp[n][41];
	for(auto &i:dp){
		for(auto &j:i)j = 1;
	}
	for(int i = 0; i < n; i++)cin >> dp[i][0];
	int q;
	cin >> q;
	while(q--){
		int type, x;
		cin >> type >> x;
		x--;
		if(type == 1){
			int d, c;
			cin >> d >> c;
			while(1){
				dp[x][d] = dp[x][d] * c % m;
				if(d-- == 0) break;
				dp[x][d] = dp[x][d] * c % m;
				if(x) x = pre[x];
				else if(d-- == 0) break;
			}
		}
		else{
			int ans = 1;
			for(int d = 0; d <= 40 && x >= 0; d++, x = pre[x]){
				ans = ans * dp[x][d] % m;
			}
			cout << ans << '\n';
        }
	}
}
main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int t = 1;
	//~ cin >> t;
	while(t--){
		solve();
	}
}
 
 
 

Compilation message

sprinkler.cpp:73:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   73 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6540 KB Output is correct
4 Correct 3 ms 6748 KB Output is correct
5 Correct 3 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 3 ms 6744 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6520 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 3 ms 6492 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6488 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 6544 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 2 ms 6540 KB Output is correct
28 Correct 2 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 483 ms 89972 KB Output is correct
3 Correct 327 ms 90452 KB Output is correct
4 Correct 413 ms 89004 KB Output is correct
5 Correct 390 ms 89996 KB Output is correct
6 Correct 329 ms 89608 KB Output is correct
7 Correct 265 ms 90452 KB Output is correct
8 Correct 236 ms 90816 KB Output is correct
9 Correct 483 ms 88660 KB Output is correct
10 Correct 346 ms 89196 KB Output is correct
11 Correct 424 ms 89772 KB Output is correct
12 Correct 336 ms 90232 KB Output is correct
13 Correct 195 ms 90492 KB Output is correct
14 Correct 212 ms 90808 KB Output is correct
15 Correct 204 ms 90224 KB Output is correct
16 Correct 211 ms 90800 KB Output is correct
17 Correct 218 ms 91136 KB Output is correct
18 Correct 2 ms 6488 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 483 ms 89972 KB Output is correct
3 Correct 327 ms 90452 KB Output is correct
4 Correct 413 ms 89004 KB Output is correct
5 Correct 390 ms 89996 KB Output is correct
6 Correct 329 ms 89608 KB Output is correct
7 Correct 265 ms 90452 KB Output is correct
8 Correct 236 ms 90816 KB Output is correct
9 Correct 483 ms 88660 KB Output is correct
10 Correct 346 ms 89196 KB Output is correct
11 Correct 424 ms 89772 KB Output is correct
12 Correct 336 ms 90232 KB Output is correct
13 Correct 195 ms 90492 KB Output is correct
14 Correct 212 ms 90808 KB Output is correct
15 Correct 204 ms 90224 KB Output is correct
16 Correct 211 ms 90800 KB Output is correct
17 Correct 218 ms 91136 KB Output is correct
18 Correct 2 ms 6488 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6320 KB Output is correct
24 Correct 392 ms 89956 KB Output is correct
25 Correct 316 ms 90736 KB Output is correct
26 Correct 395 ms 88944 KB Output is correct
27 Correct 342 ms 90272 KB Output is correct
28 Correct 296 ms 90196 KB Output is correct
29 Correct 308 ms 90120 KB Output is correct
30 Correct 219 ms 90816 KB Output is correct
31 Correct 493 ms 88776 KB Output is correct
32 Correct 289 ms 89340 KB Output is correct
33 Correct 430 ms 89756 KB Output is correct
34 Correct 292 ms 90452 KB Output is correct
35 Correct 2 ms 6492 KB Output is correct
36 Correct 2 ms 6488 KB Output is correct
37 Correct 2 ms 6488 KB Output is correct
38 Correct 3 ms 6492 KB Output is correct
39 Correct 2 ms 6400 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6492 KB Output is correct
44 Correct 2 ms 6492 KB Output is correct
45 Correct 2 ms 6492 KB Output is correct
46 Correct 2 ms 6488 KB Output is correct
47 Correct 2 ms 6492 KB Output is correct
48 Correct 2 ms 6492 KB Output is correct
49 Correct 2 ms 6544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 523 ms 85972 KB Output is correct
3 Correct 674 ms 86500 KB Output is correct
4 Correct 465 ms 86076 KB Output is correct
5 Correct 414 ms 87052 KB Output is correct
6 Correct 304 ms 87364 KB Output is correct
7 Correct 269 ms 87480 KB Output is correct
8 Correct 223 ms 87740 KB Output is correct
9 Correct 518 ms 85784 KB Output is correct
10 Correct 691 ms 86468 KB Output is correct
11 Correct 419 ms 86880 KB Output is correct
12 Correct 477 ms 86852 KB Output is correct
13 Correct 344 ms 88480 KB Output is correct
14 Correct 360 ms 89424 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 3 ms 6964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 576 ms 88480 KB Output is correct
3 Correct 668 ms 86988 KB Output is correct
4 Correct 538 ms 87448 KB Output is correct
5 Correct 401 ms 88620 KB Output is correct
6 Correct 294 ms 88912 KB Output is correct
7 Correct 291 ms 88764 KB Output is correct
8 Correct 226 ms 88768 KB Output is correct
9 Correct 547 ms 88844 KB Output is correct
10 Correct 701 ms 86992 KB Output is correct
11 Correct 496 ms 89492 KB Output is correct
12 Correct 442 ms 87980 KB Output is correct
13 Correct 339 ms 88656 KB Output is correct
14 Correct 367 ms 89428 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6548 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6540 KB Output is correct
4 Correct 3 ms 6748 KB Output is correct
5 Correct 3 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 3 ms 6744 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6520 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 3 ms 6492 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6488 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 6544 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 2 ms 6540 KB Output is correct
28 Correct 2 ms 6488 KB Output is correct
29 Correct 2 ms 6744 KB Output is correct
30 Correct 483 ms 89972 KB Output is correct
31 Correct 327 ms 90452 KB Output is correct
32 Correct 413 ms 89004 KB Output is correct
33 Correct 390 ms 89996 KB Output is correct
34 Correct 329 ms 89608 KB Output is correct
35 Correct 265 ms 90452 KB Output is correct
36 Correct 236 ms 90816 KB Output is correct
37 Correct 483 ms 88660 KB Output is correct
38 Correct 346 ms 89196 KB Output is correct
39 Correct 424 ms 89772 KB Output is correct
40 Correct 336 ms 90232 KB Output is correct
41 Correct 195 ms 90492 KB Output is correct
42 Correct 212 ms 90808 KB Output is correct
43 Correct 204 ms 90224 KB Output is correct
44 Correct 211 ms 90800 KB Output is correct
45 Correct 218 ms 91136 KB Output is correct
46 Correct 2 ms 6488 KB Output is correct
47 Correct 2 ms 6492 KB Output is correct
48 Correct 2 ms 6492 KB Output is correct
49 Correct 2 ms 6492 KB Output is correct
50 Correct 2 ms 6492 KB Output is correct
51 Correct 2 ms 6320 KB Output is correct
52 Correct 392 ms 89956 KB Output is correct
53 Correct 316 ms 90736 KB Output is correct
54 Correct 395 ms 88944 KB Output is correct
55 Correct 342 ms 90272 KB Output is correct
56 Correct 296 ms 90196 KB Output is correct
57 Correct 308 ms 90120 KB Output is correct
58 Correct 219 ms 90816 KB Output is correct
59 Correct 493 ms 88776 KB Output is correct
60 Correct 289 ms 89340 KB Output is correct
61 Correct 430 ms 89756 KB Output is correct
62 Correct 292 ms 90452 KB Output is correct
63 Correct 2 ms 6492 KB Output is correct
64 Correct 2 ms 6488 KB Output is correct
65 Correct 2 ms 6488 KB Output is correct
66 Correct 3 ms 6492 KB Output is correct
67 Correct 2 ms 6400 KB Output is correct
68 Correct 2 ms 6492 KB Output is correct
69 Correct 2 ms 6492 KB Output is correct
70 Correct 2 ms 6492 KB Output is correct
71 Correct 2 ms 6492 KB Output is correct
72 Correct 2 ms 6492 KB Output is correct
73 Correct 2 ms 6492 KB Output is correct
74 Correct 2 ms 6488 KB Output is correct
75 Correct 2 ms 6492 KB Output is correct
76 Correct 2 ms 6492 KB Output is correct
77 Correct 2 ms 6544 KB Output is correct
78 Correct 2 ms 6492 KB Output is correct
79 Correct 523 ms 85972 KB Output is correct
80 Correct 674 ms 86500 KB Output is correct
81 Correct 465 ms 86076 KB Output is correct
82 Correct 414 ms 87052 KB Output is correct
83 Correct 304 ms 87364 KB Output is correct
84 Correct 269 ms 87480 KB Output is correct
85 Correct 223 ms 87740 KB Output is correct
86 Correct 518 ms 85784 KB Output is correct
87 Correct 691 ms 86468 KB Output is correct
88 Correct 419 ms 86880 KB Output is correct
89 Correct 477 ms 86852 KB Output is correct
90 Correct 344 ms 88480 KB Output is correct
91 Correct 360 ms 89424 KB Output is correct
92 Correct 2 ms 6492 KB Output is correct
93 Correct 2 ms 6492 KB Output is correct
94 Correct 2 ms 6492 KB Output is correct
95 Correct 1 ms 6492 KB Output is correct
96 Correct 3 ms 6964 KB Output is correct
97 Correct 2 ms 6488 KB Output is correct
98 Correct 576 ms 88480 KB Output is correct
99 Correct 668 ms 86988 KB Output is correct
100 Correct 538 ms 87448 KB Output is correct
101 Correct 401 ms 88620 KB Output is correct
102 Correct 294 ms 88912 KB Output is correct
103 Correct 291 ms 88764 KB Output is correct
104 Correct 226 ms 88768 KB Output is correct
105 Correct 547 ms 88844 KB Output is correct
106 Correct 701 ms 86992 KB Output is correct
107 Correct 496 ms 89492 KB Output is correct
108 Correct 442 ms 87980 KB Output is correct
109 Correct 339 ms 88656 KB Output is correct
110 Correct 367 ms 89428 KB Output is correct
111 Correct 2 ms 6492 KB Output is correct
112 Correct 2 ms 6548 KB Output is correct
113 Correct 2 ms 6492 KB Output is correct
114 Correct 2 ms 6492 KB Output is correct
115 Correct 2 ms 6492 KB Output is correct
116 Correct 467 ms 88012 KB Output is correct
117 Correct 517 ms 90692 KB Output is correct
118 Correct 487 ms 89128 KB Output is correct
119 Correct 418 ms 90040 KB Output is correct
120 Correct 312 ms 89920 KB Output is correct
121 Correct 316 ms 90704 KB Output is correct
122 Correct 240 ms 90744 KB Output is correct
123 Correct 586 ms 88736 KB Output is correct
124 Correct 657 ms 89196 KB Output is correct
125 Correct 423 ms 88956 KB Output is correct
126 Correct 530 ms 90448 KB Output is correct
127 Correct 568 ms 90956 KB Output is correct
128 Correct 459 ms 91552 KB Output is correct
129 Correct 471 ms 92628 KB Output is correct