답안 #573323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
573323 2022-06-06T12:10:46 Z chonka Sprinkler (JOI22_sprinkler) C++
100 / 100
644 ms 97520 KB
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int MAXN = 200047 ;
const int MXVAL = 43 ;

int n , MOD ;
vector < int > v[ MAXN ] ;
int prv[ MAXN ] ;
ll coef[ MAXN ][ MXVAL ] ;
ll h[ MAXN ] ;

void dfs ( int x , int aux ) {
    for ( auto y : v[ x ] ) {
        if ( y == aux ) { continue ; }
        prv[ y ] = x ;
        dfs ( y , x ) ;
    }
}

void input ( ) {
    cin >> n >> MOD ;
    for ( int i = 1 ; i < n ; ++ i ) {
        int x , y ; cin >> x >> y ;
        v[ x ].push_back ( y ) ;
        v[ y ].push_back ( x ) ;
    }
    dfs ( 1 , -1 ) ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        cin >> h[ i ] ;
        for ( int j = 0 ; j < MXVAL ; ++ j ) {
            coef[ i ][ j ] = 1 ;
        }
    }
    prv[ 1 ] = n + 1 ;
    for ( int i = n + 1 ; i <= n + MXVAL ; ++ i ) {
        prv[ i ] = i + 1 ;
        for ( int j = 0 ; j < MXVAL ; ++ j ) {
            coef[ i ][ j ] = 1 ;
        }
    }
}

