이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int B = 40;
const int MAXN = 2e5 + 40 + 25;
int n, l, p[MAXN];
vector <int> adj[MAXN];
int dp[MAXN][B + 1], dep[MAXN];
int mul (int x, int y) {
return (x * 1ll * y) % l;
}
int h[MAXN];
void dfs (int pos, int par) {
p[pos] = par;
for (auto j : adj[pos]) {
if (j != par) {
dep[j] = 1 + dep[pos];
dfs(j, pos);
}
}
}
void solve () {
cin >> n >> l;
for (int i = 1; i < n; i++) {
int x, y; cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
dfs(1, 0);
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
p[1] = n + 1;
for (int i = n + 2; i <= n + 40; i++) {
p[i - 1] = i;
}
for (int i = 1; i <= n + 40; i++) {
for (int j = 0; j <= B; j++) {
dp[i][j] = 1;
}
}
int q; cin >> q;
while (q--) {
int t; cin >> t;
if (t == 1) {
int x, d, w; cin >> x >> d >> w;
for (int i = d; i >= 0; i--) {
dp[x][i] = mul(dp[x][i], w);
if (i) {
dp[x][i - 1] = mul(dp[x][i - 1], w);
}
x = p[x];
}
} else {
int x; cin >> x;
int ret = h[x];
for (int i = 0; i <= B; i++) {
ret = mul(ret, dp[x][i]);
x = p[x];
}
cout << ret << '\n';
}
}
}
signed main () {
ios::sync_with_stdio(0); cin.tie(0);
int tc = 1; //cin >> tc;
while (tc--) solve();
}
# | 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... |