Submission #964288

# Submission time Handle Problem Language Result Execution time Memory
964288 2024-04-16T14:54:37 Z rolandpetrean Sprinkler (JOI22_sprinkler) C++17
38 / 100
264 ms 50768 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll

#define endl '\n'
#define pb push_back
using pi = array<int, 2>;

const int N = 2e5 + 5;
vector<int> adj[N];
int par[N];

int h[N], wch[2][N];

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

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n, l;
  cin >> n >> l;
  
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  for (int i = 0; i <= n; ++i) wch[0][i] = wch[1][i] = 1;
  
  dfs(1);
  
  for (int i = 1; i <= n; ++i) cin >> h[i];
  
  int q;
  cin >> q;
  
  while (q--) {
    int t;
    cin >> t;
    
    if (t == 1) {
      int u, d, w;
      cin >> u >> d >> w;
      
      assert(d <= 2);
      
      auto mult = [&](int& var) {
        var = var * w % l;
      };
      
      int p = par[u];
      if (d == 0) {
        mult(h[u]);
      } else if (d == 1) {
        mult(h[u]);
        mult(h[p]);
        mult(wch[0][u]);
      } else {
        mult(h[p]);
        mult(wch[0][p]); // all children of p
        mult(h[par[p]]);
        mult(wch[0][u]);
        mult(wch[1][u]);
      }
    } else {
      int u;
      cin >> u;
      
      int ans = h[u];
      ans = ans * wch[0][par[u]] % l;
      ans = ans * wch[1][par[par[u]]] % l;
      cout << ans << endl;
    }
  }
}
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 22364 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11236 KB Output is correct
2 Correct 202 ms 30552 KB Output is correct
3 Correct 210 ms 30544 KB Output is correct
4 Correct 206 ms 32856 KB Output is correct
5 Correct 212 ms 30460 KB Output is correct
6 Correct 178 ms 30140 KB Output is correct
7 Correct 221 ms 30996 KB Output is correct
8 Correct 179 ms 31132 KB Output is correct
9 Correct 202 ms 34412 KB Output is correct
10 Correct 228 ms 34664 KB Output is correct
11 Correct 209 ms 30420 KB Output is correct
12 Correct 201 ms 30420 KB Output is correct
13 Correct 173 ms 30912 KB Output is correct
14 Correct 174 ms 30140 KB Output is correct
15 Correct 162 ms 28340 KB Output is correct
16 Correct 159 ms 25528 KB Output is correct
17 Correct 169 ms 19796 KB Output is correct
18 Correct 3 ms 11352 KB Output is correct
19 Correct 2 ms 11100 KB Output is correct
20 Correct 2 ms 11100 KB Output is correct
21 Correct 2 ms 11100 KB Output is correct
22 Correct 2 ms 11100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11236 KB Output is correct
2 Correct 202 ms 30552 KB Output is correct
3 Correct 210 ms 30544 KB Output is correct
4 Correct 206 ms 32856 KB Output is correct
5 Correct 212 ms 30460 KB Output is correct
6 Correct 178 ms 30140 KB Output is correct
7 Correct 221 ms 30996 KB Output is correct
8 Correct 179 ms 31132 KB Output is correct
9 Correct 202 ms 34412 KB Output is correct
10 Correct 228 ms 34664 KB Output is correct
11 Correct 209 ms 30420 KB Output is correct
12 Correct 201 ms 30420 KB Output is correct
13 Correct 173 ms 30912 KB Output is correct
14 Correct 174 ms 30140 KB Output is correct
15 Correct 162 ms 28340 KB Output is correct
16 Correct 159 ms 25528 KB Output is correct
17 Correct 169 ms 19796 KB Output is correct
18 Correct 3 ms 11352 KB Output is correct
19 Correct 2 ms 11100 KB Output is correct
20 Correct 2 ms 11100 KB Output is correct
21 Correct 2 ms 11100 KB Output is correct
22 Correct 2 ms 11100 KB Output is correct
23 Correct 2 ms 11100 KB Output is correct
24 Correct 194 ms 30476 KB Output is correct
25 Correct 227 ms 31036 KB Output is correct
26 Correct 242 ms 34636 KB Output is correct
27 Correct 242 ms 30560 KB Output is correct
28 Correct 203 ms 30800 KB Output is correct
29 Correct 225 ms 30588 KB Output is correct
30 Correct 168 ms 31260 KB Output is correct
31 Correct 193 ms 33132 KB Output is correct
32 Correct 264 ms 34784 KB Output is correct
33 Correct 193 ms 30496 KB Output is correct
34 Correct 228 ms 30796 KB Output is correct
35 Correct 3 ms 11100 KB Output is correct
36 Correct 2 ms 11096 KB Output is correct
37 Correct 3 ms 11188 KB Output is correct
38 Correct 2 ms 11100 KB Output is correct
39 Correct 3 ms 11388 KB Output is correct
40 Correct 2 ms 11100 KB Output is correct
41 Correct 2 ms 11100 KB Output is correct
42 Correct 3 ms 11100 KB Output is correct
43 Correct 4 ms 11100 KB Output is correct
44 Correct 3 ms 11096 KB Output is correct
45 Correct 3 ms 11100 KB Output is correct
46 Correct 3 ms 11100 KB Output is correct
47 Correct 2 ms 11100 KB Output is correct
48 Correct 3 ms 11096 KB Output is correct
49 Correct 2 ms 11100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11096 KB Output is correct
2 Runtime error 117 ms 50768 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 22364 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 22364 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -