Submission #760663

# Submission time Handle Problem Language Result Execution time Memory
760663 2023-06-18T05:40:43 Z bachhoangxuan Sprinkler (JOI22_sprinkler) C++17
100 / 100
1272 ms 114704 KB
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<pii,int>
#define fi first
#define se second
const int inf=1e18;
int mod;
const int maxn=250005;
const int bl=650;
const int maxs=405;
const int maxm=250005;
const int maxq=500005;
const int maxl=20;
const int maxa=250000;
const int root=3;
/*
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
const int iroot=power(3,mod-2);
*/
const int base=101;

void solve(){
    int n;cin >> n >> mod;
    vector<vector<int>> edge(n+1),mul(n+1,vector<int>(41,1));
    vector<int> h(n+1),par(n+1);
    for(int i=1;i<n;i++){
        int u,v;cin >> u >> v;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    for(int i=1;i<=n;i++) cin >> h[i];
    function<void(int,int)> dfs = [&](int u,int p){
        par[u]=p;
        for(int v:edge[u]){
            if(v==p) continue;
            dfs(v,u);
        }
    };
    dfs(1,0);
    int q;cin >> q;
    while(q--){
        int id,x,d,k;cin >> id >> x;
        if(id==1){
            cin >> d >> k;
            while(d && x>1){
                mul[x][d]=mul[x][d]*k%mod;
                mul[x][d-1]=mul[x][d-1]*k%mod;
                x=par[x];d--;
            }
            for(int i=d;i>=0;i--) mul[x][i]=mul[x][i]*k%mod;
        }
        else{
            int res=h[x];
            for(int i=0;i<=40;i++){
                res=res*mul[x][i]%mod;
                x=par[x];
            }
            cout << res << '\n';
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 2 ms 784 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 539 ms 97840 KB Output is correct
3 Correct 337 ms 98340 KB Output is correct
4 Correct 477 ms 108908 KB Output is correct
5 Correct 425 ms 98036 KB Output is correct
6 Correct 315 ms 97476 KB Output is correct
7 Correct 309 ms 98324 KB Output is correct
8 Correct 278 ms 98492 KB Output is correct
9 Correct 594 ms 114704 KB Output is correct
10 Correct 343 ms 113760 KB Output is correct
11 Correct 503 ms 97780 KB Output is correct
12 Correct 348 ms 98200 KB Output is correct
13 Correct 210 ms 98236 KB Output is correct
14 Correct 219 ms 98624 KB Output is correct
15 Correct 206 ms 98004 KB Output is correct
16 Correct 223 ms 98508 KB Output is correct
17 Correct 222 ms 98980 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 539 ms 97840 KB Output is correct
3 Correct 337 ms 98340 KB Output is correct
4 Correct 477 ms 108908 KB Output is correct
5 Correct 425 ms 98036 KB Output is correct
6 Correct 315 ms 97476 KB Output is correct
7 Correct 309 ms 98324 KB Output is correct
8 Correct 278 ms 98492 KB Output is correct
9 Correct 594 ms 114704 KB Output is correct
10 Correct 343 ms 113760 KB Output is correct
11 Correct 503 ms 97780 KB Output is correct
12 Correct 348 ms 98200 KB Output is correct
13 Correct 210 ms 98236 KB Output is correct
14 Correct 219 ms 98624 KB Output is correct
15 Correct 206 ms 98004 KB Output is correct
16 Correct 223 ms 98508 KB Output is correct
17 Correct 222 ms 98980 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 0 ms 328 KB Output is correct
24 Correct 546 ms 97748 KB Output is correct
25 Correct 360 ms 98420 KB Output is correct
26 Correct 496 ms 114292 KB Output is correct
27 Correct 452 ms 98008 KB Output is correct
28 Correct 332 ms 98076 KB Output is correct
29 Correct 318 ms 97860 KB Output is correct
30 Correct 275 ms 98592 KB Output is correct
31 Correct 634 ms 109292 KB Output is correct
32 Correct 369 ms 113796 KB Output is correct
33 Correct 506 ms 97752 KB Output is correct
34 Correct 347 ms 98196 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 678 ms 111628 KB Output is correct
3 Correct 924 ms 108148 KB Output is correct
4 Correct 643 ms 108448 KB Output is correct
5 Correct 745 ms 95060 KB Output is correct
6 Correct 373 ms 95052 KB Output is correct
7 Correct 371 ms 95364 KB Output is correct
8 Correct 363 ms 95548 KB Output is correct
9 Correct 935 ms 106444 KB Output is correct
10 Correct 1228 ms 110584 KB Output is correct
11 Correct 794 ms 94660 KB Output is correct
12 Correct 924 ms 95516 KB Output is correct
13 Correct 568 ms 96364 KB Output is correct
14 Correct 598 ms 97272 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 781 ms 108228 KB Output is correct
3 Correct 1082 ms 104168 KB Output is correct
4 Correct 678 ms 106488 KB Output is correct
5 Correct 568 ms 96800 KB Output is correct
6 Correct 368 ms 96692 KB Output is correct
7 Correct 355 ms 96564 KB Output is correct
8 Correct 319 ms 96548 KB Output is correct
9 Correct 888 ms 113188 KB Output is correct
10 Correct 1272 ms 111756 KB Output is correct
11 Correct 705 ms 97308 KB Output is correct
12 Correct 776 ms 95780 KB Output is correct
13 Correct 466 ms 96540 KB Output is correct
14 Correct 493 ms 97500 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 2 ms 784 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 539 ms 97840 KB Output is correct
31 Correct 337 ms 98340 KB Output is correct
32 Correct 477 ms 108908 KB Output is correct
33 Correct 425 ms 98036 KB Output is correct
34 Correct 315 ms 97476 KB Output is correct
35 Correct 309 ms 98324 KB Output is correct
36 Correct 278 ms 98492 KB Output is correct
37 Correct 594 ms 114704 KB Output is correct
38 Correct 343 ms 113760 KB Output is correct
39 Correct 503 ms 97780 KB Output is correct
40 Correct 348 ms 98200 KB Output is correct
41 Correct 210 ms 98236 KB Output is correct
42 Correct 219 ms 98624 KB Output is correct
43 Correct 206 ms 98004 KB Output is correct
44 Correct 223 ms 98508 KB Output is correct
45 Correct 222 ms 98980 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 336 KB Output is correct
51 Correct 0 ms 328 KB Output is correct
52 Correct 546 ms 97748 KB Output is correct
53 Correct 360 ms 98420 KB Output is correct
54 Correct 496 ms 114292 KB Output is correct
55 Correct 452 ms 98008 KB Output is correct
56 Correct 332 ms 98076 KB Output is correct
57 Correct 318 ms 97860 KB Output is correct
58 Correct 275 ms 98592 KB Output is correct
59 Correct 634 ms 109292 KB Output is correct
60 Correct 369 ms 113796 KB Output is correct
61 Correct 506 ms 97752 KB Output is correct
62 Correct 347 ms 98196 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 1 ms 336 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 678 ms 111628 KB Output is correct
80 Correct 924 ms 108148 KB Output is correct
81 Correct 643 ms 108448 KB Output is correct
82 Correct 745 ms 95060 KB Output is correct
83 Correct 373 ms 95052 KB Output is correct
84 Correct 371 ms 95364 KB Output is correct
85 Correct 363 ms 95548 KB Output is correct
86 Correct 935 ms 106444 KB Output is correct
87 Correct 1228 ms 110584 KB Output is correct
88 Correct 794 ms 94660 KB Output is correct
89 Correct 924 ms 95516 KB Output is correct
90 Correct 568 ms 96364 KB Output is correct
91 Correct 598 ms 97272 KB Output is correct
92 Correct 1 ms 332 KB Output is correct
93 Correct 1 ms 212 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 0 ms 212 KB Output is correct
98 Correct 781 ms 108228 KB Output is correct
99 Correct 1082 ms 104168 KB Output is correct
100 Correct 678 ms 106488 KB Output is correct
101 Correct 568 ms 96800 KB Output is correct
102 Correct 368 ms 96692 KB Output is correct
103 Correct 355 ms 96564 KB Output is correct
104 Correct 319 ms 96548 KB Output is correct
105 Correct 888 ms 113188 KB Output is correct
106 Correct 1272 ms 111756 KB Output is correct
107 Correct 705 ms 97308 KB Output is correct
108 Correct 776 ms 95780 KB Output is correct
109 Correct 466 ms 96540 KB Output is correct
110 Correct 493 ms 97500 KB Output is correct
111 Correct 1 ms 340 KB Output is correct
112 Correct 1 ms 340 KB Output is correct
113 Correct 1 ms 340 KB Output is correct
114 Correct 1 ms 340 KB Output is correct
115 Correct 1 ms 340 KB Output is correct
116 Correct 648 ms 95684 KB Output is correct
117 Correct 804 ms 98296 KB Output is correct
118 Correct 793 ms 114132 KB Output is correct
119 Correct 617 ms 98096 KB Output is correct
120 Correct 443 ms 97660 KB Output is correct
121 Correct 402 ms 98508 KB Output is correct
122 Correct 323 ms 98428 KB Output is correct
123 Correct 885 ms 111132 KB Output is correct
124 Correct 1138 ms 108056 KB Output is correct
125 Correct 694 ms 96884 KB Output is correct
126 Correct 893 ms 98272 KB Output is correct
127 Correct 914 ms 98880 KB Output is correct
128 Correct 555 ms 99424 KB Output is correct
129 Correct 605 ms 100172 KB Output is correct