답안 #965203

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
965203 2024-04-18T08:15:19 Z angella Sprinkler (JOI22_sprinkler) C++17
100 / 100
1034 ms 105152 KB
/*
    IN THE NAME OF GOD
*/
#include <bits/stdc++.h>

// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;

#define F                                      first
#define S                                      second
#define Mp                                     make_pair
#define pb                                     push_back
#define pf                                     push_front
#define size(x)                                ((ll)x.size())
#define all(x)                                 (x).begin(),(x).end()
#define kill(x)		                           cout << x << '\n', exit(0);
#define fuck(x)                                cout << "(" << #x << " , " << x << ")" << endl
#define endl                                   '\n'

const int N = 3e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;

inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
    ll ans = 1;
    a=MOD(a, mod);
    while (b) {
        if (b & 1) ans = MOD(ans*a, mod);
        b >>= 1;
        a = MOD(a*a, mod);
    }
    return ans;
}

ll n, q, l, a[N], h[N], par[N], dp[45][N];
vector<int> adj[N];

void init(int v, int p=0) {
    h[v] = h[p] + 1, par[v] = p;
    for(int i=0; i<=41; i++) dp[i][v] = 1;
    for(int u : adj[v]) {
        if(u == p) continue;
        init(u, v);
    }
}

int main () {
	ios_base::sync_with_stdio(false), cin.tie(0);

	cin>>n>>l; Mod = l;
    for(int v,u,i=1; i<n; i++) {
        cin>>v>>u; adj[v].pb(u); adj[u].pb(v);
    }
    init(1);
    for(int i=1; i<=n; i++) cin>>a[i];

    cin>>q;
    for(ll typ,x,d,w,tc=1; tc<=q; tc++) {
        cin>>typ>>x;
        if(typ == 1) {
            cin>>d>>w;
            while(d>=0 && x>0) {
                dp[d][x] = dp[d][x] * w % l;
                //fuck(d);
                d--; x = par[x];
            }
        } else {
            ll v = x, num = 0, res = a[v];
            while(x > 0 && num <= 40) {
                if(par[x] > 0) {
                    if(num>=0)res = MOD(res*dp[num][x]);
                    if(num+1<=40)res = MOD(res*dp[num+1][x]);
                    x = par[x];
                } else {
                    for(int i=40;i-num>=0;i--) res=MOD(res*dp[i][x]);
                    break;
                }
                num++;
            }
            cout<<res<<endl;
        }
    }

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7768 KB Output is correct
2 Correct 5 ms 7772 KB Output is correct
3 Correct 4 ms 7772 KB Output is correct
4 Correct 4 ms 8028 KB Output is correct
5 Correct 5 ms 8284 KB Output is correct
6 Correct 4 ms 8048 KB Output is correct
7 Correct 6 ms 8284 KB Output is correct
8 Correct 5 ms 8284 KB Output is correct
9 Correct 5 ms 7772 KB Output is correct
10 Correct 4 ms 7772 KB Output is correct
11 Correct 4 ms 7772 KB Output is correct
12 Correct 4 ms 7772 KB Output is correct
13 Correct 7 ms 7924 KB Output is correct
14 Correct 4 ms 7768 KB Output is correct
15 Correct 4 ms 7768 KB Output is correct
16 Correct 4 ms 7772 KB Output is correct
17 Correct 4 ms 7772 KB Output is correct
18 Correct 4 ms 7772 KB Output is correct
19 Correct 4 ms 7772 KB Output is correct
20 Correct 4 ms 7772 KB Output is correct
21 Correct 4 ms 7772 KB Output is correct
22 Correct 4 ms 7772 KB Output is correct
23 Correct 4 ms 7772 KB Output is correct
24 Correct 4 ms 7772 KB Output is correct
25 Correct 4 ms 7772 KB Output is correct
26 Correct 4 ms 7772 KB Output is correct
27 Correct 4 ms 7772 KB Output is correct
28 Correct 4 ms 7768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7772 KB Output is correct
2 Correct 942 ms 91552 KB Output is correct
3 Correct 454 ms 96804 KB Output is correct
4 Correct 629 ms 102192 KB Output is correct
5 Correct 720 ms 96384 KB Output is correct
6 Correct 415 ms 95976 KB Output is correct
7 Correct 431 ms 96676 KB Output is correct
8 Correct 303 ms 97344 KB Output is correct
9 Correct 941 ms 105052 KB Output is correct
10 Correct 442 ms 104764 KB Output is correct
11 Correct 888 ms 96168 KB Output is correct
12 Correct 394 ms 96740 KB Output is correct
13 Correct 306 ms 97100 KB Output is correct
14 Correct 277 ms 97412 KB Output is correct
15 Correct 278 ms 96700 KB Output is correct
16 Correct 312 ms 97324 KB Output is correct
17 Correct 302 ms 97764 KB Output is correct
18 Correct 5 ms 7768 KB Output is correct
19 Correct 4 ms 7768 KB Output is correct
20 Correct 4 ms 7768 KB Output is correct
21 Correct 5 ms 7756 KB Output is correct
22 Correct 4 ms 7772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7772 KB Output is correct
2 Correct 942 ms 91552 KB Output is correct
3 Correct 454 ms 96804 KB Output is correct
4 Correct 629 ms 102192 KB Output is correct
5 Correct 720 ms 96384 KB Output is correct
6 Correct 415 ms 95976 KB Output is correct
7 Correct 431 ms 96676 KB Output is correct
8 Correct 303 ms 97344 KB Output is correct
9 Correct 941 ms 105052 KB Output is correct
10 Correct 442 ms 104764 KB Output is correct
11 Correct 888 ms 96168 KB Output is correct
12 Correct 394 ms 96740 KB Output is correct
13 Correct 306 ms 97100 KB Output is correct
14 Correct 277 ms 97412 KB Output is correct
15 Correct 278 ms 96700 KB Output is correct
16 Correct 312 ms 97324 KB Output is correct
17 Correct 302 ms 97764 KB Output is correct
18 Correct 5 ms 7768 KB Output is correct
19 Correct 4 ms 7768 KB Output is correct
20 Correct 4 ms 7768 KB Output is correct
21 Correct 5 ms 7756 KB Output is correct
22 Correct 4 ms 7772 KB Output is correct
23 Correct 5 ms 7772 KB Output is correct
24 Correct 917 ms 96456 KB Output is correct
25 Correct 426 ms 97088 KB Output is correct
26 Correct 669 ms 105040 KB Output is correct
27 Correct 689 ms 96408 KB Output is correct
28 Correct 443 ms 96488 KB Output is correct
29 Correct 384 ms 96196 KB Output is correct
30 Correct 316 ms 97224 KB Output is correct
31 Correct 900 ms 102488 KB Output is correct
32 Correct 444 ms 104884 KB Output is correct
33 Correct 889 ms 96100 KB Output is correct
34 Correct 483 ms 96804 KB Output is correct
35 Correct 5 ms 7768 KB Output is correct
36 Correct 5 ms 7772 KB Output is correct
37 Correct 4 ms 7772 KB Output is correct
38 Correct 5 ms 7736 KB Output is correct
39 Correct 4 ms 7768 KB Output is correct
40 Correct 5 ms 7764 KB Output is correct
41 Correct 6 ms 7772 KB Output is correct
42 Correct 4 ms 7768 KB Output is correct
43 Correct 4 ms 7772 KB Output is correct
44 Correct 4 ms 7772 KB Output is correct
45 Correct 4 ms 7772 KB Output is correct
46 Correct 4 ms 7772 KB Output is correct
47 Correct 4 ms 7772 KB Output is correct
48 Correct 5 ms 7772 KB Output is correct
49 Correct 5 ms 7772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7768 KB Output is correct
2 Correct 969 ms 101256 KB Output is correct
3 Correct 726 ms 100952 KB Output is correct
4 Correct 729 ms 100692 KB Output is correct
5 Correct 779 ms 93520 KB Output is correct
6 Correct 442 ms 94212 KB Output is correct
7 Correct 390 ms 93840 KB Output is correct
8 Correct 328 ms 94320 KB Output is correct
9 Correct 1008 ms 99736 KB Output is correct
10 Correct 821 ms 101956 KB Output is correct
11 Correct 994 ms 93248 KB Output is correct
12 Correct 749 ms 94152 KB Output is correct
13 Correct 558 ms 95224 KB Output is correct
14 Correct 502 ms 95312 KB Output is correct
15 Correct 4 ms 7772 KB Output is correct
16 Correct 4 ms 7772 KB Output is correct
17 Correct 4 ms 7768 KB Output is correct
18 Correct 3 ms 7772 KB Output is correct
19 Correct 4 ms 7768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7772 KB Output is correct
2 Correct 1022 ms 101692 KB Output is correct
3 Correct 746 ms 98880 KB Output is correct
4 Correct 849 ms 100368 KB Output is correct
5 Correct 848 ms 95204 KB Output is correct
6 Correct 529 ms 95180 KB Output is correct
7 Correct 484 ms 95044 KB Output is correct
8 Correct 355 ms 95296 KB Output is correct
9 Correct 996 ms 104144 KB Output is correct
10 Correct 828 ms 102808 KB Output is correct
11 Correct 990 ms 95808 KB Output is correct
12 Correct 781 ms 94228 KB Output is correct
13 Correct 526 ms 94944 KB Output is correct
14 Correct 579 ms 95568 KB Output is correct
15 Correct 4 ms 7768 KB Output is correct
16 Correct 5 ms 7772 KB Output is correct
17 Correct 5 ms 7772 KB Output is correct
18 Correct 4 ms 8020 KB Output is correct
19 Correct 4 ms 7772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7768 KB Output is correct
2 Correct 5 ms 7772 KB Output is correct
3 Correct 4 ms 7772 KB Output is correct
4 Correct 4 ms 8028 KB Output is correct
5 Correct 5 ms 8284 KB Output is correct
6 Correct 4 ms 8048 KB Output is correct
7 Correct 6 ms 8284 KB Output is correct
8 Correct 5 ms 8284 KB Output is correct
9 Correct 5 ms 7772 KB Output is correct
10 Correct 4 ms 7772 KB Output is correct
11 Correct 4 ms 7772 KB Output is correct
12 Correct 4 ms 7772 KB Output is correct
13 Correct 7 ms 7924 KB Output is correct
14 Correct 4 ms 7768 KB Output is correct
15 Correct 4 ms 7768 KB Output is correct
16 Correct 4 ms 7772 KB Output is correct
17 Correct 4 ms 7772 KB Output is correct
18 Correct 4 ms 7772 KB Output is correct
19 Correct 4 ms 7772 KB Output is correct
20 Correct 4 ms 7772 KB Output is correct
21 Correct 4 ms 7772 KB Output is correct
22 Correct 4 ms 7772 KB Output is correct
23 Correct 4 ms 7772 KB Output is correct
24 Correct 4 ms 7772 KB Output is correct
25 Correct 4 ms 7772 KB Output is correct
26 Correct 4 ms 7772 KB Output is correct
27 Correct 4 ms 7772 KB Output is correct
28 Correct 4 ms 7768 KB Output is correct
29 Correct 4 ms 7772 KB Output is correct
30 Correct 942 ms 91552 KB Output is correct
31 Correct 454 ms 96804 KB Output is correct
32 Correct 629 ms 102192 KB Output is correct
33 Correct 720 ms 96384 KB Output is correct
34 Correct 415 ms 95976 KB Output is correct
35 Correct 431 ms 96676 KB Output is correct
36 Correct 303 ms 97344 KB Output is correct
37 Correct 941 ms 105052 KB Output is correct
38 Correct 442 ms 104764 KB Output is correct
39 Correct 888 ms 96168 KB Output is correct
40 Correct 394 ms 96740 KB Output is correct
41 Correct 306 ms 97100 KB Output is correct
42 Correct 277 ms 97412 KB Output is correct
43 Correct 278 ms 96700 KB Output is correct
44 Correct 312 ms 97324 KB Output is correct
45 Correct 302 ms 97764 KB Output is correct
46 Correct 5 ms 7768 KB Output is correct
47 Correct 4 ms 7768 KB Output is correct
48 Correct 4 ms 7768 KB Output is correct
49 Correct 5 ms 7756 KB Output is correct
50 Correct 4 ms 7772 KB Output is correct
51 Correct 5 ms 7772 KB Output is correct
52 Correct 917 ms 96456 KB Output is correct
53 Correct 426 ms 97088 KB Output is correct
54 Correct 669 ms 105040 KB Output is correct
55 Correct 689 ms 96408 KB Output is correct
56 Correct 443 ms 96488 KB Output is correct
57 Correct 384 ms 96196 KB Output is correct
58 Correct 316 ms 97224 KB Output is correct
59 Correct 900 ms 102488 KB Output is correct
60 Correct 444 ms 104884 KB Output is correct
61 Correct 889 ms 96100 KB Output is correct
62 Correct 483 ms 96804 KB Output is correct
63 Correct 5 ms 7768 KB Output is correct
64 Correct 5 ms 7772 KB Output is correct
65 Correct 4 ms 7772 KB Output is correct
66 Correct 5 ms 7736 KB Output is correct
67 Correct 4 ms 7768 KB Output is correct
68 Correct 5 ms 7764 KB Output is correct
69 Correct 6 ms 7772 KB Output is correct
70 Correct 4 ms 7768 KB Output is correct
71 Correct 4 ms 7772 KB Output is correct
72 Correct 4 ms 7772 KB Output is correct
73 Correct 4 ms 7772 KB Output is correct
74 Correct 4 ms 7772 KB Output is correct
75 Correct 4 ms 7772 KB Output is correct
76 Correct 5 ms 7772 KB Output is correct
77 Correct 5 ms 7772 KB Output is correct
78 Correct 3 ms 7768 KB Output is correct
79 Correct 969 ms 101256 KB Output is correct
80 Correct 726 ms 100952 KB Output is correct
81 Correct 729 ms 100692 KB Output is correct
82 Correct 779 ms 93520 KB Output is correct
83 Correct 442 ms 94212 KB Output is correct
84 Correct 390 ms 93840 KB Output is correct
85 Correct 328 ms 94320 KB Output is correct
86 Correct 1008 ms 99736 KB Output is correct
87 Correct 821 ms 101956 KB Output is correct
88 Correct 994 ms 93248 KB Output is correct
89 Correct 749 ms 94152 KB Output is correct
90 Correct 558 ms 95224 KB Output is correct
91 Correct 502 ms 95312 KB Output is correct
92 Correct 4 ms 7772 KB Output is correct
93 Correct 4 ms 7772 KB Output is correct
94 Correct 4 ms 7768 KB Output is correct
95 Correct 3 ms 7772 KB Output is correct
96 Correct 4 ms 7768 KB Output is correct
97 Correct 3 ms 7772 KB Output is correct
98 Correct 1022 ms 101692 KB Output is correct
99 Correct 746 ms 98880 KB Output is correct
100 Correct 849 ms 100368 KB Output is correct
101 Correct 848 ms 95204 KB Output is correct
102 Correct 529 ms 95180 KB Output is correct
103 Correct 484 ms 95044 KB Output is correct
104 Correct 355 ms 95296 KB Output is correct
105 Correct 996 ms 104144 KB Output is correct
106 Correct 828 ms 102808 KB Output is correct
107 Correct 990 ms 95808 KB Output is correct
108 Correct 781 ms 94228 KB Output is correct
109 Correct 526 ms 94944 KB Output is correct
110 Correct 579 ms 95568 KB Output is correct
111 Correct 4 ms 7768 KB Output is correct
112 Correct 5 ms 7772 KB Output is correct
113 Correct 5 ms 7772 KB Output is correct
114 Correct 4 ms 8020 KB Output is correct
115 Correct 4 ms 7772 KB Output is correct
116 Correct 1014 ms 96088 KB Output is correct
117 Correct 743 ms 97108 KB Output is correct
118 Correct 819 ms 105152 KB Output is correct
119 Correct 751 ms 96756 KB Output is correct
120 Correct 522 ms 96344 KB Output is correct
121 Correct 461 ms 96920 KB Output is correct
122 Correct 374 ms 97336 KB Output is correct
123 Correct 1034 ms 103492 KB Output is correct
124 Correct 705 ms 101892 KB Output is correct
125 Correct 887 ms 95440 KB Output is correct
126 Correct 690 ms 96852 KB Output is correct
127 Correct 722 ms 97748 KB Output is correct
128 Correct 593 ms 97924 KB Output is correct
129 Correct 629 ms 98516 KB Output is correct