답안 #544538

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544538 2022-04-02T09:12:54 Z Jarif_Rahman Sprinkler (JOI22_sprinkler) C++17
100 / 100
897 ms 52064 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

const int maxn = 200000;

vector<int> v[maxn];
int p[maxn];
int ml[maxn][41];

inline void dfs(int nd, int ss){
    p[nd] = ss;
    for(int x: v[nd]) if(x != ss) dfs(x, nd);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, md; cin >> n >> md;

    for(int i = 0; i < n; i++) for(int j = 0; j <= 40; j++) ml[i][j] = 1;

    for(int i = 0; i < n-1; i++){
        int a, b; cin >> a >> b; a--, b--;
        v[a].pb(b);
        v[b].pb(a);
    }

    for(int i = 0; i < n; i++) cin >> ml[i][0];
    dfs(0, -1);

    int q; cin >> q;
    while(q--){
        int tt; cin >> tt;

        if(tt == 1){
            int nd, d, w; cin >> nd >> d >> w; nd--;
            while(d >= 0){
                ml[nd][d]=(ll(ml[nd][d])*w)%md;
                if(d != 0) ml[nd][d-1]=(ll(ml[nd][d-1])*w)%md;
                if(p[nd] == -1){
                    for(int i = 0; i < d-1; i++) ml[nd][i]=(ll(ml[nd][i])*w)%md;
                    break;
                }
                d--;
                nd = p[nd];
            }
        }

        else{
            int nd; cin >> nd; nd--;
            int d = 0;

            int ans = 1;

            while(d <= 40){
                ans=(ll(ans)*ml[nd][d])%md;
                nd = p[nd];
                d++;
                if(nd == -1) break;
            }

            cout << ans << "\n";
        }
    }

}
# 결과 실행 시간 메모리 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 4 ms 5204 KB Output is correct
5 Correct 3 ms 5204 KB Output is correct
6 Correct 5 ms 5240 KB Output is correct
7 Correct 4 ms 5232 KB Output is correct
8 Correct 4 ms 5204 KB Output is correct
9 Correct 3 ms 5036 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 4 ms 5044 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 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 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 4 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 522 ms 47720 KB Output is correct
3 Correct 347 ms 44580 KB Output is correct
4 Correct 462 ms 49092 KB Output is correct
5 Correct 453 ms 46192 KB Output is correct
6 Correct 308 ms 47264 KB Output is correct
7 Correct 310 ms 46480 KB Output is correct
8 Correct 269 ms 46912 KB Output is correct
9 Correct 620 ms 52064 KB Output is correct
10 Correct 351 ms 48652 KB Output is correct
11 Correct 547 ms 47788 KB Output is correct
12 Correct 345 ms 44728 KB Output is correct
13 Correct 242 ms 45152 KB Output is correct
14 Correct 237 ms 45236 KB Output is correct
15 Correct 247 ms 45252 KB Output is correct
16 Correct 246 ms 45192 KB Output is correct
17 Correct 239 ms 45684 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4912 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 522 ms 47720 KB Output is correct
3 Correct 347 ms 44580 KB Output is correct
4 Correct 462 ms 49092 KB Output is correct
5 Correct 453 ms 46192 KB Output is correct
6 Correct 308 ms 47264 KB Output is correct
7 Correct 310 ms 46480 KB Output is correct
8 Correct 269 ms 46912 KB Output is correct
9 Correct 620 ms 52064 KB Output is correct
10 Correct 351 ms 48652 KB Output is correct
11 Correct 547 ms 47788 KB Output is correct
12 Correct 345 ms 44728 KB Output is correct
13 Correct 242 ms 45152 KB Output is correct
14 Correct 237 ms 45236 KB Output is correct
15 Correct 247 ms 45252 KB Output is correct
16 Correct 246 ms 45192 KB Output is correct
17 Correct 239 ms 45684 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4912 KB Output is correct
20 Correct 3 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 3 ms 4948 KB Output is correct
24 Correct 518 ms 47744 KB Output is correct
25 Correct 326 ms 44508 KB Output is correct
26 Correct 448 ms 50336 KB Output is correct
27 Correct 434 ms 46152 KB Output is correct
28 Correct 358 ms 46284 KB Output is correct
29 Correct 326 ms 46232 KB Output is correct
30 Correct 246 ms 46852 KB Output is correct
31 Correct 580 ms 50696 KB Output is correct
32 Correct 357 ms 48536 KB Output is correct
33 Correct 524 ms 47760 KB Output is correct
34 Correct 338 ms 44668 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 4948 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 5004 KB Output is correct
41 Correct 3 ms 4948 KB Output is correct
42 Correct 3 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 3 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 4 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4976 KB Output is correct
2 Correct 629 ms 49264 KB Output is correct
3 Correct 760 ms 47600 KB Output is correct
4 Correct 513 ms 48072 KB Output is correct
5 Correct 435 ms 44620 KB Output is correct
6 Correct 329 ms 44748 KB Output is correct
7 Correct 297 ms 44984 KB Output is correct
8 Correct 231 ms 45340 KB Output is correct
9 Correct 553 ms 48132 KB Output is correct
10 Correct 656 ms 48300 KB Output is correct
11 Correct 466 ms 45032 KB Output is correct
12 Correct 519 ms 44356 KB Output is correct
13 Correct 370 ms 45308 KB Output is correct
14 Correct 431 ms 45644 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 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 672 ms 50700 KB Output is correct
3 Correct 801 ms 46780 KB Output is correct
4 Correct 606 ms 48628 KB Output is correct
5 Correct 603 ms 46092 KB Output is correct
6 Correct 400 ms 46264 KB Output is correct
7 Correct 404 ms 46264 KB Output is correct
8 Correct 326 ms 46656 KB Output is correct
9 Correct 724 ms 51724 KB Output is correct
10 Correct 897 ms 48644 KB Output is correct
11 Correct 610 ms 47680 KB Output is correct
12 Correct 751 ms 44540 KB Output is correct
13 Correct 485 ms 45300 KB Output is correct
14 Correct 447 ms 45700 KB Output is correct
15 Correct 3 ms 5048 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 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 4 ms 5204 KB Output is correct
5 Correct 3 ms 5204 KB Output is correct
6 Correct 5 ms 5240 KB Output is correct
7 Correct 4 ms 5232 KB Output is correct
8 Correct 4 ms 5204 KB Output is correct
9 Correct 3 ms 5036 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 4 ms 5044 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 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 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 4 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 522 ms 47720 KB Output is correct
31 Correct 347 ms 44580 KB Output is correct
32 Correct 462 ms 49092 KB Output is correct
33 Correct 453 ms 46192 KB Output is correct
34 Correct 308 ms 47264 KB Output is correct
35 Correct 310 ms 46480 KB Output is correct
36 Correct 269 ms 46912 KB Output is correct
37 Correct 620 ms 52064 KB Output is correct
38 Correct 351 ms 48652 KB Output is correct
39 Correct 547 ms 47788 KB Output is correct
40 Correct 345 ms 44728 KB Output is correct
41 Correct 242 ms 45152 KB Output is correct
42 Correct 237 ms 45236 KB Output is correct
43 Correct 247 ms 45252 KB Output is correct
44 Correct 246 ms 45192 KB Output is correct
45 Correct 239 ms 45684 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 4 ms 4912 KB Output is correct
48 Correct 3 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 3 ms 4948 KB Output is correct
52 Correct 518 ms 47744 KB Output is correct
53 Correct 326 ms 44508 KB Output is correct
54 Correct 448 ms 50336 KB Output is correct
55 Correct 434 ms 46152 KB Output is correct
56 Correct 358 ms 46284 KB Output is correct
57 Correct 326 ms 46232 KB Output is correct
58 Correct 246 ms 46852 KB Output is correct
59 Correct 580 ms 50696 KB Output is correct
60 Correct 357 ms 48536 KB Output is correct
61 Correct 524 ms 47760 KB Output is correct
62 Correct 338 ms 44668 KB Output is correct
63 Correct 3 ms 4948 KB Output is correct
64 Correct 3 ms 4948 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 5004 KB Output is correct
69 Correct 3 ms 4948 KB Output is correct
70 Correct 3 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 3 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 4 ms 4948 KB Output is correct
78 Correct 3 ms 4976 KB Output is correct
79 Correct 629 ms 49264 KB Output is correct
80 Correct 760 ms 47600 KB Output is correct
81 Correct 513 ms 48072 KB Output is correct
82 Correct 435 ms 44620 KB Output is correct
83 Correct 329 ms 44748 KB Output is correct
84 Correct 297 ms 44984 KB Output is correct
85 Correct 231 ms 45340 KB Output is correct
86 Correct 553 ms 48132 KB Output is correct
87 Correct 656 ms 48300 KB Output is correct
88 Correct 466 ms 45032 KB Output is correct
89 Correct 519 ms 44356 KB Output is correct
90 Correct 370 ms 45308 KB Output is correct
91 Correct 431 ms 45644 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 4948 KB Output is correct
95 Correct 3 ms 4948 KB Output is correct
96 Correct 3 ms 4948 KB Output is correct
97 Correct 3 ms 4948 KB Output is correct
98 Correct 672 ms 50700 KB Output is correct
99 Correct 801 ms 46780 KB Output is correct
100 Correct 606 ms 48628 KB Output is correct
101 Correct 603 ms 46092 KB Output is correct
102 Correct 400 ms 46264 KB Output is correct
103 Correct 404 ms 46264 KB Output is correct
104 Correct 326 ms 46656 KB Output is correct
105 Correct 724 ms 51724 KB Output is correct
106 Correct 897 ms 48644 KB Output is correct
107 Correct 610 ms 47680 KB Output is correct
108 Correct 751 ms 44540 KB Output is correct
109 Correct 485 ms 45300 KB Output is correct
110 Correct 447 ms 45700 KB Output is correct
111 Correct 3 ms 5048 KB Output is correct
112 Correct 4 ms 4948 KB Output is correct
113 Correct 4 ms 4948 KB Output is correct
114 Correct 3 ms 4948 KB Output is correct
115 Correct 3 ms 4948 KB Output is correct
116 Correct 607 ms 45648 KB Output is correct
117 Correct 662 ms 44396 KB Output is correct
118 Correct 637 ms 50104 KB Output is correct
119 Correct 546 ms 46120 KB Output is correct
120 Correct 412 ms 46204 KB Output is correct
121 Correct 437 ms 46492 KB Output is correct
122 Correct 309 ms 46816 KB Output is correct
123 Correct 713 ms 51072 KB Output is correct
124 Correct 784 ms 47112 KB Output is correct
125 Correct 571 ms 47092 KB Output is correct
126 Correct 626 ms 44416 KB Output is correct
127 Correct 600 ms 44316 KB Output is correct
128 Correct 515 ms 45376 KB Output is correct
129 Correct 576 ms 45772 KB Output is correct