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>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define f first
#define s second
#define pii pair <int,int>
#define en '\n'
#define all(v) v.begin(),v.end()
void boos() {
ios_base :: sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const int N = 2e5 + 100;
const int bl = 400;
vector <int> g[N];
ll a[N],L,d[N][42];
int n,pr[N];
void dfs_build(int v,int p) {
for(auto to : g[v]) {
if(to == p)continue;
pr[to] = v;
dfs_build(to,v);
}
}
void add(int x,int dist,ll w) {
int v = x;
int tek = 0;
while(tek <= dist && v != -1) {
d[v][dist - tek] = (d[v][dist - tek] * w) % L;
tek++;
v = pr[v];
}
}
ll get(int x) {
ll ans = a[x];
int v = x,tek = 0;
//cout << d[v][0] << endl;
while(tek <= 40) {
for(int j = tek + 1;j >= tek;j--)ans = (ans * d[v][j]) % L;
tek++;
if(pr[v] == -1) {
for(int j = tek + 1;j <= 40;j++)ans = (ans * d[v][j]) % L;
break;
}
v = pr[v];
}
return ans;
}
void solve() {
cin >> n >> L;
for(int i = 1;i <= n;i++) {
pr[i] = -1;
for(int j = 0;j <= 40;j++)d[i][j] = 1;
}
for(int i = 1;i < n;i++) {
int x,y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
for(int i = 1;i <= n;i++)cin >> a[i];
dfs_build(1,-1);
int m;
cin >> m;
for(int i = 1;i <= m;i++) {
int typ;
cin >> typ;
if(typ == 1) {
int x,dist;
ll w;
cin >> x >> dist >> w;
add(x,dist,w);
}else {
int x;
cin >> x;
cout << get(x) << en;
}
}
}
int main() {
boos();
int ttt;
ttt = 1;
while(ttt--) {
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... |