Submission #677909

# Submission time Handle Problem Language Result Execution time Memory
677909 2023-01-04T15:23:52 Z DwightKSchrute Sprinkler (JOI22_sprinkler) C++17
100 / 100
1160 ms 104780 KB
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 */
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;
using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int>vi;
typedef vector<vector<int>>vvi;
typedef vector<ll>vl;
typedef vector<vl> vvl;
typedef pair<int,int>pi;
typedef pair<ll,ll> pl;
typedef vector<pl> vpl;
typedef vector<ld> vld;
typedef pair<ld,ld> pld;
typedef vector<pi> vpi;

//typedef tree<ll, null_type, less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<typename T> ostream& operator<<(ostream& os, vector<T>& a){os<<"[";for(int i=0; i<ll(a.size()); i++){os << a[i] << ((i!=ll(a.size()-1)?" ":""));}os << "]\n"; return os;}

#define all(x) x.begin(),x.end()
#define YES out("YES")
#define NO out("NO")
#define out(x){cout << x << "\n"; return;}
#define outfl(x){cout << x << endl;return;}
#define GLHF ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define print(x){for(auto ait:x) cout << ait << " "; cout << "\n";}
#define pb push_back
#define umap unordered_map


template<typename T>
void read(vector<T>& v){
    int n=v.size();
    for(int i=0; i<n; i++)
        cin >> v[i];
}
template<typename T>
vector<T>UNQ(vector<T>a){
    vector<T>ans;
    for(T t:a)
        if(ans.empty() || t!=ans.back())
            ans.push_back(t);
    return ans;
}



void solve();
int main(){
    GLHF;
    int t=1;
    //cin >> t;
    while(t--)
        solve();
}
ll n,m;
vvi g;
vl a;
vvl lazy;
vi up;
const int D = 40;
void dfs(int x,int p){
    for(int nbr:g[x])
        if(nbr!=p)
            up[nbr]=x,dfs(nbr,x);
}
ll qur(int x){
    ll ans=a[x];
    int d=0;
    for(; up[x]!=-1 && d<=D; d++){
        //I am on distance of i from x
        ans=(ans*lazy[x][d])%m;
        if(d+1<=D)
            ans=(ans*lazy[x][d+1])%m;
        x=up[x];
    }

    while(d<=D)
        ans=(ans*lazy[x][d])%m,d++;
    return ans;
}

