Submission #980477

# Submission time Handle Problem Language Result Execution time Memory
980477 2024-05-12T07:51:28 Z abczz Sprinkler (JOI22_sprinkler) C++14
41 / 100
4000 ms 421352 KB
#include <iostream>
#include <vector>
#define ll long long

using namespace std;

ll n, q, t, M, a, b, c, f, cnt, H[200000], edgeid[200000], P[200000], X[200000], dp[200000][41];
struct BIT{
  vector <ll> bit{vector <ll> (42, 1)};
  void mult(ll u, ll w) {
    u = 42-u;
    while (u < 42) {
      bit[u] = bit[u] * w % M;
      u += u & -u;
    }
  }
  ll query(ll u) {
    u = 42-u;
    ll res = 1;
    while (u) {
      res *= bit[u];
      res %= M;
      u -= u & -u;
    }
    return res;
  }
};
struct SegTree{
  vector <BIT> st;
  ll stsz = 0;
  void init() {
    st.resize(4*stsz);
  }
  void update(ll id, ll l, ll r, ll q, ll u, ll w) {
    st[id].mult(u, w);
    if (l == r) return;
    ll mid = (l+r)/2;
    if (q <= mid) update(id*2, l, mid, q, u, w);
    else update(id*2+1, mid+1, r, q, u, w);
  }
  ll query(ll id, ll l, ll r, ll ql, ll qr, ll u) {
    if (qr < l || r < ql || ql > qr) return 1;
    else if (ql <= l && r <= qr) return st[id].query(u);
    ll mid = (l+r)/2;
    return query(id*2, l, mid, ql, qr, u) * query(id*2+1, mid+1, r, ql, qr, u) % M;
  }
}ST[200000];
vector <ll> adj[200000];
BIT G[200000];

