답안 #964143

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964143 2024-04-16T11:09:18 Z LucaLucaM Sprinkler (JOI22_sprinkler) C++17
100 / 100
697 ms 59076 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cstring>
#include <queue>
#warning That's not AS, that's my AS

typedef long long ll;

const int NMAX = 2e5;
const int DMAX = 40;

int L;

int mult[NMAX + 1][DMAX + 1];

std::vector<int> g[NMAX + 1];
int parent[NMAX + 1];
int Time[NMAX + 1];
int timer;

void bfs() {
  std::queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    Time[u] = ++timer;
    std::vector<int> newG;
    for (const auto &v : g[u]) {
      if (!Time[v]) {
        parent[v] = u;
        newG.push_back(v);
        q.push(v);
      }
    }
    g[u] = newG;
  }
}

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

  int n;
  std::cin >> n >> L;

  for (int i = 1; i < n; i++) {
    int u, v;
    std::cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  bfs();

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= DMAX; j++) {
      mult[i][j] = 1;
    }
  }

  for (int i = 1; i <= n; i++) {
    int h;
    std::cin >> h;
    mult[i][0] = h;
  }

  int q;
  std::cin >> q;

  while (q--) {
    int type;
    std::cin >> type;
    if (type == 1) {
      int u, d, h;
      std::cin >> u >> d >> h;
      std::vector<std::pair<int, int>> ancestors;
      int v = u;
      while (d >= 0) {
        mult[v][d] = (ll) mult[v][d] * h % L;
        d--;
        if (d >= 0) {
          mult[v][d] = (ll) mult[v][d] * h % L;
        }
        if (v != 1) {
          v = parent[v];
        } else {
          d--;
        }
      }
    } else {
      int u;
      std::cin >> u;
      std::vector<std::pair<int, int>> ancestors;
      int v = u;
      int answer = 1;
      for (int i = 0; i <= DMAX && v != 0; i++) {
        answer = (ll) answer * mult[v][i] % L;
        v = parent[v];
      }
      std::cout << answer << '\n';
    }
  }

  return 0;
}

Compilation message

sprinkler.cpp:7:2: warning: #warning That's not AS, that's my AS [-Wcpp]
    7 | #warning That's not AS, that's my AS
      |  ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 3 ms 8680 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 3 ms 8540 KB Output is correct
