답안 #661283

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
661283 2022-11-25T07:50:08 Z Alex_tz307 Sprinkler (JOI22_sprinkler) C++17
100 / 100
1530 ms 70072 KB
#include <bits/stdc++.h>

using namespace std;

const int kN = 2e5;
const int kD = 40;
int par[1 + kN + kD];
vector<int> g[1 + kN + kD];

void multSelf(int &x, int y, int mod) {
  x = (int64_t)x * y % mod;
}

void dfs(int u) {
  for (int v : g[u]) {
    if (v != par[u]) {
      par[v] = u;
      dfs(v);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, l;
  cin >> n >> l;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  g[n + 1].emplace_back(1);
  for (int i = n + 2; i <= n + kD; ++i) {
    g[i].emplace_back(i - 1);
  }
  dfs(n + kD);
  vector<int> h(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
  }
  vector<vector<int>> coef(1 + n + kD, vector<int>(1 + kD, 1));
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      int x, d, w;
      cin >> x >> d >> w;
      int node = x, curr = d;
      while (curr >= 0) {
        multSelf(coef[node][curr], w, l);
        node = par[node];
        curr -= 1;
      }
      node = x, curr = d - 1;
      while (curr >= 0) {
        multSelf(coef[node][curr], w, l);
        node = par[node];
        curr -= 1;
      }
    } else {
      int x;
      cin >> x;
      int res = h[x];
      for (int d = 0; d <= kD; ++d) {
        multSelf(res, coef[x][d], l);
        x = par[x];
      }
      cout << res << '\n';
    }
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 4 ms 5292 KB Output is correct
6 Correct 4 ms 5244 KB Output is correct
7 Correct 6 ms 5204 KB Output is correct
8 Correct 4 ms 5204 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 4 ms 4948 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 5032 KB Output is correct
17 Correct 3 ms 5036 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 3 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 4996 KB Output is correct
24 Correct 4 ms 4948 KB Output is correct
25 Correct 3 ms 5032 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 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 554 ms 63780 KB Output is correct
3 Correct 425 ms 64372 KB Output is correct
4 Correct 551 ms 67884 KB Output is correct
5 Correct 507 ms 64104 KB Output is correct
6 Correct 370 ms 63712 KB Output is correct
7 Correct 392 ms 64388 KB Output is correct
8 Correct 339 ms 64908 KB Output is correct
9 Correct 638 ms 69720 KB Output is correct
10 Correct 477 ms 69652 KB Output is correct
11 Correct 578 ms 63816 KB Output is correct
12 Correct 388 ms 64356 KB Output is correct
13 Correct 264 ms 64684 KB Output is correct
14 Correct 245 ms 65124 KB Output is correct
15 Correct 265 ms 64388 KB Output is correct
16 Correct 253 ms 64924 KB Output is correct
17 Correct 286 ms 65456 KB Output is correct
18 Correct 3 ms 5032 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 5032 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 554 ms 63780 KB Output is correct
3 Correct 425 ms 64372 KB Output is correct
4 Correct 551 ms 67884 KB Output is correct
5 Correct 507 ms 64104 KB Output is correct
6 Correct 370 ms 63712 KB Output is correct
7 Correct 392 ms 64388 KB Output is correct
8 Correct 339 ms 64908 KB Output is correct
9 Correct 638 ms 69720 KB Output is correct
10 Correct 477 ms 69652 KB Output is correct
11 Correct 578 ms 63816 KB Output is correct
12 Correct 388 ms 64356 KB Output is correct
13 Correct 264 ms 64684 KB Output is correct
14 Correct 245 ms 65124 KB Output is correct
15 Correct 265 ms 64388 KB Output is correct
16 Correct 253 ms 64924 KB Output is correct
17 Correct 286 ms 65456 KB Output is correct
18 Correct 3 ms 5032 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 5032 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 610 ms 63788 KB Output is correct
25 Correct 468 ms 64512 KB Output is correct
26 Correct 569 ms 70072 KB Output is correct
27 Correct 479 ms 64088 KB Output is correct
28 Correct 383 ms 64224 KB Output is correct
29 Correct 422 ms 63844 KB Output is correct
30 Correct 319 ms 64940 KB Output is correct
31 Correct 691 ms 67972 KB Output is correct
32 Correct 498 ms 69776 KB Output is correct
33 Correct 547 ms 63824 KB Output is correct
34 Correct 424 ms 64332 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 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 3 ms 5020 KB Output is correct
42 Correct 4 ms 4948 KB Output is correct
43 Correct 4 ms 4948 KB Output is correct
44 Correct 3 ms 4948 KB Output is correct
45 Correct 3 ms 5028 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 5032 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 739 ms 59048 KB Output is correct
3 Correct 1427 ms 66304 KB Output is correct
4 Correct 805 ms 65964 KB Output is correct
5 Correct 681 ms 61140 KB Output is correct
6 Correct 440 ms 61248 KB Output is correct
7 Correct 434 ms 61420 KB Output is correct
8 Correct 361 ms 61848 KB Output is correct
9 Correct 790 ms 65016 KB Output is correct
10 Correct 1523 ms 66980 KB Output is correct
11 Correct 686 ms 60748 KB Output is correct
12 Correct 1131 ms 61776 KB Output is correct
13 Correct 712 ms 62624 KB Output is correct
14 Correct 733 ms 63056 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5052 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5028 KB Output is correct
2 Correct 759 ms 59788 KB Output is correct
3 Correct 1483 ms 65144 KB Output is correct
4 Correct 829 ms 66208 KB Output is correct
5 Correct 702 ms 62840 KB Output is correct
6 Correct 472 ms 62956 KB Output is correct
7 Correct 443 ms 62616 KB Output is correct
8 Correct 344 ms 62960 KB Output is correct
9 Correct 803 ms 69072 KB Output is correct
10 Correct 1530 ms 67540 KB Output is correct
11 Correct 614 ms 63564 KB Output is correct
12 Correct 1072 ms 62028 KB Output is correct
13 Correct 654 ms 62832 KB Output is correct
14 Correct 685 ms 63180 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5032 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 3 ms 5032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 4 ms 5292 KB Output is correct
6 Correct 4 ms 5244 KB Output is correct
7 Correct 6 ms 5204 KB Output is correct
8 Correct 4 ms 5204 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 4 ms 4948 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 5032 KB Output is correct
17 Correct 3 ms 5036 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 3 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 4996 KB Output is correct
24 Correct 4 ms 4948 KB Output is correct
25 Correct 3 ms 5032 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 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 554 ms 63780 KB Output is correct
31 Correct 425 ms 64372 KB Output is correct
32 Correct 551 ms 67884 KB Output is correct
33 Correct 507 ms 64104 KB Output is correct
34 Correct 370 ms 63712 KB Output is correct
35 Correct 392 ms 64388 KB Output is correct
36 Correct 339 ms 64908 KB Output is correct
37 Correct 638 ms 69720 KB Output is correct
38 Correct 477 ms 69652 KB Output is correct
39 Correct 578 ms 63816 KB Output is correct
40 Correct 388 ms 64356 KB Output is correct
41 Correct 264 ms 64684 KB Output is correct
42 Correct 245 ms 65124 KB Output is correct
43 Correct 265 ms 64388 KB Output is correct
44 Correct 253 ms 64924 KB Output is correct
45 Correct 286 ms 65456 KB Output is correct
46 Correct 3 ms 5032 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 5032 KB Output is correct
50 Correct 4 ms 4948 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 610 ms 63788 KB Output is correct
53 Correct 468 ms 64512 KB Output is correct
54 Correct 569 ms 70072 KB Output is correct
55 Correct 479 ms 64088 KB Output is correct
56 Correct 383 ms 64224 KB Output is correct
57 Correct 422 ms 63844 KB Output is correct
58 Correct 319 ms 64940 KB Output is correct
59 Correct 691 ms 67972 KB Output is correct
60 Correct 498 ms 69776 KB Output is correct
61 Correct 547 ms 63824 KB Output is correct
62 Correct 424 ms 64332 KB Output is correct
63 Correct 3 ms 4948 KB Output is correct
64 Correct 3 ms 4948 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 3 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 3 ms 5020 KB Output is correct
70 Correct 4 ms 4948 KB Output is correct
71 Correct 4 ms 4948 KB Output is correct
72 Correct 3 ms 4948 KB Output is correct
73 Correct 3 ms 5028 KB Output is correct
74 Correct 3 ms 4948 KB Output is correct
75 Correct 3 ms 5032 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 739 ms 59048 KB Output is correct
80 Correct 1427 ms 66304 KB Output is correct
81 Correct 805 ms 65964 KB Output is correct
82 Correct 681 ms 61140 KB Output is correct
83 Correct 440 ms 61248 KB Output is correct
84 Correct 434 ms 61420 KB Output is correct
85 Correct 361 ms 61848 KB Output is correct
86 Correct 790 ms 65016 KB Output is correct
87 Correct 1523 ms 66980 KB Output is correct
88 Correct 686 ms 60748 KB Output is correct
89 Correct 1131 ms 61776 KB Output is correct
90 Correct 712 ms 62624 KB Output is correct
91 Correct 733 ms 63056 KB Output is correct
92 Correct 3 ms 4948 KB Output is correct
93 Correct 3 ms 5052 KB Output is correct
94 Correct 3 ms 4948 KB Output is correct
95 Correct 3 ms 4948 KB Output is correct
96 Correct 4 ms 4948 KB Output is correct
97 Correct 3 ms 5028 KB Output is correct
98 Correct 759 ms 59788 KB Output is correct
99 Correct 1483 ms 65144 KB Output is correct
100 Correct 829 ms 66208 KB Output is correct
101 Correct 702 ms 62840 KB Output is correct
102 Correct 472 ms 62956 KB Output is correct
103 Correct 443 ms 62616 KB Output is correct
104 Correct 344 ms 62960 KB Output is correct
105 Correct 803 ms 69072 KB Output is correct
106 Correct 1530 ms 67540 KB Output is correct
107 Correct 614 ms 63564 KB Output is correct
108 Correct 1072 ms 62028 KB Output is correct
109 Correct 654 ms 62832 KB Output is correct
110 Correct 685 ms 63180 KB Output is correct
111 Correct 3 ms 4948 KB Output is correct
112 Correct 3 ms 4948 KB Output is correct
113 Correct 3 ms 5032 KB Output is correct
114 Correct 4 ms 4948 KB Output is correct
115 Correct 3 ms 5032 KB Output is correct
116 Correct 649 ms 61980 KB Output is correct
117 Correct 1159 ms 64452 KB Output is correct
118 Correct 841 ms 69900 KB Output is correct
119 Correct 709 ms 64240 KB Output is correct
120 Correct 498 ms 63904 KB Output is correct
121 Correct 475 ms 64588 KB Output is correct
122 Correct 384 ms 64908 KB Output is correct
123 Correct 780 ms 68840 KB Output is correct
124 Correct 1485 ms 67828 KB Output is correct
125 Correct 638 ms 63140 KB Output is correct
126 Correct 1093 ms 64472 KB Output is correct
127 Correct 1107 ms 64900 KB Output is correct
128 Correct 662 ms 65484 KB Output is correct
129 Correct 731 ms 66012 KB Output is correct