답안 #964662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964662 2024-04-17T09:51:13 Z yellowtoad Sprinkler (JOI22_sprinkler) C++17
41 / 100
4000 ms 77684 KB
#include <iostream>
#include <vector>
#define f first
#define s second
#define int long long
using namespace std;
 
int n, mod, a[200050], cnt, test, p[200050];
pair<int,int> rng[200050], grp[200050];
vector<int> edge[200050], d[200050], node[200050];
bool up;
 
void dfs(int u, int v, int depth) {
	p[u] = v;
	rng[u].f = ++cnt;
	grp[u] = {depth,d[depth].size()};
	d[depth].push_back(u);
	for (int i = 0; i < edge[u].size(); i++) if (edge[u][i] != v) dfs(edge[u][i],u,depth+1);
	rng[u].s = cnt;
}
 
void build(int i, int id, int x, int y) {
	if (x == y) {
		node[i][id] = a[d[i][x]];
		return;
	}
	int mid = (x+y)/2;
	build(i,id*2,x,mid);
	build(i,id*2+1,mid+1,y);
	node[i][id] = 1;
}
 
void update(int i, int id, int x, int y, int l, int r, int val) {
	if ((l <= rng[d[i][x]].f) && (rng[d[i][y]].f <= r)) {
		(node[i][id] *= val) %= mod;
		return;
	}
	if ((rng[d[i][y]].f < l) || (r < rng[d[i][x]].f)) return;
	int mid = (x+y)/2;
	(node[i][id*2] *= node[i][id]) %= mod;
	(node[i][id*2+1] *= node[i][id]) %= mod;
	node[i][id] = 1;
	update(i,id*2,x,mid,l,r,val);
	update(i,id*2+1,mid+1,y,l,r,val);
}

int query(int i, int id, int x, int y, int pos) {
	if (x == y) return node[i][id];
	int mid = (x+y)/2;
	(node[i][id*2] *= node[i][id]) %= mod;
	(node[i][id*2+1] *= node[i][id]) %= mod;
	node[i][id] = 1;
	if (pos <= mid) return query(i,id*2,x,mid,pos);
	else return query(i,id*2+1,mid+1,y,pos);
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> mod;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	for (int i = 1; i <= n; i++) cin >> a[i];
	dfs(1,0,1);
	for (int i = 1; i <= n; i++) {
		if (d[i].size()) {
			node[i].resize(d[i].size()*4+10);
			build(i,1,0,d[i].size()-1);
		}
	}
	cin >> test;
	while (test--) {
		int type, u, dis, val, depth;
		cin >> type;
		if (type == 1) {
			cin >> u >> dis >> val;
			depth = grp[u].f+dis;
			up = 0;
			while (depth >= grp[u].f) {
				if (d[depth].size()) update(depth,1,0,d[depth].size()-1,rng[u].f,rng[u].s,val);
				if ((up) && (p[u])) u = p[u];
				up = 1-up;
				depth--;
			}
		} else {
			cin >> u;
			cout << query(grp[u].f,1,0,d[grp[u].f].size()-1,grp[u].s) << endl;
		}
	}
}

Compilation message

sprinkler.cpp: In function 'void dfs(long long int, long long int, long long int)':
sprinkler.cpp:18:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for (int i = 0; i < edge[u].size(); i++) if (edge[u][i] != v) dfs(edge[u][i],u,depth+1);
      |                  ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 4 ms 21108 KB Output is correct
