답안 #544702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544702 2022-04-02T15:06:42 Z kevinxiehk Sprinkler (JOI22_sprinkler) C++17
100 / 100
1084 ms 93796 KB
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define iint long long
#define int long long
#define inf 1e18
#define ick cout<<"ickbmi32.9\n"
using namespace std;
int mod;
int n;
vector<int> conn[200005];
int fa[200005];
// unordered_map<int, iint> no[200005][4]; // no[fa][dist][chd] = need
iint h[200005];
iint mul[200005][45];
// iint bm(iint a, iint b) {
//     if(b == 0) return 1; 
//     iint t = bm(a, b / 2); 
//     t = t * t % mod; 
//     return (b % 2 == 1 ? t * a % mod : t);
// }
// int phi(int n) {
//     iint result = n;
//     for(int p = 2; p * p <= n; p++) {
//         if (n % p == 0) {
//             while (n % p == 0) n /= p; 
//             result = result * (p - 1) / p;
//         }
//     }
//     if (n > 1) result = result * (n - 1) / n;
//     return result;
// }
// int phimod;
// int inv(int a) {return bm(a, phimod - 1);}
void dfs(int now, int f) {
    for(auto x: conn[now]) {
        if(x == f) continue;
        // for(int i = 0; i <= 41; i++) no[now][i][x] = 1;
        fa[x] = now;
        dfs(x, now);
    }
}

int getres(int id, int di, int fm) {
    iint res = 1;
    if(id != 1) res = res * mul[id][di] % mod * mul[id][di + 1] % mod;
    else for(int i = di; i <= 40; i++) res = res * mul[1][i] % mod;
    // if(fm != -1) {
    //     for(int i = di; i <= 3; i++) res = res * no[id][i][fm] % mod;
    // } 
    if(di < 40 && fa[id] != 0) res = res * getres(fa[id], di + 1, id) % mod;
    return res % mod;
}   

// int invk;

void updval(int id, int di, int fm, int k) {
    mul[id][di] = mul[id][di] * k % mod;
    // if(fm != -1) no[id][di][fm] = no[id][di][fm] * invk % mod;
    if(di == 0 || fa[id] == 0) return;
    updval(fa[id], di - 1, id, k);
}   

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0);
    cin >> n >> mod;
    // phimod = phi(mod);
    int t, tt, ttt;
    for(int i = 1; i < n; i++) {
        cin >> t >> tt;
        conn[t].pb(tt);
        conn[tt].pb(t);
    }
    for(int i = 1; i <= n; i++) cin >> h[i];
    for(int i = 1; i <= n; i++) for(int j = 0; j <= 41; j++) mul[i][j] = 1;
    dfs(1, 1);
    int q;
    cin >> q;
    while(q--) {
        cin >> t;
        if(t == 1) {
            cin >> t >> tt >> ttt;
            // invk = inv(ttt);
            updval(t, tt, -1, ttt);
        }
        else {
            cin >> t;
            cout << h[t] * getres(t, 0, -1) % mod << '\n';
        }
    }
    return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5456 KB Output is correct
