Submission #661278

# Submission time Handle Problem Language Result Execution time Memory
661278 2022-11-25T07:38:28 Z Alex_tz307 Sprinkler (JOI22_sprinkler) C++17
0 / 100
397 ms 51788 KB
#include <bits/stdc++.h>

using namespace std;

const int kD = 40;

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, l;
  cin >> n >> l;
  vector<int> par(1 + n + kD);
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    par[v] = u;
  }
  par[1] = n + 1;
  for (int i = n + 1; i < n + kD; ++i) {
    par[i] = i + 1;
  }
  vector<vector<int>> coef(1 + n + kD, vector<int>(1 + kD, 1));
  for (int i = 1; i <= n; ++i) {
    cin >> coef[i][0];
  }
  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 = 1, curr = 0;
      while (curr <= kD) {
        multSelf(res, coef[x][curr], l);
        x = par[x];
        curr += 1;
      }
      cout << res << '\n';
    }
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 346 ms 48832 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 397 ms 51788 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -