답안 #966762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966762 2024-04-20T10:08:46 Z PM1 Sprinkler (JOI22_sprinkler) C++17
100 / 100
3913 ms 129028 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
const int mxn=2e5+5;
int n,M,q,st[mxn],fn[mxn],cnt,dis[mxn],par[mxn],w;
pair<int,int> fnd[mxn][42];
vector<int>v[mxn],d[mxn];
struct segment{
	vector<long long>val;
	int sz=0;
	void build(){
		while(__builtin_popcount(sz)!=1){
			sz++;
		}
		val.resize(sz*2,1);
	}
	void add(int i,int l,int r,int tl,int tr){
		if(l>r||l>tr||r<tl||tl>tr){
			return ;
		}
		if(l>=tl&&r<=tr){
			val[i]*=w;
			val[i]%=M;
			return ;
		}
		int m=(l+r)>>1;
		add((i<<1),l,m,tl,tr);
		add((i<<1)^1,m+1,r,tl,tr);
		return ;
	}
	int get(int i){
		if(i==0){
			return 1;
		}
		int ret=val[i]*get((i>>1))%M;
		return ret;
	}
}seg[mxn];
void dfs(int z){
	st[z]=++cnt;
	d[dis[z]].push_back(st[z]);
	for(auto i:v[z]){
		if(i!=par[z]){
			par[i]=z;
			dis[i]=dis[z]+1;
			dfs(i);
		}
	}
	fn[z]=cnt;
}
void up(int x,int dd){
	int z=0;
	dd+=dis[x];
	while(dd>=dis[x]){
		if(dd<mxn){
			int l=fnd[x][dd-dis[x]].first;
			int r=fnd[x][dd-dis[x]].second;
			seg[dd].add(1,0,seg[dd].sz-1,l,r);
		}
		if(z)
			x=par[x];
		z^=1;
		dd--;
	}
}
void get(int z,int x){
	int l=fnd[x][0].first;
	cout<<seg[z].get(l+seg[z].sz)<<'\n';
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>M;
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	par[1]=1;
	dfs(1);
	for(int i=0;i<=n;i++){
		seg[i].sz=d[i].size();
		seg[i].build();
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<=40 && dis[i]+j<mxn;j++){
			int dd=dis[i]+j;
			fnd[i][j].first=lower_bound(d[dd].begin(),d[dd].end(),st[i])-d[dd].begin();
			fnd[i][j].second=upper_bound(d[dd].begin(),d[dd].end(),fn[i])-d[dd].begin()-1;
		}
	}
	for(int i=1;i<=n;i++){
		int l=fnd[i][0].first;
		cin>>w;
		seg[dis[i]].add(1,0,seg[dis[i]].sz-1,l,l);
	}
	cin>>q;
	while(q--){
		int ty,x,dd;
		cin>>ty;
		if(ty==1){
			cin>>x>>dd>>w;
			up(x,dd);
		}

		else{
			cin>>x;
			get(dis[x],x);
		}
		
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 4 ms 19036 KB Output is correct
3 Correct 4 ms 19072 KB Output is correct
4 Correct 5 ms 19072 KB Output is correct
5 Correct 6 ms 19032 KB Output is correct
6 Correct 6 ms 19036 KB Output is correct
7 Correct 5 ms 19032 KB Output is correct
8 Correct 5 ms 19036 KB Output is correct
9 Correct 4 ms 19036 KB Output is correct
10 Correct 4 ms 19036 KB Output is correct
11 Correct 4 ms 19032 KB Output is correct
12 Correct 4 ms 19036 KB Output is correct
13 Correct 5 ms 19036 KB Output is correct
14 Correct 5 ms 19036 KB Output is correct
15 Correct 4 ms 19036 KB Output is correct
16 Correct 5 ms 19124 KB Output is correct
17 Correct 4 ms 19032 KB Output is correct
18 Correct 4 ms 19108 KB Output is correct
19 Correct 4 ms 19036 KB Output is correct
20 Correct 4 ms 19032 KB Output is correct
21 Correct 4 ms 19104 KB Output is correct
22 Correct 4 ms 19060 KB Output is correct
23 Correct 4 ms 19036 KB Output is correct
24 Correct 5 ms 19036 KB Output is correct
25 Correct 5 ms 19036 KB Output is correct
26 Correct 4 ms 19036 KB Output is correct
27 Correct 4 ms 19036 KB Output is correct
28 Correct 5 ms 19036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19032 KB Output is correct
2 Correct 825 ms 113396 KB Output is correct
3 Correct 1054 ms 113712 KB Output is correct
4 Correct 406 ms 122872 KB Output is correct
5 Correct 1025 ms 113524 KB Output is correct
6 Correct 655 ms 113136 KB Output is correct
7 Correct 558 ms 113468 KB Output is correct
8 Correct 355 ms 113224 KB Output is correct
9 Correct 416 ms 129028 KB Output is correct
10 Correct 427 ms 127620 KB Output is correct
11 Correct 886 ms 113504 KB Output is correct
12 Correct 965 ms 113260 KB Output is correct
13 Correct 397 ms 113360 KB Output is correct
14 Correct 443 ms 114468 KB Output is correct
15 Correct 429 ms 113116 KB Output is correct
16 Correct 447 ms 113912 KB Output is correct
17 Correct 512 ms 113696 KB Output is correct
18 Correct 4 ms 19032 KB Output is correct
19 Correct 5 ms 19036 KB Output is correct
20 Correct 4 ms 19132 KB Output is correct
21 Correct 4 ms 19036 KB Output is correct
22 Correct 4 ms 19036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19032 KB Output is correct
2 Correct 825 ms 113396 KB Output is correct
3 Correct 1054 ms 113712 KB Output is correct
4 Correct 406 ms 122872 KB Output is correct
5 Correct 1025 ms 113524 KB Output is correct
6 Correct 655 ms 113136 KB Output is correct
7 Correct 558 ms 113468 KB Output is correct
8 Correct 355 ms 113224 KB Output is correct
9 Correct 416 ms 129028 KB Output is correct
10 Correct 427 ms 127620 KB Output is correct
11 Correct 886 ms 113504 KB Output is correct
12 Correct 965 ms 113260 KB Output is correct
13 Correct 397 ms 113360 KB Output is correct
14 Correct 443 ms 114468 KB Output is correct
15 Correct 429 ms 113116 KB Output is correct
16 Correct 447 ms 113912 KB Output is correct
17 Correct 512 ms 113696 KB Output is correct
18 Correct 4 ms 19032 KB Output is correct
19 Correct 5 ms 19036 KB Output is correct
20 Correct 4 ms 19132 KB Output is correct
21 Correct 4 ms 19036 KB Output is correct
22 Correct 4 ms 19036 KB Output is correct
23 Correct 5 ms 19036 KB Output is correct
24 Correct 944 ms 113436 KB Output is correct
25 Correct 1095 ms 113116 KB Output is correct
26 Correct 398 ms 128096 KB Output is correct
27 Correct 1008 ms 113584 KB Output is correct
28 Correct 733 ms 113460 KB Output is correct
29 Correct 600 ms 113480 KB Output is correct
30 Correct 356 ms 113124 KB Output is correct
31 Correct 452 ms 123732 KB Output is correct
32 Correct 426 ms 127484 KB Output is correct
33 Correct 817 ms 113688 KB Output is correct
34 Correct 1185 ms 113212 KB Output is correct
35 Correct 6 ms 19036 KB Output is correct
36 Correct 4 ms 19036 KB Output is correct
37 Correct 4 ms 19036 KB Output is correct
38 Correct 5 ms 19036 KB Output is correct
39 Correct 4 ms 19036 KB Output is correct
40 Correct 4 ms 19036 KB Output is correct
41 Correct 4 ms 19064 KB Output is correct
42 Correct 5 ms 19036 KB Output is correct
43 Correct 4 ms 19036 KB Output is correct
44 Correct 5 ms 19032 KB Output is correct
45 Correct 4 ms 19288 KB Output is correct
46 Correct 4 ms 19036 KB Output is correct
47 Correct 5 ms 19036 KB Output is correct
48 Correct 4 ms 19068 KB Output is correct
49 Correct 4 ms 19036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 627 ms 125792 KB Output is correct
3 Correct 2179 ms 122024 KB Output is correct
4 Correct 938 ms 122492 KB Output is correct
5 Correct 1915 ms 110728 KB Output is correct
6 Correct 1139 ms 110676 KB Output is correct
7 Correct 739 ms 111464 KB Output is correct
8 Correct 409 ms 108664 KB Output is correct
9 Correct 605 ms 120776 KB Output is correct
10 Correct 1903 ms 124696 KB Output is correct
11 Correct 1218 ms 110852 KB Output is correct
12 Correct 3526 ms 110940 KB Output is correct
13 Correct 2887 ms 111076 KB Output is correct
14 Correct 2462 ms 113644 KB Output is correct
15 Correct 4 ms 19032 KB Output is correct
16 Correct 5 ms 19036 KB Output is correct
17 Correct 4 ms 19036 KB Output is correct
18 Correct 4 ms 19036 KB Output is correct
19 Correct 4 ms 18888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 579 ms 122688 KB Output is correct
3 Correct 2562 ms 118372 KB Output is correct
4 Correct 934 ms 120696 KB Output is correct
5 Correct 1716 ms 112408 KB Output is correct
6 Correct 1018 ms 112736 KB Output is correct
7 Correct 770 ms 112180 KB Output is correct
8 Correct 353 ms 112052 KB Output is correct
9 Correct 526 ms 127524 KB Output is correct
10 Correct 1848 ms 125948 KB Output is correct
11 Correct 1192 ms 113292 KB Output is correct
12 Correct 3634 ms 111504 KB Output is correct
13 Correct 2848 ms 111116 KB Output is correct
14 Correct 2473 ms 113628 KB Output is correct
15 Correct 4 ms 19036 KB Output is correct
16 Correct 5 ms 19036 KB Output is correct
17 Correct 5 ms 19036 KB Output is correct
18 Correct 4 ms 19036 KB Output is correct
19 Correct 4 ms 19036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 4 ms 19036 KB Output is correct
3 Correct 4 ms 19072 KB Output is correct
4 Correct 5 ms 19072 KB Output is correct
5 Correct 6 ms 19032 KB Output is correct
6 Correct 6 ms 19036 KB Output is correct
7 Correct 5 ms 19032 KB Output is correct
8 Correct 5 ms 19036 KB Output is correct
9 Correct 4 ms 19036 KB Output is correct
10 Correct 4 ms 19036 KB Output is correct
11 Correct 4 ms 19032 KB Output is correct
12 Correct 4 ms 19036 KB Output is correct
13 Correct 5 ms 19036 KB Output is correct
14 Correct 5 ms 19036 KB Output is correct
15 Correct 4 ms 19036 KB Output is correct
16 Correct 5 ms 19124 KB Output is correct
17 Correct 4 ms 19032 KB Output is correct
18 Correct 4 ms 19108 KB Output is correct
19 Correct 4 ms 19036 KB Output is correct
20 Correct 4 ms 19032 KB Output is correct
21 Correct 4 ms 19104 KB Output is correct
22 Correct 4 ms 19060 KB Output is correct
23 Correct 4 ms 19036 KB Output is correct
24 Correct 5 ms 19036 KB Output is correct
25 Correct 5 ms 19036 KB Output is correct
26 Correct 4 ms 19036 KB Output is correct
27 Correct 4 ms 19036 KB Output is correct
28 Correct 5 ms 19036 KB Output is correct
29 Correct 4 ms 19032 KB Output is correct
30 Correct 825 ms 113396 KB Output is correct
31 Correct 1054 ms 113712 KB Output is correct
32 Correct 406 ms 122872 KB Output is correct
33 Correct 1025 ms 113524 KB Output is correct
34 Correct 655 ms 113136 KB Output is correct
35 Correct 558 ms 113468 KB Output is correct
36 Correct 355 ms 113224 KB Output is correct
37 Correct 416 ms 129028 KB Output is correct
38 Correct 427 ms 127620 KB Output is correct
39 Correct 886 ms 113504 KB Output is correct
40 Correct 965 ms 113260 KB Output is correct
41 Correct 397 ms 113360 KB Output is correct
42 Correct 443 ms 114468 KB Output is correct
43 Correct 429 ms 113116 KB Output is correct
44 Correct 447 ms 113912 KB Output is correct
45 Correct 512 ms 113696 KB Output is correct
46 Correct 4 ms 19032 KB Output is correct
47 Correct 5 ms 19036 KB Output is correct
48 Correct 4 ms 19132 KB Output is correct
49 Correct 4 ms 19036 KB Output is correct
50 Correct 4 ms 19036 KB Output is correct
51 Correct 5 ms 19036 KB Output is correct
52 Correct 944 ms 113436 KB Output is correct
53 Correct 1095 ms 113116 KB Output is correct
54 Correct 398 ms 128096 KB Output is correct
55 Correct 1008 ms 113584 KB Output is correct
56 Correct 733 ms 113460 KB Output is correct
57 Correct 600 ms 113480 KB Output is correct
58 Correct 356 ms 113124 KB Output is correct
59 Correct 452 ms 123732 KB Output is correct
60 Correct 426 ms 127484 KB Output is correct
61 Correct 817 ms 113688 KB Output is correct
62 Correct 1185 ms 113212 KB Output is correct
63 Correct 6 ms 19036 KB Output is correct
64 Correct 4 ms 19036 KB Output is correct
65 Correct 4 ms 19036 KB Output is correct
66 Correct 5 ms 19036 KB Output is correct
67 Correct 4 ms 19036 KB Output is correct
68 Correct 4 ms 19036 KB Output is correct
69 Correct 4 ms 19064 KB Output is correct
70 Correct 5 ms 19036 KB Output is correct
71 Correct 4 ms 19036 KB Output is correct
72 Correct 5 ms 19032 KB Output is correct
73 Correct 4 ms 19288 KB Output is correct
74 Correct 4 ms 19036 KB Output is correct
75 Correct 5 ms 19036 KB Output is correct
76 Correct 4 ms 19068 KB Output is correct
77 Correct 4 ms 19036 KB Output is correct
78 Correct 4 ms 19036 KB Output is correct
79 Correct 627 ms 125792 KB Output is correct
80 Correct 2179 ms 122024 KB Output is correct
81 Correct 938 ms 122492 KB Output is correct
82 Correct 1915 ms 110728 KB Output is correct
83 Correct 1139 ms 110676 KB Output is correct
84 Correct 739 ms 111464 KB Output is correct
85 Correct 409 ms 108664 KB Output is correct
86 Correct 605 ms 120776 KB Output is correct
87 Correct 1903 ms 124696 KB Output is correct
88 Correct 1218 ms 110852 KB Output is correct
89 Correct 3526 ms 110940 KB Output is correct
90 Correct 2887 ms 111076 KB Output is correct
91 Correct 2462 ms 113644 KB Output is correct
92 Correct 4 ms 19032 KB Output is correct
93 Correct 5 ms 19036 KB Output is correct
94 Correct 4 ms 19036 KB Output is correct
95 Correct 4 ms 19036 KB Output is correct
96 Correct 4 ms 18888 KB Output is correct
97 Correct 4 ms 19036 KB Output is correct
98 Correct 579 ms 122688 KB Output is correct
99 Correct 2562 ms 118372 KB Output is correct
100 Correct 934 ms 120696 KB Output is correct
101 Correct 1716 ms 112408 KB Output is correct
102 Correct 1018 ms 112736 KB Output is correct
103 Correct 770 ms 112180 KB Output is correct
104 Correct 353 ms 112052 KB Output is correct
105 Correct 526 ms 127524 KB Output is correct
106 Correct 1848 ms 125948 KB Output is correct
107 Correct 1192 ms 113292 KB Output is correct
108 Correct 3634 ms 111504 KB Output is correct
109 Correct 2848 ms 111116 KB Output is correct
110 Correct 2473 ms 113628 KB Output is correct
111 Correct 4 ms 19036 KB Output is correct
112 Correct 5 ms 19036 KB Output is correct
113 Correct 5 ms 19036 KB Output is correct
114 Correct 4 ms 19036 KB Output is correct
115 Correct 4 ms 19036 KB Output is correct
116 Correct 1184 ms 111584 KB Output is correct
117 Correct 3840 ms 112860 KB Output is correct
118 Correct 765 ms 127980 KB Output is correct
119 Correct 1859 ms 113428 KB Output is correct
120 Correct 1054 ms 113420 KB Output is correct
121 Correct 860 ms 113252 KB Output is correct
122 Correct 364 ms 113184 KB Output is correct
123 Correct 561 ms 125536 KB Output is correct
124 Correct 2246 ms 121636 KB Output is correct
125 Correct 1265 ms 112636 KB Output is correct
126 Correct 3842 ms 113340 KB Output is correct
127 Correct 3913 ms 113432 KB Output is correct
128 Correct 2765 ms 115892 KB Output is correct
129 Correct 3344 ms 118260 KB Output is correct