void dfs(ll u, ll p) {
  for (auto v : adj[u]) {
    if (v != p) {
      X[v] = ST[u].stsz++;
      edgeid[v] = cnt++;
      dfs(v, u);
      P[v] = u;
    }
  }
  ST[u].init();
}
int main() {
  cin >> n >> M;
  for (int i=0; i<n-1; ++i) {
    cin >> a >> b;
    --a, --b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i=0; i<n; ++i) {
    cin >> H[i];
  }
  dfs(0, -1);
  P[0] = -1;
  cin >> q;
  while (q--) {
    cin >> t;
    if (t == 1) {
      cin >> a >> b >> c;
      --a;
      G[a].mult(b+1, c);
      for (int i=b-1; i>=0 && P[a] != -1; --i) {
        ST[P[a]].update(1, 0, ST[P[a]].stsz-1, X[a], i+1, c);
        a = P[a];
      }
    }
    else {
      cin >> a;
      --a;
      f = H[a] * G[a].query(1) % M;
      f = f * ST[a].query(1, 0, ST[a].stsz-1, 0, ST[a].stsz-1, 1) % M;
      for (int i=1; i<=40 && P[a] != -1; ++i) {
        f = f * G[P[a]].query(i+1) % M;
        f = f * ST[P[a]].query(1, 0, ST[P[a]].stsz-1, 0, X[a]-1, i+1) % M * ST[P[a]].query(1, 0, ST[P[a]].stsz-1, X[a]+1, ST[P[a]].stsz-1, i+1) % M;
        a = P[a];
      }
      cout << f << '\n';
    }
  }
}
# Verdict Execution time Memory Grader output
1 Correct 37 ms 91980 KB Output is correct
2 Correct 40 ms 91880 KB Output is correct
3 Correct 39 ms 91832 KB Output is correct
4 Correct 42 ms 93524 KB Output is correct
5 Correct 42 ms 93572 KB Output is correct
6 Correct 57 ms 93648 KB Output is correct
7 Correct 43 ms 93588 KB Output is correct
8 Correct 46 ms 93592 KB Output is correct
9 Correct 38 ms 91988 KB Output is correct
10 Correct 48 ms 91976 KB Output is correct
11 Correct 42 ms 91996 KB Output is correct
12 Correct 39 ms 92060 KB Output is correct
13 Correct 40 ms 91860 KB Output is correct
14 Correct 39 ms 92000 KB Output is correct
15 Correct 42 ms 92052 KB Output is correct
16 Correct 41 ms 91988 KB Output is correct
17 Correct 40 ms 91984 KB Output is correct
18 Correct 42 ms 91992 KB Output is correct
19 Correct 40 ms 91988 KB Output is correct
20 Correct 42 ms 91984 KB Output is correct
21 Correct 38 ms 91996 KB Output is correct
22 Correct 42 ms 91996 KB Output is correct
23 Correct 47 ms 91984 KB Output is correct
24 Correct 39 ms 91984 KB Output is correct
25 Correct 41 ms 91984 KB Output is correct
26 Correct 48 ms 92032 KB Output is correct
27 Correct 41 ms 91972 KB Output is correct
28 Correct 38 ms 91868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 92012 KB Output is correct
2 Correct 3536 ms 409316 KB Output is correct
3 Correct 1354 ms 409776 KB Output is correct
4 Correct 2133 ms 417412 KB Output is correct
5 Correct 2309 ms 409492 KB Output is correct
6 Correct 1555 ms 408624 KB Output is correct
7 Correct 1500 ms 409120 KB Output is correct
8 Correct 1194 ms 408500 KB Output is correct
9 Correct 2587 ms 421164 KB Output is correct
10 Correct 1157 ms 420748 KB Output is correct
11 Correct 2942 ms 409296 KB Output is correct
12 Correct 1206 ms 409648 KB Output is correct
13 Correct 785 ms 408388 KB Output is correct
14 Correct 817 ms 408820 KB Output is correct
15 Correct 882 ms 408036 KB Output is correct
16 Correct 853 ms 408604 KB Output is correct
17 Correct 899 ms 409428 KB Output is correct
18 Correct 39 ms 91984 KB Output is correct
19 Correct 40 ms 91988 KB Output is correct
20 Correct 40 ms 91984 KB Output is correct
21 Correct 40 ms 91988 KB Output is correct
22 Correct 41 ms 91996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 92012 KB Output is correct
2 Correct 3536 ms 409316 KB Output is correct
3 Correct 1354 ms 409776 KB Output is correct
4 Correct 2133 ms 417412 KB Output is correct
5 Correct 2309 ms 409492 KB Output is correct
6 Correct 1555 ms 408624 KB Output is correct
7 Correct 1500 ms 409120 KB Output is correct
8 Correct 1194 ms 408500 KB Output is correct
9 Correct 2587 ms 421164 KB Output is correct
10 Correct 1157 ms 420748 KB Output is correct
11 Correct 2942 ms 409296 KB Output is correct
12 Correct 1206 ms 409648 KB Output is correct
13 Correct 785 ms 408388 KB Output is correct
14 Correct 817 ms 408820 KB Output is correct
15 Correct 882 ms 408036 KB Output is correct
16 Correct 853 ms 408604 KB Output is correct
17 Correct 899 ms 409428 KB Output is correct
18 Correct 39 ms 91984 KB Output is correct
19 Correct 40 ms 91988 KB Output is correct
20 Correct 40 ms 91984 KB Output is correct
21 Correct 40 ms 91988 KB Output is correct
22 Correct 41 ms 91996 KB Output is correct
23 Correct 40 ms 92048 KB Output is correct
24 Correct 3134 ms 409100 KB Output is correct
25 Correct 1377 ms 409796 KB Output is correct
26 Correct 1979 ms 421352 KB Output is correct
27 Correct 2117 ms 409732 KB Output is correct
28 Correct 1644 ms 409064 KB Output is correct
29 Correct 1472 ms 408708 KB Output is correct
30 Correct 1229 ms 408156 KB Output is correct
31 Correct 2635 ms 417816 KB Output is correct
32 Correct 1228 ms 421100 KB Output is correct
33 Correct 2949 ms 409408 KB Output is correct
34 Correct 1255 ms 409656 KB Output is correct
35 Correct 46 ms 91988 KB Output is correct
36 Correct 45 ms 92012 KB Output is correct
37 Correct 40 ms 91988 KB Output is correct
38 Correct 39 ms 91904 KB Output is correct
39 Correct 42 ms 91988 KB Output is correct
40 Correct 40 ms 92028 KB Output is correct
41 Correct 39 ms 92072 KB Output is correct
42 Correct 41 ms 91984 KB Output is correct
43 Correct 39 ms 91988 KB Output is correct
44 Correct 40 ms 91988 KB Output is correct
45 Correct 41 ms 91988 KB Output is correct
46 Correct 40 ms 92048 KB Output is correct
47 Correct 39 ms 91988 KB Output is correct
48 Correct 40 ms 91984 KB Output is correct
49 Correct 40 ms 91984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 91984 KB Output is correct
2 Correct 2972 ms 418352 KB Output is correct
3 Correct 3117 ms 416152 KB Output is correct
4 Correct 2769 ms 416224 KB Output is correct
5 Correct 3646 ms 406416 KB Output is correct
6 Correct 2359 ms 404588 KB Output is correct
7 Correct 2138 ms 403388 KB Output is correct
8 Correct 1522 ms 403644 KB Output is correct
9 Correct 3704 ms 414700 KB Output is correct
10 Correct 3276 ms 417932 KB Output is correct
11 Execution timed out 4025 ms 406196 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 41 ms 92068 KB Output is correct
2 Correct 3049 ms 417060 KB Output is correct
3 Correct 2853 ms 414164 KB Output is correct
4 Correct 2442 ms 415368 KB Output is correct
5 Correct 2871 ms 408316 KB Output is correct
6 Correct 1972 ms 407852 KB Output is correct
7 Correct 1960 ms 407780 KB Output is correct
8 Correct 1318 ms 406340 KB Output is correct
9 Correct 2982 ms 420112 KB Output is correct
10 Correct 3167 ms 418560 KB Output is correct
11 Correct 3529 ms 408820 KB Output is correct
12 Correct 3730 ms 407492 KB Output is correct
13 Execution timed out 4030 ms 405604 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 91980 KB Output is correct
2 Correct 40 ms 91880 KB Output is correct
3 Correct 39 ms 91832 KB Output is correct
4 Correct 42 ms 93524 KB Output is correct
5 Correct 42 ms 93572 KB Output is correct
6 Correct 57 ms 93648 KB Output is correct
7 Correct 43 ms 93588 KB Output is correct
8 Correct 46 ms 93592 KB Output is correct
9 Correct 38 ms 91988 KB Output is correct
10 Correct 48 ms 91976 KB Output is correct
11 Correct 42 ms 91996 KB Output is correct
12 Correct 39 ms 92060 KB Output is correct
13 Correct 40 ms 91860 KB Output is correct
14 Correct 39 ms 92000 KB Output is correct
15 Correct 42 ms 92052 KB Output is correct
16 Correct 41 ms 91988 KB Output is correct
17 Correct 40 ms 91984 KB Output is correct
18 Correct 42 ms 91992 KB Output is correct
19 Correct 40 ms 91988 KB Output is correct
20 Correct 42 ms 91984 KB Output is correct
21 Correct 38 ms 91996 KB Output is correct
22 Correct 42 ms 91996 KB Output is correct
23 Correct 47 ms 91984 KB Output is correct
24 Correct 39 ms 91984 KB Output is correct
25 Correct 41 ms 91984 KB Output is correct
26 Correct 48 ms 92032 KB Output is correct
27 Correct 41 ms 91972 KB Output is correct
28 Correct 38 ms 91868 KB Output is correct
29 Correct 38 ms 92012 KB Output is correct
30 Correct 3536 ms 409316 KB Output is correct
31 Correct 1354 ms 409776 KB Output is correct
32 Correct 2133 ms 417412 KB Output is correct
33 Correct 2309 ms 409492 KB Output is correct
34 Correct 1555 ms 408624 KB Output is correct
35 Correct 1500 ms 409120 KB Output is correct
36 Correct 1194 ms 408500 KB Output is correct
37 Correct 2587 ms 421164 KB Output is correct
38 Correct 1157 ms 420748 KB Output is correct
39 Correct 2942 ms 409296 KB Output is correct
40 Correct 1206 ms 409648 KB Output is correct
41 Correct 785 ms 408388 KB Output is correct
42 Correct 817 ms 408820 KB Output is correct
43 Correct 882 ms 408036 KB Output is correct
44 Correct 853 ms 408604 KB Output is correct
45 Correct 899 ms 409428 KB Output is correct
46 Correct 39 ms 91984 KB Output is correct
47 Correct 40 ms 91988 KB Output is correct
48 Correct 40 ms 91984 KB Output is correct
49 Correct 40 ms 91988 KB Output is correct
50 Correct 41 ms 91996 KB Output is correct
51 Correct 40 ms 92048 KB Output is correct
52 Correct 3134 ms 409100 KB Output is correct
53 Correct 1377 ms 409796 KB Output is correct
54 Correct 1979 ms 421352 KB Output is correct
55 Correct 2117 ms 409732 KB Output is correct
56 Correct 1644 ms 409064 KB Output is correct
57 Correct 1472 ms 408708 KB Output is correct
58 Correct 1229 ms 408156 KB Output is correct
59 Correct 2635 ms 417816 KB Output is correct
60 Correct 1228 ms 421100 KB Output is correct
61 Correct 2949 ms 409408 KB Output is correct
62 Correct 1255 ms 409656 KB Output is correct
63 Correct 46 ms 91988 KB Output is correct
64 Correct 45 ms 92012 KB Output is correct
65 Correct 40 ms 91988 KB Output is correct
66 Correct 39 ms 91904 KB Output is correct
67 Correct 42 ms 91988 KB Output is correct
68 Correct 40 ms 92028 KB Output is correct
69 Correct 39 ms 92072 KB Output is correct
70 Correct 41 ms 91984 KB Output is correct
71 Correct 39 ms 91988 KB Output is correct
72 Correct 40 ms 91988 KB Output is correct
73 Correct 41 ms 91988 KB Output is correct
74 Correct 40 ms 92048 KB Output is correct
75 Correct 39 ms 91988 KB Output is correct
76 Correct 40 ms 91984 KB Output is correct
77 Correct 40 ms 91984 KB Output is correct
78 Correct 39 ms 91984 KB Output is correct
79 Correct 2972 ms 418352 KB Output is correct
80 Correct 3117 ms 416152 KB Output is correct
81 Correct 2769 ms 416224 KB Output is correct
82 Correct 3646 ms 406416 KB Output is correct
83 Correct 2359 ms 404588 KB Output is correct
84 Correct 2138 ms 403388 KB Output is correct
85 Correct 1522 ms 403644 KB Output is correct
86 Correct 3704 ms 414700 KB Output is correct
87 Correct 3276 ms 417932 KB Output is correct
88 Execution timed out 4025 ms 406196 KB Time limit exceeded
89 Halted 0 ms 0 KB -