void solve ( ) {
    int q ; cin >> q ;
    while ( q -- ) {
        int type ;
        cin >> type ;
        if ( type == 1 ) {
            int x , dist , nw ;
            cin >> x >> dist >> nw ;
            int y = x ;
            for ( int i = 0 ; i <= dist ; ++ i ) {
                coef[ y ][ dist - i ] = ( coef[ y ][ dist - i ] * nw ) % MOD ;
                y = prv[ y ] ;
            }
        }
        else {
            int x ;
            cin >> x ;
            ll ans = 1 ;
            int y = x ;
            for ( int i = 0 ; i <= 40 ; ++ i ) {
                ans = ( ans * coef[ y ][ i ] ) % MOD ;
                ans = ( ans * coef[ y ][ i + 1 ] ) % MOD ;
                y = prv[ y ] ;
            }
            cout << ( h[ x ] * ans ) % MOD << "\n" ;
        }
    }
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t ;
    t = 1 ;
    /// scanf ( "%d" , &t ) ;
    /// cin >> t ;
    while ( t -- ) {
        input ( ) ;
        solve ( ) ;
    }
    return 0 ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5028 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 4 ms 5464 KB Output is correct
5 Correct 4 ms 5332 KB Output is correct
6 Correct 4 ms 5460 KB Output is correct
7 Correct 4 ms 5460 KB Output is correct
8 Correct 4 ms 5460 KB Output is correct
9 Correct 3 ms 5032 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 4 ms 5032 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5076 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 4944 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
23 Correct 3 ms 5064 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 4 ms 5032 KB Output is correct
26 Correct 3 ms 5008 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 540 ms 92628 KB Output is correct
3 Correct 343 ms 93260 KB Output is correct
4 Correct 461 ms 95872 KB Output is correct
5 Correct 439 ms 92948 KB Output is correct
6 Correct 391 ms 92060 KB Output is correct
7 Correct 395 ms 93292 KB Output is correct
8 Correct 342 ms 93336 KB Output is correct
9 Correct 599 ms 97240 KB Output is correct
10 Correct 360 ms 97520 KB Output is correct
11 Correct 518 ms 91992 KB Output is correct
12 Correct 348 ms 93160 KB Output is correct
13 Correct 258 ms 93592 KB Output is correct
14 Correct 270 ms 94100 KB Output is correct
15 Correct 261 ms 91276 KB Output is correct
16 Correct 270 ms 93912 KB Output is correct
17 Correct 266 ms 93284 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 4 ms 5036 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 540 ms 92628 KB Output is correct
3 Correct 343 ms 93260 KB Output is correct
4 Correct 461 ms 95872 KB Output is correct
5 Correct 439 ms 92948 KB Output is correct
6 Correct 391 ms 92060 KB Output is correct
7 Correct 395 ms 93292 KB Output is correct
8 Correct 342 ms 93336 KB Output is correct
9 Correct 599 ms 97240 KB Output is correct
10 Correct 360 ms 97520 KB Output is correct
11 Correct 518 ms 91992 KB Output is correct
12 Correct 348 ms 93160 KB Output is correct
13 Correct 258 ms 93592 KB Output is correct
14 Correct 270 ms 94100 KB Output is correct
15 Correct 261 ms 91276 KB Output is correct
16 Correct 270 ms 93912 KB Output is correct
17 Correct 266 ms 93284 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 4 ms 5036 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 580 ms 92752 KB Output is correct
25 Correct 376 ms 93064 KB Output is correct
26 Correct 494 ms 97484 KB Output is correct
27 Correct 455 ms 92852 KB Output is correct
28 Correct 398 ms 93044 KB Output is correct
29 Correct 386 ms 92820 KB Output is correct
30 Correct 346 ms 93752 KB Output is correct
31 Correct 593 ms 96016 KB Output is correct
32 Correct 378 ms 97108 KB Output is correct
33 Correct 606 ms 92748 KB Output is correct
34 Correct 410 ms 93068 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 3 ms 5032 KB Output is correct
37 Correct 4 ms 4948 KB Output is correct
38 Correct 4 ms 5032 KB Output is correct
39 Correct 4 ms 4948 KB Output is correct
40 Correct 4 ms 5032 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 4 ms 5036 KB Output is correct
47 Correct 4 ms 5032 KB Output is correct
48 Correct 3 ms 5028 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5032 KB Output is correct
2 Correct 633 ms 94456 KB Output is correct
3 Correct 617 ms 93988 KB Output is correct
4 Correct 571 ms 93640 KB Output is correct
5 Correct 522 ms 89900 KB Output is correct
6 Correct 413 ms 90036 KB Output is correct
7 Correct 410 ms 90096 KB Output is correct
8 Correct 361 ms 90808 KB Output is correct
9 Correct 622 ms 92980 KB Output is correct
10 Correct 622 ms 94608 KB Output is correct
11 Correct 617 ms 89548 KB Output is correct
12 Correct 570 ms 90444 KB Output is correct
13 Correct 365 ms 91256 KB Output is correct
14 Correct 437 ms 91832 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 4 ms 5032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5028 KB Output is correct
2 Correct 640 ms 88608 KB Output is correct
3 Correct 617 ms 93164 KB Output is correct
4 Correct 590 ms 94312 KB Output is correct
5 Correct 501 ms 91652 KB Output is correct
6 Correct 433 ms 91728 KB Output is correct
7 Correct 445 ms 91548 KB Output is correct
8 Correct 364 ms 91816 KB Output is correct
9 Correct 636 ms 96644 KB Output is correct
10 Correct 599 ms 95184 KB Output is correct
11 Correct 574 ms 92496 KB Output is correct
12 Correct 553 ms 90640 KB Output is correct
13 Correct 362 ms 91496 KB Output is correct
14 Correct 418 ms 92040 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 5028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5028 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 4 ms 5464 KB Output is correct
5 Correct 4 ms 5332 KB Output is correct
6 Correct 4 ms 5460 KB Output is correct
7 Correct 4 ms 5460 KB Output is correct
8 Correct 4 ms 5460 KB Output is correct
9 Correct 3 ms 5032 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 4 ms 5032 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5076 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 4944 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
23 Correct 3 ms 5064 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 4 ms 5032 KB Output is correct
26 Correct 3 ms 5008 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 540 ms 92628 KB Output is correct
31 Correct 343 ms 93260 KB Output is correct
32 Correct 461 ms 95872 KB Output is correct
33 Correct 439 ms 92948 KB Output is correct
34 Correct 391 ms 92060 KB Output is correct
35 Correct 395 ms 93292 KB Output is correct
36 Correct 342 ms 93336 KB Output is correct
37 Correct 599 ms 97240 KB Output is correct
38 Correct 360 ms 97520 KB Output is correct
39 Correct 518 ms 91992 KB Output is correct
40 Correct 348 ms 93160 KB Output is correct
41 Correct 258 ms 93592 KB Output is correct
42 Correct 270 ms 94100 KB Output is correct
43 Correct 261 ms 91276 KB Output is correct
44 Correct 270 ms 93912 KB Output is correct
45 Correct 266 ms 93284 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 4 ms 5036 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 2 ms 4948 KB Output is correct
52 Correct 580 ms 92752 KB Output is correct
53 Correct 376 ms 93064 KB Output is correct
54 Correct 494 ms 97484 KB Output is correct
55 Correct 455 ms 92852 KB Output is correct
56 Correct 398 ms 93044 KB Output is correct
57 Correct 386 ms 92820 KB Output is correct
58 Correct 346 ms 93752 KB Output is correct
59 Correct 593 ms 96016 KB Output is correct
60 Correct 378 ms 97108 KB Output is correct
61 Correct 606 ms 92748 KB Output is correct
62 Correct 410 ms 93068 KB Output is correct
63 Correct 4 ms 5076 KB Output is correct
64 Correct 3 ms 5032 KB Output is correct
65 Correct 4 ms 4948 KB Output is correct
66 Correct 4 ms 5032 KB Output is correct
67 Correct 4 ms 4948 KB Output is correct
68 Correct 4 ms 5032 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 4 ms 5036 KB Output is correct
75 Correct 4 ms 5032 KB Output is correct
76 Correct 3 ms 5028 KB Output is correct
77 Correct 3 ms 4948 KB Output is correct
78 Correct 3 ms 5032 KB Output is correct
79 Correct 633 ms 94456 KB Output is correct
80 Correct 617 ms 93988 KB Output is correct
81 Correct 571 ms 93640 KB Output is correct
82 Correct 522 ms 89900 KB Output is correct
83 Correct 413 ms 90036 KB Output is correct
84 Correct 410 ms 90096 KB Output is correct
85 Correct 361 ms 90808 KB Output is correct
86 Correct 622 ms 92980 KB Output is correct
87 Correct 622 ms 94608 KB Output is correct
88 Correct 617 ms 89548 KB Output is correct
89 Correct 570 ms 90444 KB Output is correct
90 Correct 365 ms 91256 KB Output is correct
91 Correct 437 ms 91832 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 4 ms 5032 KB Output is correct
97 Correct 3 ms 5028 KB Output is correct
98 Correct 640 ms 88608 KB Output is correct
99 Correct 617 ms 93164 KB Output is correct
100 Correct 590 ms 94312 KB Output is correct
101 Correct 501 ms 91652 KB Output is correct
102 Correct 433 ms 91728 KB Output is correct
103 Correct 445 ms 91548 KB Output is correct
104 Correct 364 ms 91816 KB Output is correct
105 Correct 636 ms 96644 KB Output is correct
106 Correct 599 ms 95184 KB Output is correct
107 Correct 574 ms 92496 KB Output is correct
108 Correct 553 ms 90640 KB Output is correct
109 Correct 362 ms 91496 KB Output is correct
110 Correct 418 ms 92040 KB Output is correct
111 Correct 3 ms 4948 KB Output is correct
112 Correct 3 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 5028 KB Output is correct
116 Correct 590 ms 90864 KB Output is correct
117 Correct 600 ms 93300 KB Output is correct
118 Correct 556 ms 97404 KB Output is correct
119 Correct 531 ms 92968 KB Output is correct
120 Correct 468 ms 92424 KB Output is correct
121 Correct 468 ms 93396 KB Output is correct
122 Correct 401 ms 93480 KB Output is correct
123 Correct 644 ms 96444 KB Output is correct
124 Correct 641 ms 95788 KB Output is correct
125 Correct 620 ms 91832 KB Output is correct
126 Correct 611 ms 93260 KB Output is correct
127 Correct 603 ms 93644 KB Output is correct
128 Correct 421 ms 94316 KB Output is correct
129 Correct 445 ms 95076 KB Output is correct