Submission #1278038

#TimeUsernameProblemLanguageResultExecution timeMemory
1278038minggaSprinkler (JOI22_sprinkler)C++20
0 / 100
1766 ms98448 KiB
// Author: caption_mingle
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 2e5 + 7;
int n, l, a[N], par[N], q;
int ext[N][50];

vector<int> g[N];

int mul(int x, int y) {
	return (1ll * x * y) % l;
}

void dfs(int u, int p) {
	for(int v : g[u]) {
		if(v == p) continue;
		par[v] = u;
		dfs(v, u);
	}
}

signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	#define task ""
	if(fopen(task ".INP", "r")) {
		freopen(task ".INP", "r", stdin);
		freopen(task ".OUT", "w", stdout);
	}
	cin >> n >> l;
	for(int i = 1; i < n; i++) {
		int u, v; cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		for(int j = 0; j <= 40; j++) {
			ext[i][j] = 1;
		}
	}
	dfs(1, 0);
	cin >> q;
	for(int i = 1; i <= q; i++) {
		int t; cin >> t;
		if(t == 1) {
			int x, d, w; cin >> x >> d >> w;
			// for(int j = d, u = x; j >= 0 and u != 0; j--, u = par[u]) {
			// 	ext[u][j] = mul(ext[u][j], w);
			// }
			while(x!=0 && d>=0){
				ext[x][d]=mul(ext[x][d],w);
				d--;
				x=par[x];
			}
		} else {
			int x; cin >> x;
			int cur = 1;
			for(int j = 0, u = x; j <= 40 and u != 0; j++, u = par[u]) {
				if(u == 1) {
					for(int t = j; t <= 40; t++) {
						cur = mul(cur, ext[u][t]);
					}
				} else cur = mul(cur, mul(ext[u][j], ext[u][j + 1]));
			}
			cout << mul(a[x], cur) << ln;
		}
	}
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

Compilation message (stderr)

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:37:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |                 freopen(task ".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:38:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |                 freopen(task ".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...