Submission #588807

# Submission time Handle Problem Language Result Execution time Memory
588807 2022-07-04T05:36:55 Z SeDunion Sprinkler (JOI22_sprinkler) C++17
0 / 100
672 ms 99484 KB
#include<iostream>
#include<vector>

using namespace std;
using ll = long long;
const int N = 5e5 + 123;

const int LOG = 20;

const int D = 45;

ll h[N], q[N][D];

int n, L;

void mult(ll &a, ll b) {
	a += b;
	return;
	a *= b;
	a %= L;
}

void dvdv(ll &a, ll b) {
	a -= b;
}

vector<int>g[N];

int pr[N];

void dfs(int v) {
	for (int to : g[v]) if (to != pr[v]) {
		pr[to] = v;
		dfs(to);
	}
}

ll binpow(ll a, ll b) {
	ll r = 1;
	while (b) {
		if (b & 1) r = r * a % L;
		a = a * a % L;
		b >>= 1;
	}
	return r;
}

ll ih[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> L;
	for (int i = 1 ; i < n ; ++ i) {
		int a, b;
		cin >> a >> b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	dfs(1);
	for (int i = 1 ; i <= n ; ++ i) {
		cin >> ih[i];
		h[i] = 0;
		for (int j = 0 ; j <= 40 ; ++ j) {
			//q[i][j] = 1;
			q[i][j] = 0;
		}
	}
	int qq;
	cin >> qq;
	for (int i = 0 ; i < qq ; ++ i) {
		int t, x, d, w;
		cin >> t;
		if (t == 1) {
			cin >> x >> d >> w;
			w = 1;
			for (int i = d ; i >= 0 ; -- i) {
				mult(q[x][i], w);
				mult(h[x], w);
				if (x == 1) break;
				x = pr[x];
			}
		} else {
			cin >> x;
			ll ret = ih[x];
			ll ans = 0;
			for (int i = 0 ; i <= 40 ; ++ i) {
				mult(ans, q[x][i]);
				mult(ans, q[x][i+1]);
				if (x == 1) break;
				x = pr[x];
			}
			if (ans > 0) {
				ans = 0;
			} else {
				ans = ret;
			}
			cout << ans << "\n";
			//cout << ret*binpow(2, ans) % L << "\n";
		}
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 11988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 12096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 12096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11988 KB Output is correct
2 Incorrect 672 ms 99484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 11988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 11988 KB Output isn't correct
2 Halted 0 ms 0 KB -