Submission #689331

# Submission time Handle Problem Language Result Execution time Memory
689331 2023-01-28T08:04:31 Z happypotato Sprinkler (JOI22_sprinkler) C++17
3 / 100
1369 ms 108368 KB
#include <bits/stdc++.h>
using namespace std;
const int mxN = 2e5;
const int mxD = 40;
int contrib[mxN + 1][mxD + 1];
vector<int> adj[mxN];
int height[mxN];
int n, L;
void Init() {
	for (int i = 1; i <= mxN; i++) {
		for (int j = 0; j <= mxD; j++) {
			contrib[i][j] = 1;
		}
	}
}
void Input() {
	cin >> n >> L;
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for (int i = 1; i <= n; i++) {
		cin >> height[i];
	}
}
int par[mxN];
void FindParent(int u = 1, int pp = 0) {
	par[u] = pp;
	for (int &v : adj[u]) {
		if (v != pp) {
			FindParent(v, u);
		}
	}
}
void Update(int x, int d, int w) {
	while (x != 1 && d >= 0) {
		contrib[x][d] = (1LL * contrib[x][d] * w) % L;
		if (d > 0) {
			contrib[x][d - 1] = (1LL * contrib[x][d - 1] * w) % L;
		}
		x = par[x];
		d--;
	}
	for (int i = d; i >= 0; i--) {
		contrib[x][i] = (1LL * contrib[x][i] * w) % L;
	}
}
int Query(int x) {
	int res = height[x];
	for (int i = 0; i <= mxD; i++) {
		if (x == 0) break;
		res = (1LL * res * contrib[x][i]) % L;
		x = par[x];
	}
	return res;
}
int main() {
	Init();
	Input();
	FindParent();
	int q;
	cin >> q;
	while (q--) {
		int cmd;
		cin >> cmd;
		if (cmd == 1) {
			int x, d, w;
			cin >> x >> d >> w;
			Update(x, d, w);
		} else if (cmd == 2) {
			int x;
			cin >> x;
			cout << Query(x) << endl;
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 37104 KB Output is correct
2 Correct 20 ms 37096 KB Output is correct
3 Correct 20 ms 37076 KB Output is correct
4 Correct 25 ms 37120 KB Output is correct
5 Correct 24 ms 37112 KB Output is correct
6 Correct 22 ms 37140 KB Output is correct
7 Correct 24 ms 37240 KB Output is correct
8 Correct 22 ms 37116 KB Output is correct
9 Correct 21 ms 37092 KB Output is correct
10 Correct 21 ms 37084 KB Output is correct
11 Correct 21 ms 37052 KB Output is correct
12 Correct 21 ms 37112 KB Output is correct
13 Correct 30 ms 37020 KB Output is correct
14 Correct 21 ms 37104 KB Output is correct
15 Correct 21 ms 37004 KB Output is correct
16 Correct 20 ms 37020 KB Output is correct
17 Correct 20 ms 37104 KB Output is correct
18 Correct 21 ms 37120 KB Output is correct
19 Correct 21 ms 37108 KB Output is correct
20 Correct 26 ms 37068 KB Output is correct
21 Correct 22 ms 37064 KB Output is correct
22 Correct 21 ms 37084 KB Output is correct
23 Correct 21 ms 37076 KB Output is correct
24 Correct 27 ms 37220 KB Output is correct
25 Correct 24 ms 37108 KB Output is correct
26 Correct 24 ms 37076 KB Output is correct
27 Correct 23 ms 37020 KB Output is correct
28 Correct 20 ms 37076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 37100 KB Output is correct
2 Runtime error 1318 ms 101408 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 37100 KB Output is correct
2 Runtime error 1318 ms 101408 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 37108 KB Output is correct
2 Runtime error 1369 ms 108368 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37096 KB Output is correct
2 Runtime error 1312 ms 106764 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 37104 KB Output is correct
2 Correct 20 ms 37096 KB Output is correct
3 Correct 20 ms 37076 KB Output is correct
4 Correct 25 ms 37120 KB Output is correct
5 Correct 24 ms 37112 KB Output is correct
6 Correct 22 ms 37140 KB Output is correct
7 Correct 24 ms 37240 KB Output is correct
8 Correct 22 ms 37116 KB Output is correct
9 Correct 21 ms 37092 KB Output is correct
10 Correct 21 ms 37084 KB Output is correct
11 Correct 21 ms 37052 KB Output is correct
12 Correct 21 ms 37112 KB Output is correct
13 Correct 30 ms 37020 KB Output is correct
14 Correct 21 ms 37104 KB Output is correct
15 Correct 21 ms 37004 KB Output is correct
16 Correct 20 ms 37020 KB Output is correct
17 Correct 20 ms 37104 KB Output is correct
18 Correct 21 ms 37120 KB Output is correct
19 Correct 21 ms 37108 KB Output is correct
20 Correct 26 ms 37068 KB Output is correct
21 Correct 22 ms 37064 KB Output is correct
22 Correct 21 ms 37084 KB Output is correct
23 Correct 21 ms 37076 KB Output is correct
24 Correct 27 ms 37220 KB Output is correct
25 Correct 24 ms 37108 KB Output is correct
26 Correct 24 ms 37076 KB Output is correct
27 Correct 23 ms 37020 KB Output is correct
28 Correct 20 ms 37076 KB Output is correct
29 Correct 20 ms 37100 KB Output is correct
30 Runtime error 1318 ms 101408 KB Execution killed with signal 11
31 Halted 0 ms 0 KB -