Submission #573312

#TimeUsernameProblemLanguageResultExecution timeMemory
573312chonkaSprinkler (JOI22_sprinkler)C++98
0 / 100
403 ms78556 KiB
#include<bits/stdc++.h> using namespace std ; typedef long long ll ; const int MAXN = 200047 ; const int MXVAL = 43 ; int n , MOD ; int prv[ MAXN ] ; ll coef[ MAXN ][ MXVAL ] ; ll h[ MAXN ] ; void input ( ) { cin >> n >> MOD ; for ( int i = 1 ; i < n ; ++ i ) { int x , y ; cin >> x >> y ; prv[ y ] = x ; } 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 ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...