5 Correct 4 ms 5460 KB Output is correct
6 Correct 4 ms 5460 KB Output is correct
7 Correct 4 ms 5460 KB Output is correct
8 Correct 4 ms 5460 KB Output is correct
9 Correct 4 ms 5044 KB Output is correct
10 Correct 4 ms 5052 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 4 ms 5052 KB Output is correct
13 Correct 4 ms 4948 KB Output is correct
14 Correct 3 ms 5052 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 5 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 4 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 775 ms 89488 KB Output is correct
3 Correct 405 ms 86272 KB Output is correct
4 Correct 667 ms 90368 KB Output is correct
5 Correct 558 ms 88056 KB Output is correct
6 Correct 419 ms 89024 KB Output is correct
7 Correct 461 ms 88164 KB Output is correct
8 Correct 286 ms 88420 KB Output is correct
9 Correct 804 ms 93796 KB Output is correct
10 Correct 414 ms 90188 KB Output is correct
11 Correct 763 ms 89424 KB Output is correct
12 Correct 377 ms 86272 KB Output is correct
13 Correct 239 ms 86596 KB Output is correct
14 Correct 246 ms 86696 KB Output is correct
15 Correct 239 ms 86608 KB Output is correct
16 Correct 239 ms 86568 KB Output is correct
17 Correct 258 ms 87132 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 4 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 775 ms 89488 KB Output is correct
3 Correct 405 ms 86272 KB Output is correct
4 Correct 667 ms 90368 KB Output is correct
5 Correct 558 ms 88056 KB Output is correct
6 Correct 419 ms 89024 KB Output is correct
7 Correct 461 ms 88164 KB Output is correct
8 Correct 286 ms 88420 KB Output is correct
9 Correct 804 ms 93796 KB Output is correct
10 Correct 414 ms 90188 KB Output is correct
11 Correct 763 ms 89424 KB Output is correct
12 Correct 377 ms 86272 KB Output is correct
13 Correct 239 ms 86596 KB Output is correct
14 Correct 246 ms 86696 KB Output is correct
15 Correct 239 ms 86608 KB Output is correct
16 Correct 239 ms 86568 KB Output is correct
17 Correct 258 ms 87132 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 4 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 745 ms 89440 KB Output is correct
25 Correct 379 ms 86248 KB Output is correct
26 Correct 621 ms 91924 KB Output is correct
27 Correct 555 ms 87856 KB Output is correct
28 Correct 433 ms 87936 KB Output is correct
29 Correct 369 ms 88072 KB Output is correct
30 Correct 281 ms 88452 KB Output is correct
31 Correct 808 ms 92236 KB Output is correct
32 Correct 399 ms 90148 KB Output is correct
33 Correct 730 ms 89412 KB Output is correct
34 Correct 379 ms 86456 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 4 ms 5048 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 4 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 4 ms 4948 KB Output is correct
41 Correct 5 ms 4948 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 3 ms 4948 KB Output is correct
45 Correct 4 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 909 ms 91068 KB Output is correct
3 Correct 675 ms 88940 KB Output is correct
4 Correct 669 ms 89528 KB Output is correct
5 Correct 614 ms 86388 KB Output is correct
6 Correct 418 ms 86520 KB Output is correct
7 Correct 379 ms 86600 KB Output is correct
8 Correct 264 ms 86820 KB Output is correct
9 Correct 854 ms 89484 KB Output is correct
10 Correct 732 ms 89908 KB Output is correct
11 Correct 804 ms 86832 KB Output is correct
12 Correct 623 ms 85988 KB Output is correct
13 Correct 381 ms 86868 KB Output is correct
14 Correct 402 ms 87652 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4920 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4948 KB Output is correct
2 Correct 1002 ms 91964 KB Output is correct
3 Correct 662 ms 88012 KB Output is correct
4 Correct 675 ms 89992 KB Output is correct
5 Correct 657 ms 87872 KB Output is correct
6 Correct 452 ms 87976 KB Output is correct
7 Correct 410 ms 88012 KB Output is correct
8 Correct 290 ms 88292 KB Output is correct
9 Correct 855 ms 93280 KB Output is correct
10 Correct 669 ms 90268 KB Output is correct
11 Correct 745 ms 89460 KB Output is correct
12 Correct 594 ms 86276 KB Output is correct
13 Correct 380 ms 86996 KB Output is correct
14 Correct 406 ms 87760 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 4 ms 5020 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5456 KB Output is correct
5 Correct 4 ms 5460 KB Output is correct
6 Correct 4 ms 5460 KB Output is correct
7 Correct 4 ms 5460 KB Output is correct
8 Correct 4 ms 5460 KB Output is correct
9 Correct 4 ms 5044 KB Output is correct
10 Correct 4 ms 5052 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 4 ms 5052 KB Output is correct
13 Correct 4 ms 4948 KB Output is correct
14 Correct 3 ms 5052 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 5 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 4 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 775 ms 89488 KB Output is correct
31 Correct 405 ms 86272 KB Output is correct
32 Correct 667 ms 90368 KB Output is correct
33 Correct 558 ms 88056 KB Output is correct
34 Correct 419 ms 89024 KB Output is correct
35 Correct 461 ms 88164 KB Output is correct
36 Correct 286 ms 88420 KB Output is correct
37 Correct 804 ms 93796 KB Output is correct
38 Correct 414 ms 90188 KB Output is correct
39 Correct 763 ms 89424 KB Output is correct
40 Correct 377 ms 86272 KB Output is correct
41 Correct 239 ms 86596 KB Output is correct
42 Correct 246 ms 86696 KB Output is correct
43 Correct 239 ms 86608 KB Output is correct
44 Correct 239 ms 86568 KB Output is correct
45 Correct 258 ms 87132 KB Output is correct
46 Correct 4 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 4 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 745 ms 89440 KB Output is correct
53 Correct 379 ms 86248 KB Output is correct
54 Correct 621 ms 91924 KB Output is correct
55 Correct 555 ms 87856 KB Output is correct
56 Correct 433 ms 87936 KB Output is correct
57 Correct 369 ms 88072 KB Output is correct
58 Correct 281 ms 88452 KB Output is correct
59 Correct 808 ms 92236 KB Output is correct
60 Correct 399 ms 90148 KB Output is correct
61 Correct 730 ms 89412 KB Output is correct
62 Correct 379 ms 86456 KB Output is correct
63 Correct 3 ms 4948 KB Output is correct
64 Correct 4 ms 5048 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 4 ms 4948 KB Output is correct
67 Correct 3 ms 4948 KB Output is correct
68 Correct 4 ms 4948 KB Output is correct
69 Correct 5 ms 4948 KB Output is correct
70 Correct 3 ms 4948 KB Output is correct
71 Correct 3 ms 4948 KB Output is correct
72 Correct 3 ms 4948 KB Output is correct
73 Correct 4 ms 4948 KB Output is correct
74 Correct 3 ms 4948 KB Output is correct
75 Correct 3 ms 4948 KB Output is correct
76 Correct 3 ms 4948 KB Output is correct
77 Correct 3 ms 4948 KB Output is correct
78 Correct 3 ms 4948 KB Output is correct
79 Correct 909 ms 91068 KB Output is correct
80 Correct 675 ms 88940 KB Output is correct
81 Correct 669 ms 89528 KB Output is correct
82 Correct 614 ms 86388 KB Output is correct
83 Correct 418 ms 86520 KB Output is correct
84 Correct 379 ms 86600 KB Output is correct
85 Correct 264 ms 86820 KB Output is correct
86 Correct 854 ms 89484 KB Output is correct
87 Correct 732 ms 89908 KB Output is correct
88 Correct 804 ms 86832 KB Output is correct
89 Correct 623 ms 85988 KB Output is correct
90 Correct 381 ms 86868 KB Output is correct
91 Correct 402 ms 87652 KB Output is correct
92 Correct 3 ms 4948 KB Output is correct
93 Correct 4 ms 4920 KB Output is correct
94 Correct 3 ms 4948 KB Output is correct
95 Correct 3 ms 4948 KB Output is correct
96 Correct 3 ms 4948 KB Output is correct
97 Correct 5 ms 4948 KB Output is correct
98 Correct 1002 ms 91964 KB Output is correct
99 Correct 662 ms 88012 KB Output is correct
100 Correct 675 ms 89992 KB Output is correct
101 Correct 657 ms 87872 KB Output is correct
102 Correct 452 ms 87976 KB Output is correct
103 Correct 410 ms 88012 KB Output is correct
104 Correct 290 ms 88292 KB Output is correct
105 Correct 855 ms 93280 KB Output is correct
106 Correct 669 ms 90268 KB Output is correct
107 Correct 745 ms 89460 KB Output is correct
108 Correct 594 ms 86276 KB Output is correct
109 Correct 380 ms 86996 KB Output is correct
110 Correct 406 ms 87760 KB Output is correct
111 Correct 3 ms 4948 KB Output is correct
112 Correct 3 ms 4948 KB Output is correct
113 Correct 4 ms 4948 KB Output is correct
114 Correct 4 ms 5020 KB Output is correct
115 Correct 3 ms 4948 KB Output is correct
116 Correct 793 ms 87428 KB Output is correct
117 Correct 652 ms 85996 KB Output is correct
118 Correct 701 ms 91800 KB Output is correct
119 Correct 668 ms 87756 KB Output is correct
120 Correct 451 ms 87824 KB Output is correct
121 Correct 456 ms 88132 KB Output is correct
122 Correct 324 ms 88376 KB Output is correct
123 Correct 1043 ms 92804 KB Output is correct
124 Correct 866 ms 88428 KB Output is correct
125 Correct 1084 ms 88756 KB Output is correct
126 Correct 779 ms 86108 KB Output is correct
127 Correct 896 ms 86044 KB Output is correct
128 Correct 523 ms 87088 KB Output is correct
129 Correct 529 ms 87856 KB Output is correct