Submission #1023824

# Submission time Handle Problem Language Result Execution time Memory
1023824 2024-07-15T07:02:19 Z manizare Sprinkler (JOI22_sprinkler) C++14
100 / 100
594 ms 105556 KB
#include <bits/stdc++.h>
 
 
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define ld long double 
#define int long long 
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= b;i++)
#define per(i, a , b) for(int i=a;i >= b;i--)
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 2e5 + 10  , sq = 550,  inf = 1e8+10 , mod = 10007 , lg = 20  ;
int n , l , h[maxn]  , dis[maxn] , par[maxn] ;
vector <int> G[maxn] ;

void dfs(int v){
    for(int u : G[v]){
        if(par[v] == u)continue ; 
        dis[u] = dis[v] +1  ;
        par[u] = v ; 
        dfs(u) ;
    }
}
int t[maxn][45] , ted[maxn+100] ;

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);    
    cin >> n >> l ; 
    rep(i , 1, n-1){
        int v , u ;cin >> v >> u ; 
        G[v].pb(u) ;
        G[u].pb(v) ;
    }
    rep(i ,1 , n)cin >> h[i] ; 
    int q ;cin >> q ;rep(i ,0, n+42)ted[i] = 1 ;
    rep(i , 1 , n)rep(j , 0 , 40)t[i][j] = 1 ;
    dfs(1) ;
    while(q--){
        int T ;
        cin >> T ; 
        if(T == 1){
            int x , w , d ;
            cin >> x >> d >> w ; 
            if(d >= dis[x])ted[d-dis[x]]  = ted[d-dis[x]] * w % l ;
            while(d >= 0){
                if(x == 1)break ; 
                t[x][d] = (t[x][d] * w % l); 
                if(d)t[x][d-1] = t[x][d-1] * w % l  ;
                d--;
                x = par[x] ;               
            }      
        }else{
            int x ;cin >> x ; 
            int d = 0 ;
            int ans = h[x]  ;
            rep(j , dis[x] , 42)ans= ans * ted[j]% l ; 
            while(x!=1){
                if(d > 40)break ;
                ans= ans * t[x][d] % l ; 
                d++ ;      
                x = par[x] ;
            } 
            cout << ans << "\n" ; 
        }      
    }  
}
/*
*/
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 5108 KB Output is correct
4 Correct 3 ms 5464 KB Output is correct
5 Correct 3 ms 5512 KB Output is correct
6 Correct 3 ms 5468 KB Output is correct
7 Correct 2 ms 5468 KB Output is correct
8 Correct 3 ms 5468 KB Output is correct
9 Correct 2 ms 5212 KB Output is correct
10 Correct 3 ms 5032 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 5212 KB Output is correct
13 Correct 2 ms 5212 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 2 ms 5212 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 5212 KB Output is correct
18 Correct 2 ms 5212 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 5180 KB Output is correct
22 Correct 2 ms 4952 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 4 ms 5212 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 5212 KB Output is correct
28 Correct 3 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 489 ms 100952 KB Output is correct
3 Correct 265 ms 101456 KB Output is correct
4 Correct 392 ms 103760 KB Output is correct
5 Correct 353 ms 101132 KB Output is correct
6 Correct 256 ms 100692 KB Output is correct
7 Correct 283 ms 101456 KB Output is correct
8 Correct 217 ms 101820 KB Output is correct
9 Correct 520 ms 105296 KB Output is correct
10 Correct 298 ms 105556 KB Output is correct
11 Correct 453 ms 100756 KB Output is correct
12 Correct 257 ms 101252 KB Output is correct
13 Correct 172 ms 101312 KB Output is correct
14 Correct 187 ms 101884 KB Output is correct
15 Correct 200 ms 101044 KB Output is correct
16 Correct 184 ms 101784 KB Output is correct
17 Correct 185 ms 102200 KB Output is correct
18 Correct 2 ms 5212 KB Output is correct
19 Correct 2 ms 5212 KB Output is correct
20 Correct 2 ms 5212 KB Output is correct
21 Correct 2 ms 5212 KB Output is correct
22 Correct 2 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 489 ms 100952 KB Output is correct
3 Correct 265 ms 101456 KB Output is correct
4 Correct 392 ms 103760 KB Output is correct
5 Correct 353 ms 101132 KB Output is correct
6 Correct 256 ms 100692 KB Output is correct
7 Correct 283 ms 101456 KB Output is correct
8 Correct 217 ms 101820 KB Output is correct
9 Correct 520 ms 105296 KB Output is correct
10 Correct 298 ms 105556 KB Output is correct
11 Correct 453 ms 100756 KB Output is correct
12 Correct 257 ms 101252 KB Output is correct
13 Correct 172 ms 101312 KB Output is correct
14 Correct 187 ms 101884 KB Output is correct
15 Correct 200 ms 101044 KB Output is correct
16 Correct 184 ms 101784 KB Output is correct
17 Correct 185 ms 102200 KB Output is correct
18 Correct 2 ms 5212 KB Output is correct
19 Correct 2 ms 5212 KB Output is correct
20 Correct 2 ms 5212 KB Output is correct
21 Correct 2 ms 5212 KB Output is correct
22 Correct 2 ms 5208 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 507 ms 100936 KB Output is correct
25 Correct 289 ms 101484 KB Output is correct
26 Correct 434 ms 105556 KB Output is correct
27 Correct 400 ms 100948 KB Output is correct
28 Correct 290 ms 101456 KB Output is correct
29 Correct 273 ms 91344 KB Output is correct
30 Correct 240 ms 99776 KB Output is correct
31 Correct 573 ms 102712 KB Output is correct
32 Correct 285 ms 103372 KB Output is correct
33 Correct 486 ms 95568 KB Output is correct
34 Correct 276 ms 89940 KB Output is correct
35 Correct 2 ms 4952 KB Output is correct
36 Correct 2 ms 4952 KB Output is correct
37 Correct 4 ms 4956 KB Output is correct
38 Correct 3 ms 5040 KB Output is correct
39 Correct 2 ms 5212 KB Output is correct
40 Correct 3 ms 4956 KB Output is correct
41 Correct 3 ms 4956 KB Output is correct
42 Correct 2 ms 4956 KB Output is correct
43 Correct 4 ms 4968 KB Output is correct
44 Correct 2 ms 4956 KB Output is correct
45 Correct 2 ms 5168 KB Output is correct
46 Correct 2 ms 5212 KB Output is correct
47 Correct 3 ms 5212 KB Output is correct
48 Correct 2 ms 5212 KB Output is correct
49 Correct 2 ms 5176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 540 ms 94596 KB Output is correct
3 Correct 580 ms 101968 KB Output is correct
4 Correct 500 ms 101460 KB Output is correct
5 Correct 437 ms 98120 KB Output is correct
6 Correct 260 ms 98260 KB Output is correct
7 Correct 253 ms 98388 KB Output is correct
8 Correct 221 ms 98792 KB Output is correct
9 Correct 547 ms 100944 KB Output is correct
10 Correct 549 ms 102488 KB Output is correct
11 Correct 484 ms 97704 KB Output is correct
12 Correct 477 ms 99008 KB Output is correct
13 Correct 340 ms 99668 KB Output is correct
14 Correct 312 ms 100448 KB Output is correct
15 Correct 2 ms 4968 KB Output is correct
16 Correct 3 ms 5180 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 586 ms 99572 KB Output is correct
3 Correct 588 ms 98448 KB Output is correct
4 Correct 465 ms 102104 KB Output is correct
5 Correct 402 ms 99664 KB Output is correct
6 Correct 266 ms 99780 KB Output is correct
7 Correct 260 ms 99668 KB Output is correct
8 Correct 215 ms 99776 KB Output is correct
9 Correct 535 ms 104808 KB Output is correct
10 Correct 567 ms 103508 KB Output is correct
11 Correct 538 ms 100436 KB Output is correct
12 Correct 510 ms 99296 KB Output is correct
13 Correct 329 ms 99668 KB Output is correct
14 Correct 306 ms 100688 KB Output is correct
15 Correct 2 ms 5208 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 5108 KB Output is correct
4 Correct 3 ms 5464 KB Output is correct
5 Correct 3 ms 5512 KB Output is correct
6 Correct 3 ms 5468 KB Output is correct
7 Correct 2 ms 5468 KB Output is correct
8 Correct 3 ms 5468 KB Output is correct
9 Correct 2 ms 5212 KB Output is correct
10 Correct 3 ms 5032 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 5212 KB Output is correct
13 Correct 2 ms 5212 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 2 ms 5212 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 5212 KB Output is correct
18 Correct 2 ms 5212 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 5180 KB Output is correct
22 Correct 2 ms 4952 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 4 ms 5212 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 5212 KB Output is correct
28 Correct 3 ms 5212 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 489 ms 100952 KB Output is correct
31 Correct 265 ms 101456 KB Output is correct
32 Correct 392 ms 103760 KB Output is correct
33 Correct 353 ms 101132 KB Output is correct
34 Correct 256 ms 100692 KB Output is correct
35 Correct 283 ms 101456 KB Output is correct
36 Correct 217 ms 101820 KB Output is correct
37 Correct 520 ms 105296 KB Output is correct
38 Correct 298 ms 105556 KB Output is correct
39 Correct 453 ms 100756 KB Output is correct
40 Correct 257 ms 101252 KB Output is correct
41 Correct 172 ms 101312 KB Output is correct
42 Correct 187 ms 101884 KB Output is correct
43 Correct 200 ms 101044 KB Output is correct
44 Correct 184 ms 101784 KB Output is correct
45 Correct 185 ms 102200 KB Output is correct
46 Correct 2 ms 5212 KB Output is correct
47 Correct 2 ms 5212 KB Output is correct
48 Correct 2 ms 5212 KB Output is correct
49 Correct 2 ms 5212 KB Output is correct
50 Correct 2 ms 5208 KB Output is correct
51 Correct 2 ms 4956 KB Output is correct
52 Correct 507 ms 100936 KB Output is correct
53 Correct 289 ms 101484 KB Output is correct
54 Correct 434 ms 105556 KB Output is correct
55 Correct 400 ms 100948 KB Output is correct
56 Correct 290 ms 101456 KB Output is correct
57 Correct 273 ms 91344 KB Output is correct
58 Correct 240 ms 99776 KB Output is correct
59 Correct 573 ms 102712 KB Output is correct
60 Correct 285 ms 103372 KB Output is correct
61 Correct 486 ms 95568 KB Output is correct
62 Correct 276 ms 89940 KB Output is correct
63 Correct 2 ms 4952 KB Output is correct
64 Correct 2 ms 4952 KB Output is correct
65 Correct 4 ms 4956 KB Output is correct
66 Correct 3 ms 5040 KB Output is correct
67 Correct 2 ms 5212 KB Output is correct
68 Correct 3 ms 4956 KB Output is correct
69 Correct 3 ms 4956 KB Output is correct
70 Correct 2 ms 4956 KB Output is correct
71 Correct 4 ms 4968 KB Output is correct
72 Correct 2 ms 4956 KB Output is correct
73 Correct 2 ms 5168 KB Output is correct
74 Correct 2 ms 5212 KB Output is correct
75 Correct 3 ms 5212 KB Output is correct
76 Correct 2 ms 5212 KB Output is correct
77 Correct 2 ms 5176 KB Output is correct
78 Correct 2 ms 4956 KB Output is correct
79 Correct 540 ms 94596 KB Output is correct
80 Correct 580 ms 101968 KB Output is correct
81 Correct 500 ms 101460 KB Output is correct
82 Correct 437 ms 98120 KB Output is correct
83 Correct 260 ms 98260 KB Output is correct
84 Correct 253 ms 98388 KB Output is correct
85 Correct 221 ms 98792 KB Output is correct
86 Correct 547 ms 100944 KB Output is correct
87 Correct 549 ms 102488 KB Output is correct
88 Correct 484 ms 97704 KB Output is correct
89 Correct 477 ms 99008 KB Output is correct
90 Correct 340 ms 99668 KB Output is correct
91 Correct 312 ms 100448 KB Output is correct
92 Correct 2 ms 4968 KB Output is correct
93 Correct 3 ms 5180 KB Output is correct
94 Correct 2 ms 4956 KB Output is correct
95 Correct 2 ms 4956 KB Output is correct
96 Correct 2 ms 4956 KB Output is correct
97 Correct 2 ms 4956 KB Output is correct
98 Correct 586 ms 99572 KB Output is correct
99 Correct 588 ms 98448 KB Output is correct
100 Correct 465 ms 102104 KB Output is correct
101 Correct 402 ms 99664 KB Output is correct
102 Correct 266 ms 99780 KB Output is correct
103 Correct 260 ms 99668 KB Output is correct
104 Correct 215 ms 99776 KB Output is correct
105 Correct 535 ms 104808 KB Output is correct
106 Correct 567 ms 103508 KB Output is correct
107 Correct 538 ms 100436 KB Output is correct
108 Correct 510 ms 99296 KB Output is correct
109 Correct 329 ms 99668 KB Output is correct
110 Correct 306 ms 100688 KB Output is correct
111 Correct 2 ms 5208 KB Output is correct
112 Correct 2 ms 4956 KB Output is correct
113 Correct 2 ms 4956 KB Output is correct
114 Correct 2 ms 4956 KB Output is correct
115 Correct 2 ms 5212 KB Output is correct
116 Correct 506 ms 98904 KB Output is correct
117 Correct 491 ms 101456 KB Output is correct
118 Correct 480 ms 105512 KB Output is correct
119 Correct 472 ms 101240 KB Output is correct
120 Correct 271 ms 100692 KB Output is correct
121 Correct 264 ms 101748 KB Output is correct
122 Correct 220 ms 101756 KB Output is correct
123 Correct 547 ms 104284 KB Output is correct
124 Correct 594 ms 103504 KB Output is correct
125 Correct 487 ms 100176 KB Output is correct
126 Correct 489 ms 101488 KB Output is correct
127 Correct 539 ms 101712 KB Output is correct
128 Correct 314 ms 102564 KB Output is correct
129 Correct 336 ms 103504 KB Output is correct