8 Correct 2 ms 8536 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6588 KB Output is correct
11 Correct 2 ms 6488 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6632 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6744 KB Output is correct
21 Correct 2 ms 6628 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 2 ms 6488 KB Output is correct
25 Correct 2 ms 6632 KB Output is correct
26 Correct 2 ms 6488 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6620 KB Output is correct
2 Correct 363 ms 56300 KB Output is correct
3 Correct 273 ms 56136 KB Output is correct
4 Correct 423 ms 55908 KB Output is correct
5 Correct 351 ms 56384 KB Output is correct
6 Correct 258 ms 55996 KB Output is correct
7 Correct 230 ms 56660 KB Output is correct
8 Correct 237 ms 58060 KB Output is correct
9 Correct 504 ms 55888 KB Output is correct
10 Correct 276 ms 56012 KB Output is correct
11 Correct 430 ms 56356 KB Output is correct
12 Correct 280 ms 56228 KB Output is correct
13 Correct 207 ms 57756 KB Output is correct
14 Correct 185 ms 56968 KB Output is correct
15 Correct 187 ms 56848 KB Output is correct
16 Correct 201 ms 56868 KB Output is correct
17 Correct 196 ms 57596 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6620 KB Output is correct
2 Correct 363 ms 56300 KB Output is correct
3 Correct 273 ms 56136 KB Output is correct
4 Correct 423 ms 55908 KB Output is correct
5 Correct 351 ms 56384 KB Output is correct
6 Correct 258 ms 55996 KB Output is correct
7 Correct 230 ms 56660 KB Output is correct
8 Correct 237 ms 58060 KB Output is correct
9 Correct 504 ms 55888 KB Output is correct
10 Correct 276 ms 56012 KB Output is correct
11 Correct 430 ms 56356 KB Output is correct
12 Correct 280 ms 56228 KB Output is correct
13 Correct 207 ms 57756 KB Output is correct
14 Correct 185 ms 56968 KB Output is correct
15 Correct 187 ms 56848 KB Output is correct
16 Correct 201 ms 56868 KB Output is correct
17 Correct 196 ms 57596 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 394 ms 56360 KB Output is correct
25 Correct 273 ms 57404 KB Output is correct
26 Correct 384 ms 56968 KB Output is correct
27 Correct 363 ms 57004 KB Output is correct
28 Correct 277 ms 57380 KB Output is correct
29 Correct 256 ms 56952 KB Output is correct
30 Correct 216 ms 59076 KB Output is correct
31 Correct 509 ms 56792 KB Output is correct
32 Correct 305 ms 57156 KB Output is correct
33 Correct 411 ms 56712 KB Output is correct
34 Correct 258 ms 57336 KB Output is correct
35 Correct 2 ms 6628 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 2 ms 6492 KB Output is correct
38 Correct 1 ms 6492 KB Output is correct
39 Correct 2 ms 6488 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6492 KB Output is correct
44 Correct 2 ms 6624 KB Output is correct
45 Correct 1 ms 6492 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 2 ms 6660 KB Output is correct
49 Correct 2 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6628 KB Output is correct
2 Correct 566 ms 53080 KB Output is correct
3 Correct 680 ms 54016 KB Output is correct
4 Correct 536 ms 52388 KB Output is correct
5 Correct 424 ms 52312 KB Output is correct
6 Correct 302 ms 52688 KB Output is correct
7 Correct 261 ms 52724 KB Output is correct
8 Correct 228 ms 54200 KB Output is correct
9 Correct 544 ms 51864 KB Output is correct
10 Correct 625 ms 52500 KB Output is correct
11 Correct 414 ms 52180 KB Output is correct
12 Correct 425 ms 52776 KB Output is correct
13 Correct 335 ms 54188 KB Output is correct
14 Correct 360 ms 55352 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 528 ms 56444 KB Output is correct
3 Correct 697 ms 54800 KB Output is correct
4 Correct 507 ms 55608 KB Output is correct
5 Correct 392 ms 55596 KB Output is correct
6 Correct 315 ms 55948 KB Output is correct
7 Correct 282 ms 55640 KB Output is correct
8 Correct 228 ms 56832 KB Output is correct
9 Correct 507 ms 56336 KB Output is correct
10 Correct 612 ms 54852 KB Output is correct
11 Correct 425 ms 56408 KB Output is correct
12 Correct 468 ms 54876 KB Output is correct
13 Correct 344 ms 55764 KB Output is correct
14 Correct 377 ms 56152 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6632 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 3 ms 8680 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 3 ms 8540 KB Output is correct
8 Correct 2 ms 8536 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6588 KB Output is correct
11 Correct 2 ms 6488 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6632 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6744 KB Output is correct
21 Correct 2 ms 6628 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 2 ms 6488 KB Output is correct
25 Correct 2 ms 6632 KB Output is correct
26 Correct 2 ms 6488 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 2 ms 6620 KB Output is correct
30 Correct 363 ms 56300 KB Output is correct
31 Correct 273 ms 56136 KB Output is correct
32 Correct 423 ms 55908 KB Output is correct
33 Correct 351 ms 56384 KB Output is correct
34 Correct 258 ms 55996 KB Output is correct
35 Correct 230 ms 56660 KB Output is correct
36 Correct 237 ms 58060 KB Output is correct
37 Correct 504 ms 55888 KB Output is correct
38 Correct 276 ms 56012 KB Output is correct
39 Correct 430 ms 56356 KB Output is correct
40 Correct 280 ms 56228 KB Output is correct
41 Correct 207 ms 57756 KB Output is correct
42 Correct 185 ms 56968 KB Output is correct
43 Correct 187 ms 56848 KB Output is correct
44 Correct 201 ms 56868 KB Output is correct
45 Correct 196 ms 57596 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 2 ms 6492 KB Output is correct
49 Correct 2 ms 6492 KB Output is correct
50 Correct 2 ms 6492 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 394 ms 56360 KB Output is correct
53 Correct 273 ms 57404 KB Output is correct
54 Correct 384 ms 56968 KB Output is correct
55 Correct 363 ms 57004 KB Output is correct
56 Correct 277 ms 57380 KB Output is correct
57 Correct 256 ms 56952 KB Output is correct
58 Correct 216 ms 59076 KB Output is correct
59 Correct 509 ms 56792 KB Output is correct
60 Correct 305 ms 57156 KB Output is correct
61 Correct 411 ms 56712 KB Output is correct
62 Correct 258 ms 57336 KB Output is correct
63 Correct 2 ms 6628 KB Output is correct
64 Correct 2 ms 6492 KB Output is correct
65 Correct 2 ms 6492 KB Output is correct
66 Correct 1 ms 6492 KB Output is correct
67 Correct 2 ms 6488 KB Output is correct
68 Correct 2 ms 6492 KB Output is correct
69 Correct 2 ms 6492 KB Output is correct
70 Correct 2 ms 6492 KB Output is correct
71 Correct 2 ms 6492 KB Output is correct
72 Correct 2 ms 6624 KB Output is correct
73 Correct 1 ms 6492 KB Output is correct
74 Correct 2 ms 6492 KB Output is correct
75 Correct 1 ms 6492 KB Output is correct
76 Correct 2 ms 6660 KB Output is correct
77 Correct 2 ms 6488 KB Output is correct
78 Correct 1 ms 6628 KB Output is correct
79 Correct 566 ms 53080 KB Output is correct
80 Correct 680 ms 54016 KB Output is correct
81 Correct 536 ms 52388 KB Output is correct
82 Correct 424 ms 52312 KB Output is correct
83 Correct 302 ms 52688 KB Output is correct
84 Correct 261 ms 52724 KB Output is correct
85 Correct 228 ms 54200 KB Output is correct
86 Correct 544 ms 51864 KB Output is correct
87 Correct 625 ms 52500 KB Output is correct
88 Correct 414 ms 52180 KB Output is correct
89 Correct 425 ms 52776 KB Output is correct
90 Correct 335 ms 54188 KB Output is correct
91 Correct 360 ms 55352 KB Output is correct
92 Correct 2 ms 6488 KB Output is correct
93 Correct 2 ms 6492 KB Output is correct
94 Correct 1 ms 6492 KB Output is correct
95 Correct 2 ms 6492 KB Output is correct
96 Correct 2 ms 6492 KB Output is correct
97 Correct 1 ms 6492 KB Output is correct
98 Correct 528 ms 56444 KB Output is correct
99 Correct 697 ms 54800 KB Output is correct
100 Correct 507 ms 55608 KB Output is correct
101 Correct 392 ms 55596 KB Output is correct
102 Correct 315 ms 55948 KB Output is correct
103 Correct 282 ms 55640 KB Output is correct
104 Correct 228 ms 56832 KB Output is correct
105 Correct 507 ms 56336 KB Output is correct
106 Correct 612 ms 54852 KB Output is correct
107 Correct 425 ms 56408 KB Output is correct
108 Correct 468 ms 54876 KB Output is correct
109 Correct 344 ms 55764 KB Output is correct
110 Correct 377 ms 56152 KB Output is correct
111 Correct 2 ms 6492 KB Output is correct
112 Correct 2 ms 6632 KB Output is correct
113 Correct 2 ms 6492 KB Output is correct
114 Correct 2 ms 6492 KB Output is correct
115 Correct 1 ms 6492 KB Output is correct
116 Correct 405 ms 54844 KB Output is correct
117 Correct 520 ms 57360 KB Output is correct
118 Correct 559 ms 56912 KB Output is correct
119 Correct 446 ms 57120 KB Output is correct
120 Correct 319 ms 56824 KB Output is correct
121 Correct 329 ms 58052 KB Output is correct
122 Correct 231 ms 58924 KB Output is correct
123 Correct 555 ms 56632 KB Output is correct
124 Correct 681 ms 56912 KB Output is correct
125 Correct 432 ms 56124 KB Output is correct
126 Correct 482 ms 57240 KB Output is correct
127 Correct 518 ms 57680 KB Output is correct
128 Correct 444 ms 58356 KB Output is correct
129 Correct 451 ms 59028 KB Output is correct