void upd(ll x,ll d,ll w){
    for(; d>=0 && x!=-1; d--){
        lazy[x][d] = (lazy[x][d]*w)%m;
        x=up[x];
    }
}
void solve() {
    cin >> n >> m;
    g.resize(n+1);
    for(int i=0; i<n-1; i++){
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    a.resize(n+1);
    for(int i=1; i<=n; i++)
        cin >> a[i];

    up.resize(n+1,-1);
    lazy.resize(n+1,vl(D+1,1));
    dfs(1,-1);

    int q;
    cin >> q;
    while(q--){
        int op;
        cin >> op;
        if(op==2){
            int x;
            cin >> x;
            cout << qur(x) << "\n";
        }
        else{
            ll x,d,w;
            cin >> x >> d >> w;
            upd(x,d,w);
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 672 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 672 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 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 324 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 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 320 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 1 ms 212 KB Output is correct
2 Correct 656 ms 95960 KB Output is correct
3 Correct 401 ms 96424 KB Output is correct
4 Correct 598 ms 102212 KB Output is correct
5 Correct 516 ms 96232 KB Output is correct
6 Correct 397 ms 95664 KB Output is correct
7 Correct 416 ms 96440 KB Output is correct
8 Correct 330 ms 96964 KB Output is correct
9 Correct 757 ms 104780 KB Output is correct
10 Correct 437 ms 104616 KB Output is correct
11 Correct 611 ms 95944 KB Output is correct
12 Correct 401 ms 96460 KB Output is correct
13 Correct 262 ms 96736 KB Output is correct
14 Correct 261 ms 97184 KB Output is correct
15 Correct 273 ms 96556 KB Output is correct
16 Correct 267 ms 97048 KB Output is correct
17 Correct 288 ms 97536 KB Output is correct
18 Correct 1 ms 340 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 328 KB Output is correct
22 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 656 ms 95960 KB Output is correct
3 Correct 401 ms 96424 KB Output is correct
4 Correct 598 ms 102212 KB Output is correct
5 Correct 516 ms 96232 KB Output is correct
6 Correct 397 ms 95664 KB Output is correct
7 Correct 416 ms 96440 KB Output is correct
8 Correct 330 ms 96964 KB Output is correct
9 Correct 757 ms 104780 KB Output is correct
10 Correct 437 ms 104616 KB Output is correct
11 Correct 611 ms 95944 KB Output is correct
12 Correct 401 ms 96460 KB Output is correct
13 Correct 262 ms 96736 KB Output is correct
14 Correct 261 ms 97184 KB Output is correct
15 Correct 273 ms 96556 KB Output is correct
16 Correct 267 ms 97048 KB Output is correct
17 Correct 288 ms 97536 KB Output is correct
18 Correct 1 ms 340 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 328 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 320 KB Output is correct
24 Correct 645 ms 95896 KB Output is correct
25 Correct 419 ms 96400 KB Output is correct
26 Correct 607 ms 104776 KB Output is correct
27 Correct 539 ms 96172 KB Output is correct
28 Correct 433 ms 96328 KB Output is correct
29 Correct 404 ms 95960 KB Output is correct
30 Correct 349 ms 96948 KB Output is correct
31 Correct 775 ms 102220 KB Output is correct
32 Correct 457 ms 104692 KB Output is correct
33 Correct 627 ms 95948 KB Output is correct
34 Correct 424 ms 96476 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 332 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 340 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 320 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 320 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 823 ms 101944 KB Output is correct
3 Correct 1116 ms 100536 KB Output is correct
4 Correct 783 ms 100316 KB Output is correct
5 Correct 616 ms 93228 KB Output is correct
6 Correct 433 ms 93396 KB Output is correct
7 Correct 388 ms 93480 KB Output is correct
8 Correct 329 ms 94080 KB Output is correct
9 Correct 832 ms 99324 KB Output is correct
10 Correct 1100 ms 101576 KB Output is correct
11 Correct 659 ms 93084 KB Output is correct
12 Correct 778 ms 94028 KB Output is correct
13 Correct 444 ms 94612 KB Output is correct
14 Correct 493 ms 95268 KB Output is correct
15 Correct 1 ms 212 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 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 860 ms 101684 KB Output is correct
3 Correct 1099 ms 98928 KB Output is correct
4 Correct 779 ms 100128 KB Output is correct
5 Correct 664 ms 94816 KB Output is correct
6 Correct 455 ms 94868 KB Output is correct
7 Correct 444 ms 94812 KB Output is correct
8 Correct 348 ms 95076 KB Output is correct
9 Correct 882 ms 103892 KB Output is correct
10 Correct 1102 ms 102480 KB Output is correct
11 Correct 674 ms 95572 KB Output is correct
12 Correct 783 ms 94040 KB Output is correct
13 Correct 464 ms 94856 KB Output is correct
14 Correct 481 ms 95292 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 0 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 672 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 672 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 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 324 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 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 320 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 1 ms 212 KB Output is correct
30 Correct 656 ms 95960 KB Output is correct
31 Correct 401 ms 96424 KB Output is correct
32 Correct 598 ms 102212 KB Output is correct
33 Correct 516 ms 96232 KB Output is correct
34 Correct 397 ms 95664 KB Output is correct
35 Correct 416 ms 96440 KB Output is correct
36 Correct 330 ms 96964 KB Output is correct
37 Correct 757 ms 104780 KB Output is correct
38 Correct 437 ms 104616 KB Output is correct
39 Correct 611 ms 95944 KB Output is correct
40 Correct 401 ms 96460 KB Output is correct
41 Correct 262 ms 96736 KB Output is correct
42 Correct 261 ms 97184 KB Output is correct
43 Correct 273 ms 96556 KB Output is correct
44 Correct 267 ms 97048 KB Output is correct
45 Correct 288 ms 97536 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 328 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 0 ms 320 KB Output is correct
52 Correct 645 ms 95896 KB Output is correct
53 Correct 419 ms 96400 KB Output is correct
54 Correct 607 ms 104776 KB Output is correct
55 Correct 539 ms 96172 KB Output is correct
56 Correct 433 ms 96328 KB Output is correct
57 Correct 404 ms 95960 KB Output is correct
58 Correct 349 ms 96948 KB Output is correct
59 Correct 775 ms 102220 KB Output is correct
60 Correct 457 ms 104692 KB Output is correct
61 Correct 627 ms 95948 KB Output is correct
62 Correct 424 ms 96476 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 332 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 340 KB Output is correct
72 Correct 1 ms 332 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 1 ms 320 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 320 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 320 KB Output is correct
79 Correct 823 ms 101944 KB Output is correct
80 Correct 1116 ms 100536 KB Output is correct
81 Correct 783 ms 100316 KB Output is correct
82 Correct 616 ms 93228 KB Output is correct
83 Correct 433 ms 93396 KB Output is correct
84 Correct 388 ms 93480 KB Output is correct
85 Correct 329 ms 94080 KB Output is correct
86 Correct 832 ms 99324 KB Output is correct
87 Correct 1100 ms 101576 KB Output is correct
88 Correct 659 ms 93084 KB Output is correct
89 Correct 778 ms 94028 KB Output is correct
90 Correct 444 ms 94612 KB Output is correct
91 Correct 493 ms 95268 KB Output is correct
92 Correct 1 ms 212 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 324 KB Output is correct
97 Correct 1 ms 320 KB Output is correct
98 Correct 860 ms 101684 KB Output is correct
99 Correct 1099 ms 98928 KB Output is correct
100 Correct 779 ms 100128 KB Output is correct
101 Correct 664 ms 94816 KB Output is correct
102 Correct 455 ms 94868 KB Output is correct
103 Correct 444 ms 94812 KB Output is correct
104 Correct 348 ms 95076 KB Output is correct
105 Correct 882 ms 103892 KB Output is correct
106 Correct 1102 ms 102480 KB Output is correct
107 Correct 674 ms 95572 KB Output is correct
108 Correct 783 ms 94040 KB Output is correct
109 Correct 464 ms 94856 KB Output is correct
110 Correct 481 ms 95292 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 657 ms 93912 KB Output is correct
117 Correct 800 ms 96604 KB Output is correct
118 Correct 809 ms 104648 KB Output is correct
119 Correct 679 ms 96252 KB Output is correct
120 Correct 485 ms 95872 KB Output is correct
121 Correct 480 ms 96600 KB Output is correct
122 Correct 361 ms 96892 KB Output is correct
123 Correct 853 ms 103168 KB Output is correct
124 Correct 1160 ms 101660 KB Output is correct
125 Correct 712 ms 95144 KB Output is correct
126 Correct 844 ms 96532 KB Output is correct
127 Correct 850 ms 97064 KB Output is correct
128 Correct 493 ms 97564 KB Output is correct
129 Correct 551 ms 98268 KB Output is correct