제출 #721263

#제출 시각아이디문제언어결과실행 시간메모리
721263Abrar_Al_SamitSprinkler (JOI22_sprinkler)C++17
100 / 100
2404 ms95568 KiB
#include<bits/stdc++.h>
using namespace std;

const int nax = 2e5 + 3;
const int cax = 42;

vector<int>g[nax];
int n;
long long L;
long long H[nax];
long long growth[nax][cax];
int par[nax];


void dfs(int v, int p = 1) {
	par[v] = p;
	for(int u : g[v]) if(u!=p) {
		dfs(u, v);
	}
}
void update(int v, int cd, int mt) {
	if(cd<0) return;
	growth[v][cd] = (growth[v][cd] * mt) % L;

	if(v!=1) update(par[v], cd-1, mt);
}	
long long query(int v, int cd) {
	if(cd==cax) return 1LL;

	long long ret = 1LL;
	for(int j=cd; j<cax; ++j) {
		if(j-1>=cd+1 && v!=1) continue;
		ret = (ret * growth[v][j]) % L;
	}	
	if(v!=1) ret = (ret * query(par[v], cd+1)) % L;
	return ret;
}
void PlayGround() {
	cin>>n>>L;
	for(int i=0; i<n-1; ++i) {
		int u, v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}	
	for(int i=1; i<=n; ++i) {
		cin>>H[i];
	}
	for(int i=1; i<=n; ++i) {
		for(int j=0; j<cax; ++j) {
			growth[i][j] = 1;
		}
	}
	dfs(1);

	int q;
	cin>>q;
	while(q--) {
		int type;
		cin>>type;
		if(type==1) {
			int x, d, w;
			cin>>x>>d>>w;

			update(x, d, w);
		} else {
			int x;
			cin>>x;
			long long ans = query(x, 0) * H[x];
			ans %= L;
			cout<<ans<<'\n';
		}
	}

	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	PlayGround();
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...