This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
namespace x = __gnu_pbds;
template <typename T>
using ordered_set = x::tree<T, x::null_type, less<T>, x::rb_tree_tag, x::tree_order_statistics_node_update>;
template <typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;
#define all(x) begin(x), end(x)
#define sz(x) ((int) (x).size())
#define x first
#define y second
using ll = long long;
using ld = long double;
const int N = 2e5 + 50, D = 40;
vector<int> g[N];
int p[N];
ll h[N][D + 1];
void dfs(int u = 0, int parent = -1) {
p[u] = parent;
for (int v : g[u]) {
if (v != parent) {
dfs(v, u);
}
}
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, modulo;
cin >> n >> modulo;
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
u += D, v += D;
g[--u].push_back(--v);
g[v].push_back(u);
}
for (int i = 1; i <= D; ++i) {
g[i].push_back(i - 1);
g[i - 1].push_back(i);
}
dfs();
fill(h[0], h[N], 1);
for (int i = 0; i < n; ++i) {
cin >> h[i + D][D];
}
int queries;
cin >> queries;
while (queries--) {
int type;
cin >> type;
if (type == 1) {
int u, d, w;
cin >> u >> d >> w;
u += D - 1;
for (int i = 0; i <= d; ++i) {
(h[u][D - d + i] *= w) %= modulo;
u = p[u];
}
} else {
int u;
cin >> u;
u += D - 1;
ll ans = 1;
for (int i = 0; i <= D; ++i) {
(ans *= h[u][D - i]) %= modulo;
if (i != D) {
(ans *= h[u][D - i - 1]) %= modulo;
}
u = p[u];
}
cout << ans << "\n";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |