답안 #799571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
799571 2023-07-31T16:05:21 Z eltu0815 Sprinkler (JOI22_sprinkler) C++14
100 / 100
807 ms 165328 KB
#include <bits/stdc++.h>
#define MAX 500005
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
 
using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
 
ll n, m, k, q, l, tt;
ll arr[MAX], par[MAX][41], dp[MAX][41];
vector<ll> graph[MAX];

void dfs(ll node, ll p) {
    par[node][1] = p;
    for(auto v : graph[node]) if(v != p) dfs(v, node);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n >> l;
    for(ll i = 1; i <= n - 1; ++i) {
        ll a, b; cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    for(ll i = 1; i <= n; ++i) cin >> arr[i];
    for(ll i = 0; i <= n; ++i) for(ll k = 0; k <= 40; ++k) dp[i][k] = 1;
    for(ll i = 0; i <= n; ++i) par[i][0] = i;
    dfs(1, 0);
    for(ll k = 2; k <= 40; ++k) for(ll i = 1; i <= n; ++i) par[i][k] = par[par[i][k - 1]][1];
    
    
    cin >> q;
    for(ll i = 1; i <= q; ++i) {
        ll t; cin >> t;
        if(t == 1) {
            ll x, d, w; cin >> x >> d >> w;
            for(ll i = 0; i <= d; ++i) {
                dp[par[x][i]][d - i] = dp[par[x][i]][d - i] * w % l;
                if(par[x][i] == 0) break;
            }
        }
        else {
            ll x; cin >> x;
            ll ans = arr[x];
            for(ll j = 0; j <= 40; ++j) {
                if(par[x][j] == 0) {
                    for(ll k = j; k <= 40; ++k) ans = ans * dp[par[x][j]][k] % l;
                    break;
                }
                ans = ans * dp[par[x][j]][j] % l;
                if(j < 40) ans = ans * dp[par[x][j]][j + 1] % l;
            }
            cout << ans << '\n';
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 6 ms 12072 KB Output is correct
4 Correct 7 ms 12724 KB Output is correct
5 Correct 9 ms 12756 KB Output is correct
6 Correct 9 ms 12724 KB Output is correct
7 Correct 6 ms 12728 KB Output is correct
8 Correct 7 ms 12784 KB Output is correct
9 Correct 6 ms 12076 KB Output is correct
10 Correct 6 ms 11988 KB Output is correct
11 Correct 6 ms 12024 KB Output is correct
12 Correct 5 ms 12080 KB Output is correct
13 Correct 8 ms 12028 KB Output is correct
14 Correct 7 ms 11988 KB Output is correct
15 Correct 6 ms 11996 KB Output is correct
16 Correct 6 ms 11988 KB Output is correct
17 Correct 6 ms 12080 KB Output is correct
18 Correct 6 ms 12084 KB Output is correct
19 Correct 6 ms 12084 KB Output is correct
20 Correct 7 ms 11988 KB Output is correct
21 Correct 8 ms 11988 KB Output is correct
22 Correct 7 ms 12076 KB Output is correct
23 Correct 7 ms 11988 KB Output is correct
24 Correct 7 ms 11988 KB Output is correct
25 Correct 6 ms 12100 KB Output is correct
26 Correct 6 ms 12080 KB Output is correct
27 Correct 6 ms 12068 KB Output is correct
28 Correct 7 ms 12076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 696 ms 161016 KB Output is correct
3 Correct 474 ms 161600 KB Output is correct
4 Correct 681 ms 163428 KB Output is correct
5 Correct 603 ms 161276 KB Output is correct
6 Correct 449 ms 160952 KB Output is correct
7 Correct 424 ms 161656 KB Output is correct
8 Correct 408 ms 161888 KB Output is correct
9 Correct 782 ms 164884 KB Output is correct
10 Correct 531 ms 165328 KB Output is correct
11 Correct 651 ms 160652 KB Output is correct
12 Correct 550 ms 161596 KB Output is correct
13 Correct 298 ms 161656 KB Output is correct
14 Correct 306 ms 162136 KB Output is correct
15 Correct 288 ms 161416 KB Output is correct
16 Correct 295 ms 162000 KB Output is correct
17 Correct 295 ms 162472 KB Output is correct
18 Correct 6 ms 11988 KB Output is correct
19 Correct 6 ms 12084 KB Output is correct
20 Correct 9 ms 12076 KB Output is correct
21 Correct 6 ms 12084 KB Output is correct
22 Correct 9 ms 12080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 696 ms 161016 KB Output is correct
3 Correct 474 ms 161600 KB Output is correct
4 Correct 681 ms 163428 KB Output is correct
5 Correct 603 ms 161276 KB Output is correct
6 Correct 449 ms 160952 KB Output is correct
7 Correct 424 ms 161656 KB Output is correct
8 Correct 408 ms 161888 KB Output is correct
9 Correct 782 ms 164884 KB Output is correct
10 Correct 531 ms 165328 KB Output is correct
11 Correct 651 ms 160652 KB Output is correct
12 Correct 550 ms 161596 KB Output is correct
13 Correct 298 ms 161656 KB Output is correct
14 Correct 306 ms 162136 KB Output is correct
15 Correct 288 ms 161416 KB Output is correct
16 Correct 295 ms 162000 KB Output is correct
17 Correct 295 ms 162472 KB Output is correct
18 Correct 6 ms 11988 KB Output is correct
19 Correct 6 ms 12084 KB Output is correct
20 Correct 9 ms 12076 KB Output is correct
21 Correct 6 ms 12084 KB Output is correct
22 Correct 9 ms 12080 KB Output is correct
23 Correct 11 ms 12056 KB Output is correct
24 Correct 728 ms 161084 KB Output is correct
25 Correct 474 ms 161544 KB Output is correct
26 Correct 688 ms 165156 KB Output is correct
27 Correct 532 ms 161236 KB Output is correct
28 Correct 467 ms 161520 KB Output is correct
29 Correct 465 ms 161224 KB Output is correct
30 Correct 392 ms 162092 KB Output is correct
31 Correct 737 ms 163492 KB Output is correct
32 Correct 495 ms 165088 KB Output is correct
33 Correct 614 ms 161116 KB Output is correct
34 Correct 464 ms 161528 KB Output is correct
35 Correct 7 ms 12104 KB Output is correct
36 Correct 6 ms 12084 KB Output is correct
37 Correct 6 ms 11988 KB Output is correct
38 Correct 8 ms 12116 KB Output is correct
39 Correct 8 ms 12116 KB Output is correct
40 Correct 6 ms 12072 KB Output is correct
41 Correct 6 ms 11988 KB Output is correct
42 Correct 6 ms 12076 KB Output is correct
43 Correct 6 ms 12076 KB Output is correct
44 Correct 8 ms 11988 KB Output is correct
45 Correct 8 ms 11988 KB Output is correct
46 Correct 8 ms 12020 KB Output is correct
47 Correct 10 ms 11992 KB Output is correct
48 Correct 8 ms 12072 KB Output is correct
49 Correct 7 ms 12116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12068 KB Output is correct
2 Correct 807 ms 162128 KB Output is correct
3 Correct 784 ms 161556 KB Output is correct
4 Correct 725 ms 161240 KB Output is correct
5 Correct 562 ms 158356 KB Output is correct
6 Correct 463 ms 158600 KB Output is correct
7 Correct 423 ms 158680 KB Output is correct
8 Correct 395 ms 159096 KB Output is correct
9 Correct 785 ms 160608 KB Output is correct
10 Correct 702 ms 162192 KB Output is correct
11 Correct 578 ms 158032 KB Output is correct
12 Correct 558 ms 158860 KB Output is correct
13 Correct 407 ms 159900 KB Output is correct
14 Correct 412 ms 160580 KB Output is correct
15 Correct 6 ms 11988 KB Output is correct
16 Correct 6 ms 11988 KB Output is correct
17 Correct 6 ms 12084 KB Output is correct
18 Correct 5 ms 11988 KB Output is correct
19 Correct 6 ms 12076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 771 ms 163080 KB Output is correct
3 Correct 718 ms 160712 KB Output is correct
4 Correct 667 ms 161760 KB Output is correct
5 Correct 525 ms 160028 KB Output is correct
6 Correct 460 ms 160112 KB Output is correct
7 Correct 464 ms 159948 KB Output is correct
8 Correct 400 ms 160020 KB Output is correct
9 Correct 764 ms 164384 KB Output is correct
10 Correct 694 ms 162836 KB Output is correct
11 Correct 580 ms 160716 KB Output is correct
12 Correct 521 ms 159180 KB Output is correct
13 Correct 412 ms 159984 KB Output is correct
14 Correct 406 ms 160752 KB Output is correct
15 Correct 6 ms 11988 KB Output is correct
16 Correct 6 ms 11988 KB Output is correct
17 Correct 7 ms 12120 KB Output is correct
18 Correct 6 ms 12116 KB Output is correct
19 Correct 5 ms 12116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 6 ms 12072 KB Output is correct
4 Correct 7 ms 12724 KB Output is correct
5 Correct 9 ms 12756 KB Output is correct
6 Correct 9 ms 12724 KB Output is correct
7 Correct 6 ms 12728 KB Output is correct
8 Correct 7 ms 12784 KB Output is correct
9 Correct 6 ms 12076 KB Output is correct
10 Correct 6 ms 11988 KB Output is correct
11 Correct 6 ms 12024 KB Output is correct
12 Correct 5 ms 12080 KB Output is correct
13 Correct 8 ms 12028 KB Output is correct
14 Correct 7 ms 11988 KB Output is correct
15 Correct 6 ms 11996 KB Output is correct
16 Correct 6 ms 11988 KB Output is correct
17 Correct 6 ms 12080 KB Output is correct
18 Correct 6 ms 12084 KB Output is correct
19 Correct 6 ms 12084 KB Output is correct
20 Correct 7 ms 11988 KB Output is correct
21 Correct 8 ms 11988 KB Output is correct
22 Correct 7 ms 12076 KB Output is correct
23 Correct 7 ms 11988 KB Output is correct
24 Correct 7 ms 11988 KB Output is correct
25 Correct 6 ms 12100 KB Output is correct
26 Correct 6 ms 12080 KB Output is correct
27 Correct 6 ms 12068 KB Output is correct
28 Correct 7 ms 12076 KB Output is correct
29 Correct 6 ms 11988 KB Output is correct
30 Correct 696 ms 161016 KB Output is correct
31 Correct 474 ms 161600 KB Output is correct
32 Correct 681 ms 163428 KB Output is correct
33 Correct 603 ms 161276 KB Output is correct
34 Correct 449 ms 160952 KB Output is correct
35 Correct 424 ms 161656 KB Output is correct
36 Correct 408 ms 161888 KB Output is correct
37 Correct 782 ms 164884 KB Output is correct
38 Correct 531 ms 165328 KB Output is correct
39 Correct 651 ms 160652 KB Output is correct
40 Correct 550 ms 161596 KB Output is correct
41 Correct 298 ms 161656 KB Output is correct
42 Correct 306 ms 162136 KB Output is correct
43 Correct 288 ms 161416 KB Output is correct
44 Correct 295 ms 162000 KB Output is correct
45 Correct 295 ms 162472 KB Output is correct
46 Correct 6 ms 11988 KB Output is correct
47 Correct 6 ms 12084 KB Output is correct
48 Correct 9 ms 12076 KB Output is correct
49 Correct 6 ms 12084 KB Output is correct
50 Correct 9 ms 12080 KB Output is correct
51 Correct 11 ms 12056 KB Output is correct
52 Correct 728 ms 161084 KB Output is correct
53 Correct 474 ms 161544 KB Output is correct
54 Correct 688 ms 165156 KB Output is correct
55 Correct 532 ms 161236 KB Output is correct
56 Correct 467 ms 161520 KB Output is correct
57 Correct 465 ms 161224 KB Output is correct
58 Correct 392 ms 162092 KB Output is correct
59 Correct 737 ms 163492 KB Output is correct
60 Correct 495 ms 165088 KB Output is correct
61 Correct 614 ms 161116 KB Output is correct
62 Correct 464 ms 161528 KB Output is correct
63 Correct 7 ms 12104 KB Output is correct
64 Correct 6 ms 12084 KB Output is correct
65 Correct 6 ms 11988 KB Output is correct
66 Correct 8 ms 12116 KB Output is correct
67 Correct 8 ms 12116 KB Output is correct
68 Correct 6 ms 12072 KB Output is correct
69 Correct 6 ms 11988 KB Output is correct
70 Correct 6 ms 12076 KB Output is correct
71 Correct 6 ms 12076 KB Output is correct
72 Correct 8 ms 11988 KB Output is correct
73 Correct 8 ms 11988 KB Output is correct
74 Correct 8 ms 12020 KB Output is correct
75 Correct 10 ms 11992 KB Output is correct
76 Correct 8 ms 12072 KB Output is correct
77 Correct 7 ms 12116 KB Output is correct
78 Correct 7 ms 12068 KB Output is correct
79 Correct 807 ms 162128 KB Output is correct
80 Correct 784 ms 161556 KB Output is correct
81 Correct 725 ms 161240 KB Output is correct
82 Correct 562 ms 158356 KB Output is correct
83 Correct 463 ms 158600 KB Output is correct
84 Correct 423 ms 158680 KB Output is correct
85 Correct 395 ms 159096 KB Output is correct
86 Correct 785 ms 160608 KB Output is correct
87 Correct 702 ms 162192 KB Output is correct
88 Correct 578 ms 158032 KB Output is correct
89 Correct 558 ms 158860 KB Output is correct
90 Correct 407 ms 159900 KB Output is correct
91 Correct 412 ms 160580 KB Output is correct
92 Correct 6 ms 11988 KB Output is correct
93 Correct 6 ms 11988 KB Output is correct
94 Correct 6 ms 12084 KB Output is correct
95 Correct 5 ms 11988 KB Output is correct
96 Correct 6 ms 12076 KB Output is correct
97 Correct 6 ms 11988 KB Output is correct
98 Correct 771 ms 163080 KB Output is correct
99 Correct 718 ms 160712 KB Output is correct
100 Correct 667 ms 161760 KB Output is correct
101 Correct 525 ms 160028 KB Output is correct
102 Correct 460 ms 160112 KB Output is correct
103 Correct 464 ms 159948 KB Output is correct
104 Correct 400 ms 160020 KB Output is correct
105 Correct 764 ms 164384 KB Output is correct
106 Correct 694 ms 162836 KB Output is correct
107 Correct 580 ms 160716 KB Output is correct
108 Correct 521 ms 159180 KB Output is correct
109 Correct 412 ms 159984 KB Output is correct
110 Correct 406 ms 160752 KB Output is correct
111 Correct 6 ms 11988 KB Output is correct
112 Correct 6 ms 11988 KB Output is correct
113 Correct 7 ms 12120 KB Output is correct
114 Correct 6 ms 12116 KB Output is correct
115 Correct 5 ms 12116 KB Output is correct
116 Correct 609 ms 159052 KB Output is correct
117 Correct 548 ms 161652 KB Output is correct
118 Correct 650 ms 164984 KB Output is correct
119 Correct 550 ms 161348 KB Output is correct
120 Correct 471 ms 160968 KB Output is correct
121 Correct 481 ms 161884 KB Output is correct
122 Correct 437 ms 161976 KB Output is correct
123 Correct 747 ms 164016 KB Output is correct
124 Correct 723 ms 163400 KB Output is correct
125 Correct 623 ms 160224 KB Output is correct
126 Correct 561 ms 161548 KB Output is correct
127 Correct 589 ms 161976 KB Output is correct
128 Correct 482 ms 162656 KB Output is correct
129 Correct 477 ms 163640 KB Output is correct