답안 #589577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
589577 2022-07-04T21:42:10 Z GioChkhaidze Sprinkler (JOI22_sprinkler) C++14
3 / 100
285 ms 189752 KB
#include <bits/stdc++.h>

#define ll long long
#define pb push_back

using namespace std;

const int N = 2e5 + 5;
const int K = 44;

int n, q, pr[N];
ll D[N][K], h[N], L;
vector < int > v[N];

void dfs(int x, int p) {
	pr[x] = p;
	for (int i = 0; i < v[x].size(); ++i) {
		int to = v[x][i];
		if (to == p) continue;
		dfs(to, x);
	}
}

main () {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> L;
	for (int i = 1; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
	}
	
	dfs(1, 0);
	int st = 0;
	for (int i = n + 1; i <= n + 40; ++i) {
		pr[st] = i;
		st = i;
	}
	
	for (int i = 0; i <= n + 40; ++i) {
		for (int j = 0; j <= 40; ++j) {
			D[i][j] = 1;
		}
	}
	
	for (int i = 1; i <= n; ++i) {
		cin >> h[i];
	}
	
	cin >> q;
	for (int i = 1; i <= q; ++i) {
		int tp, x;
		cin >> tp;
		if (tp == 1) {
			ll d, W;
			cin >> x >> d >> W;
			for (int j = d; j >= 0; --j) {
				D[x][j] = (D[x][j] * W) % L;
				if (0 < j) {
					D[x][j - 1] = (D[x][j - 1] * W) % L;
				}
				D[x][j] %= L;
				x = pr[x];
			}
		}	
			else 
		if (tp == 2) {
			cin >> x;	
			ll ans = h[x];
			for (int j = 0; j <= 40; ++j) {
				ans = (ans * D[x][j]) % L;
				x = pr[x];
			}
			cout << ans << "\n";
		}
	}
}

Compilation message

sprinkler.cpp: In function 'void dfs(int, int)':
sprinkler.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for (int i = 0; i < v[x].size(); ++i) {
      |                  ~~^~~~~~~~~~~~~
sprinkler.cpp: At global scope:
sprinkler.cpp:24:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   24 | main () {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 5008 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5460 KB Output is correct
5 Correct 4 ms 5460 KB Output is correct
6 Correct 4 ms 5460 KB Output is correct
7 Correct 4 ms 5460 KB Output is correct
8 Correct 3 ms 5432 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 5032 KB Output is correct
17 Correct 3 ms 5036 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 5032 KB Output is correct
24 Correct 3 ms 5036 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5028 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Runtime error 285 ms 171888 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Runtime error 285 ms 171888 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Runtime error 249 ms 189752 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Runtime error 277 ms 183672 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 5008 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5460 KB Output is correct
5 Correct 4 ms 5460 KB Output is correct
6 Correct 4 ms 5460 KB Output is correct
7 Correct 4 ms 5460 KB Output is correct
8 Correct 3 ms 5432 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 5032 KB Output is correct
17 Correct 3 ms 5036 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 5032 KB Output is correct
24 Correct 3 ms 5036 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5028 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Runtime error 285 ms 171888 KB Execution killed with signal 11
31 Halted 0 ms 0 KB -