# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
892225 | vjudge1 | Sprinkler (JOI22_sprinkler) | C++17 | 276 ms | 43092 KiB |
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>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define mpa make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define bc back()
#define ar array
#define vll vector<ll>
using namespace std;/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;*/
template <class _T>
bool chmin(_T &x, const _T &y){
if(x>y){
x=y;
return true;
}
return false;
}
template <class _T>
bool chmax(_T &x, const _T &y){
bool flag=false;
if (x<y){
x=y;flag|=true;
}
return flag;
}
//#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll inf=2e18+7;
const ll mod=1e9+7;
const ll N=2e5+7;
const ld eps=1e-9;
vector<vll> g(N);
ll h[N];
ll i;
ll n,k,p[N];
ll val[N][5];
void dfs(ll v,ll p,ll w,ll d,ll r){
h[v]*=w;
h[v]%=k;
if(d==r)return;
for(auto i : g[v]){
if(i==p)continue;
dfs(i,v,w,d+1,r);
}
}
void dfs2(ll v){
for(auto i : g[v]){
if(i==p[v])continue;
p[i]=v;
dfs2(i);
}
}
void solve(){
ll i,q;
ll a,b,c;
cin>>n>>k;
for(i=0;i<=n;i++)val[i][1]=val[i][2]=1;
for(i=1;i<n;i++){
cin>>a>>b;
g[a].pb(b);
g[b].pb(a);
}
for(i=1;i<=n;i++)cin>>h[i];
dfs2(1);
cin>>q;
ll t;
if(n<=1000 && q<=1000){
for(i=0;i<q;i++){
cin>>t;
if(t==1){
cin>>a>>b>>c;
dfs(a,0,c,0,b);
}else{
cin>>a;
cout<<h[a]<<endl;
}
}
return;
}
for(i=0;i<q;i++){
cin>>t;
if(t==1){
cin>>a>>b>>c;
if(b==1){
val[a][1]*=c;
val[a][1]%=k;
h[a]*=c;
h[a]%=k;
h[p[a]]*=c;
h[p[a]]%=k;
}else if(b==2){
val[a][2]*=c;
val[a][2]%=k;
if(p[a]!=0){
val[p[a]][1]*=c;
val[p[a]][1]%=k;
h[p[a]]*=c;
h[p[a]]%=k;
}else {
h[a]*=c;
h[a]%=k;
}
h[p[p[a]]]*=c;
h[p[p[a]]]%=k;
}else{
h[a]*=c;
h[a]%=k;
}
}else{
cin>>a;
cout<<h[a]*val[p[a]][2]%k*val[p[a]][1]%k*val[p[p[a]]][2]%k<<endl;
}
}
}
signed main(){
start();
ll t=1;
//cin>>t;
while(t--) solve();
return 0;
}
/*
1
7
1 2
2 3
3 4
4 5
3 6
6 7
2
4 1
5 7
*/
Compilation message (stderr)
# | 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... |