4 Correct 6 ms 21080 KB Output is correct
5 Correct 8 ms 21080 KB Output is correct
6 Correct 7 ms 21084 KB Output is correct
7 Correct 7 ms 21080 KB Output is correct
8 Correct 6 ms 21240 KB Output is correct
9 Correct 5 ms 21084 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 7 ms 21080 KB Output is correct
12 Correct 6 ms 20932 KB Output is correct
13 Correct 5 ms 21080 KB Output is correct
14 Correct 6 ms 21084 KB Output is correct
15 Correct 5 ms 21084 KB Output is correct
16 Correct 5 ms 21080 KB Output is correct
17 Correct 6 ms 21084 KB Output is correct
18 Correct 5 ms 21084 KB Output is correct
19 Correct 5 ms 21164 KB Output is correct
20 Correct 5 ms 21160 KB Output is correct
21 Correct 5 ms 21236 KB Output is correct
22 Correct 6 ms 21084 KB Output is correct
23 Correct 7 ms 21272 KB Output is correct
24 Correct 5 ms 21084 KB Output is correct
25 Correct 6 ms 21084 KB Output is correct
26 Correct 6 ms 21080 KB Output is correct
27 Correct 6 ms 21080 KB Output is correct
28 Correct 5 ms 21084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 793 ms 43408 KB Output is correct
3 Correct 813 ms 40320 KB Output is correct
4 Correct 657 ms 62484 KB Output is correct
5 Correct 710 ms 41860 KB Output is correct
6 Correct 851 ms 41224 KB Output is correct
7 Correct 829 ms 41596 KB Output is correct
8 Correct 684 ms 41604 KB Output is correct
9 Correct 889 ms 76532 KB Output is correct
10 Correct 561 ms 70132 KB Output is correct
11 Correct 865 ms 43356 KB Output is correct
12 Correct 690 ms 40404 KB Output is correct
13 Correct 332 ms 40908 KB Output is correct
14 Correct 496 ms 39764 KB Output is correct
15 Correct 615 ms 40224 KB Output is correct
16 Correct 694 ms 40000 KB Output is correct
17 Correct 792 ms 40508 KB Output is correct
18 Correct 5 ms 21084 KB Output is correct
19 Correct 5 ms 21084 KB Output is correct
20 Correct 5 ms 21084 KB Output is correct
21 Correct 5 ms 21084 KB Output is correct
22 Correct 5 ms 21084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 793 ms 43408 KB Output is correct
3 Correct 813 ms 40320 KB Output is correct
4 Correct 657 ms 62484 KB Output is correct
5 Correct 710 ms 41860 KB Output is correct
6 Correct 851 ms 41224 KB Output is correct
7 Correct 829 ms 41596 KB Output is correct
8 Correct 684 ms 41604 KB Output is correct
9 Correct 889 ms 76532 KB Output is correct
10 Correct 561 ms 70132 KB Output is correct
11 Correct 865 ms 43356 KB Output is correct
12 Correct 690 ms 40404 KB Output is correct
13 Correct 332 ms 40908 KB Output is correct
14 Correct 496 ms 39764 KB Output is correct
15 Correct 615 ms 40224 KB Output is correct
16 Correct 694 ms 40000 KB Output is correct
17 Correct 792 ms 40508 KB Output is correct
18 Correct 5 ms 21084 KB Output is correct
19 Correct 5 ms 21084 KB Output is correct
20 Correct 5 ms 21084 KB Output is correct
21 Correct 5 ms 21084 KB Output is correct
22 Correct 5 ms 21084 KB Output is correct
23 Correct 5 ms 21084 KB Output is correct
24 Correct 954 ms 43268 KB Output is correct
25 Correct 1041 ms 40220 KB Output is correct
26 Correct 709 ms 73296 KB Output is correct
27 Correct 812 ms 41768 KB Output is correct
28 Correct 1026 ms 41588 KB Output is correct
29 Correct 954 ms 41528 KB Output is correct
30 Correct 687 ms 41580 KB Output is correct
31 Correct 921 ms 65304 KB Output is correct
32 Correct 644 ms 76416 KB Output is correct
33 Correct 867 ms 47764 KB Output is correct
34 Correct 1088 ms 46324 KB Output is correct
35 Correct 6 ms 21084 KB Output is correct
36 Correct 6 ms 21160 KB Output is correct
37 Correct 5 ms 21080 KB Output is correct
38 Correct 5 ms 21172 KB Output is correct
39 Correct 5 ms 21080 KB Output is correct
40 Correct 5 ms 21112 KB Output is correct
41 Correct 5 ms 21084 KB Output is correct
42 Correct 5 ms 21084 KB Output is correct
43 Correct 5 ms 21108 KB Output is correct
44 Correct 5 ms 21084 KB Output is correct
45 Correct 5 ms 21156 KB Output is correct
46 Correct 6 ms 21084 KB Output is correct
47 Correct 5 ms 21084 KB Output is correct
48 Correct 6 ms 21148 KB Output is correct
49 Correct 6 ms 21084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 1038 ms 77420 KB Output is correct
3 Correct 2705 ms 69276 KB Output is correct
4 Correct 1199 ms 70440 KB Output is correct
5 Correct 3502 ms 44868 KB Output is correct
6 Correct 2019 ms 44452 KB Output is correct
7 Correct 1183 ms 44768 KB Output is correct
8 Correct 498 ms 44668 KB Output is correct
9 Correct 1076 ms 66956 KB Output is correct
10 Correct 2917 ms 74568 KB Output is correct
11 Correct 1766 ms 45164 KB Output is correct
12 Execution timed out 4013 ms 43824 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 21080 KB Output is correct
2 Correct 1102 ms 68080 KB Output is correct
3 Correct 3556 ms 60904 KB Output is correct
4 Correct 1538 ms 65012 KB Output is correct
5 Correct 3415 ms 46544 KB Output is correct
6 Correct 2071 ms 46072 KB Output is correct
7 Correct 1312 ms 45932 KB Output is correct
8 Correct 617 ms 45800 KB Output is correct
9 Correct 1244 ms 77684 KB Output is correct
10 Correct 2859 ms 75948 KB Output is correct
11 Correct 1784 ms 47712 KB Output is correct
12 Execution timed out 4009 ms 43892 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 4 ms 21108 KB Output is correct
4 Correct 6 ms 21080 KB Output is correct
5 Correct 8 ms 21080 KB Output is correct
6 Correct 7 ms 21084 KB Output is correct
7 Correct 7 ms 21080 KB Output is correct
8 Correct 6 ms 21240 KB Output is correct
9 Correct 5 ms 21084 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 7 ms 21080 KB Output is correct
12 Correct 6 ms 20932 KB Output is correct
13 Correct 5 ms 21080 KB Output is correct
14 Correct 6 ms 21084 KB Output is correct
15 Correct 5 ms 21084 KB Output is correct
16 Correct 5 ms 21080 KB Output is correct
17 Correct 6 ms 21084 KB Output is correct
18 Correct 5 ms 21084 KB Output is correct
19 Correct 5 ms 21164 KB Output is correct
20 Correct 5 ms 21160 KB Output is correct
21 Correct 5 ms 21236 KB Output is correct
22 Correct 6 ms 21084 KB Output is correct
23 Correct 7 ms 21272 KB Output is correct
24 Correct 5 ms 21084 KB Output is correct
25 Correct 6 ms 21084 KB Output is correct
26 Correct 6 ms 21080 KB Output is correct
27 Correct 6 ms 21080 KB Output is correct
28 Correct 5 ms 21084 KB Output is correct
29 Correct 4 ms 21080 KB Output is correct
30 Correct 793 ms 43408 KB Output is correct
31 Correct 813 ms 40320 KB Output is correct
32 Correct 657 ms 62484 KB Output is correct
33 Correct 710 ms 41860 KB Output is correct
34 Correct 851 ms 41224 KB Output is correct
35 Correct 829 ms 41596 KB Output is correct
36 Correct 684 ms 41604 KB Output is correct
37 Correct 889 ms 76532 KB Output is correct
38 Correct 561 ms 70132 KB Output is correct
39 Correct 865 ms 43356 KB Output is correct
40 Correct 690 ms 40404 KB Output is correct
41 Correct 332 ms 40908 KB Output is correct
42 Correct 496 ms 39764 KB Output is correct
43 Correct 615 ms 40224 KB Output is correct
44 Correct 694 ms 40000 KB Output is correct
45 Correct 792 ms 40508 KB Output is correct
46 Correct 5 ms 21084 KB Output is correct
47 Correct 5 ms 21084 KB Output is correct
48 Correct 5 ms 21084 KB Output is correct
49 Correct 5 ms 21084 KB Output is correct
50 Correct 5 ms 21084 KB Output is correct
51 Correct 5 ms 21084 KB Output is correct
52 Correct 954 ms 43268 KB Output is correct
53 Correct 1041 ms 40220 KB Output is correct
54 Correct 709 ms 73296 KB Output is correct
55 Correct 812 ms 41768 KB Output is correct
56 Correct 1026 ms 41588 KB Output is correct
57 Correct 954 ms 41528 KB Output is correct
58 Correct 687 ms 41580 KB Output is correct
59 Correct 921 ms 65304 KB Output is correct
60 Correct 644 ms 76416 KB Output is correct
61 Correct 867 ms 47764 KB Output is correct
62 Correct 1088 ms 46324 KB Output is correct
63 Correct 6 ms 21084 KB Output is correct
64 Correct 6 ms 21160 KB Output is correct
65 Correct 5 ms 21080 KB Output is correct
66 Correct 5 ms 21172 KB Output is correct
67 Correct 5 ms 21080 KB Output is correct
68 Correct 5 ms 21112 KB Output is correct
69 Correct 5 ms 21084 KB Output is correct
70 Correct 5 ms 21084 KB Output is correct
71 Correct 5 ms 21108 KB Output is correct
72 Correct 5 ms 21084 KB Output is correct
73 Correct 5 ms 21156 KB Output is correct
74 Correct 6 ms 21084 KB Output is correct
75 Correct 5 ms 21084 KB Output is correct
76 Correct 6 ms 21148 KB Output is correct
77 Correct 6 ms 21084 KB Output is correct
78 Correct 4 ms 21084 KB Output is correct
79 Correct 1038 ms 77420 KB Output is correct
80 Correct 2705 ms 69276 KB Output is correct
81 Correct 1199 ms 70440 KB Output is correct
82 Correct 3502 ms 44868 KB Output is correct
83 Correct 2019 ms 44452 KB Output is correct
84 Correct 1183 ms 44768 KB Output is correct
85 Correct 498 ms 44668 KB Output is correct
86 Correct 1076 ms 66956 KB Output is correct
87 Correct 2917 ms 74568 KB Output is correct
88 Correct 1766 ms 45164 KB Output is correct
89 Execution timed out 4013 ms 43824 KB Time limit exceeded
90 Halted 0 ms 0 KB -