이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("Ofast,unroll-loops")
#define pii pair<int,int>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
#define f first
#define s second
#define pii pair<int,int>
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
const int mod= 1e9 +7;
const int N=1e5*4;
int binpow (int a, int n) {
if (n == 0)
return 1;
if (n % 2 == 1)
return binpow (a, n-1) * a;
else {
int b = binpow (a, n/2);
return b * b;
}
}
int n,m,k,l;
vector<int>v[N],pr(N);
int dp[N][50];
void dfs(int x,int prad){
pr[x] = prad;
for(auto to:v[x]){
if(prad==to)continue;
dfs(to,x);
}
return;
}
int md(int a,int b) {
return (a*b)%l;
}
void solve(){
cin>>n>>l;
for(int i = 0;i<n-1;i++){
int a,b;
cin>>a>>b;
v[a].pb(b);
v[b].pb(a);
}
for(int i = 1;i<=n;i++){
for(int j = 0;j<41;j++){
dp[i][j] = 1;
}
}
for(int i = 1;i<=n;i++){
int a;
cin>>a;
dp[i][0] = a;
}
dfs(1,-1);
int q;
cin>>q;
//~ cout<<pr[2]<<endl;
while(q--){
int a,x,dist,cst;
cin>>a>>x;
if(a==1){
cin>>dist>>cst;
while(true){
for(int i = dist;i>=0;i--){
dp[x][i] = md(dp[x][i],cst);
}
dist--;
if(dist<0)break;
if(x==1)break;
x = pr[x];
}
}
else{
int ans = 1;
for(int d = 0;d<=40&&x>0;d++,x = pr[x])
ans = md(ans,dp[x][d]);
cout<<ans<<"\n";
}
}
}
signed main()
{
// freopen("seq.in", "r", stdin);
// freopen("seq.out", "w", stdout);
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int tt=1;//cin>>tt;
while(tt--)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... |