답안 #966645

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966645 2024-04-20T07:38:12 Z PM1 Sprinkler (JOI22_sprinkler) C++17
41 / 100
4000 ms 74960 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxn=2e5+5,sq=448;
int n,M,q,h[mxn],st[mxn],fn[mxn],cnt,dis[mxn],par[mxn];
vector<ll>v[mxn],d[mxn],res[mxn],lazy[mxn];
void dfs(int z){
	st[z]=++cnt;
	d[dis[z]].push_back(st[z]);
	res[dis[z]].push_back(h[z]);
	for(auto i:v[z]){
		if(i!=par[z]){
			par[i]=z;
			dis[i]=dis[z]+1;
			dfs(i);
		}
	}
	fn[z]=cnt;
}
void add(int x,int L,int R,ll w){
	if(d[x].size()==0)return;
	int l=lower_bound(d[x].begin(),d[x].end(),L)-d[x].begin();
	int r=upper_bound(d[x].begin(),d[x].end(),R)-d[x].begin()-1;
	r=min((int)d[x].size()-1,r);

	for(;l<=r && l%sq!=0;l++)
		res[x][l]=(res[x][l]*w)%M;
	for(;l+sq-1<=r;l+=sq)
		lazy[x][l/sq]=(lazy[x][l/sq]*w)%M;
	for(;l<=r;l++)
		res[x][l]=(res[x][l]*w)%M;
}
void up(int x,int dd,int w){
	for(;dd>=1 && x!=1;dd--){
		int z=dis[x]+dd,zz=dis[x]+dd-1;
		add(z,st[x],fn[x],w);
		add(zz,st[x],fn[x],w);
		x=par[x];
	}
	for(;dd>=0;dd--){
		add(dis[x]+dd,st[x],fn[x],w);
	}
}
ll get(int z,int x){
	int l=lower_bound(d[z].begin(),d[z].end(),st[x])-d[z].begin();
	return (res[z][l]*lazy[z][l/sq])%M;
}
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);
	}
	for(int i=1;i<=n;i++)
		cin>>h[i];
	dfs(1);
	for(int i=0;i<=n;i++){
		int x=d[i].size();
		while(x>0){
			x-=sq;
			lazy[i].push_back(1);
		}
	}
	
	cin>>q;
	while(q--){
		int ty,x,dd,w;
		cin>>ty;
		if(ty==1){
			cin>>x>>dd>>w;
			up(x,dd,w);
		}

		else{
			cin>>x;
			cout<<get(dis[x],x)<<'\n';
		}
		
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 5 ms 21084 KB Output is correct
3 Correct 5 ms 21084 KB Output is correct
4 Correct 6 ms 21336 KB Output is correct
5 Correct 7 ms 21488 KB Output is correct
6 Correct 8 ms 21084 KB Output is correct
7 Correct 9 ms 21128 KB Output is correct
8 Correct 7 ms 21080 KB Output is correct
9 Correct 5 ms 21084 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 5 ms 21176 KB Output is correct
12 Correct 5 ms 21084 KB Output is correct
13 Correct 5 ms 21084 KB Output is correct
14 Correct 5 ms 20940 KB Output is correct
15 Correct 5 ms 21176 KB Output is correct
16 Correct 6 ms 21084 KB Output is correct
17 Correct 5 ms 21084 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 21180 KB Output is correct
21 Correct 5 ms 21084 KB Output is correct
22 Correct 5 ms 21080 KB Output is correct
23 Correct 5 ms 21084 KB Output is correct
24 Correct 5 ms 21084 KB Output is correct
25 Correct 5 ms 21080 KB Output is correct
26 Correct 5 ms 21084 KB Output is correct
27 Correct 5 ms 21084 KB Output is correct
28 Correct 5 ms 21084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 254 ms 46964 KB Output is correct
3 Correct 370 ms 47700 KB Output is correct
4 Correct 354 ms 63312 KB Output is correct
5 Correct 314 ms 47440 KB Output is correct
6 Correct 300 ms 45872 KB Output is correct
7 Correct 321 ms 46376 KB Output is correct
8 Correct 251 ms 48060 KB Output is correct
9 Correct 348 ms 74960 KB Output is correct
10 Correct 372 ms 72268 KB Output is correct
11 Correct 247 ms 46956 KB Output is correct
12 Correct 352 ms 47216 KB Output is correct
13 Correct 1760 ms 47620 KB Output is correct
14 Correct 1881 ms 47648 KB Output is correct
15 Correct 1242 ms 46272 KB Output is correct
16 Correct 1028 ms 46732 KB Output is correct
17 Correct 1508 ms 47420 KB Output is correct
18 Correct 6 ms 21336 KB Output is correct
19 Correct 6 ms 21084 KB Output is correct
20 Correct 5 ms 21084 KB Output is correct
21 Correct 5 ms 21168 KB Output is correct
22 Correct 5 ms 21168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 254 ms 46964 KB Output is correct
3 Correct 370 ms 47700 KB Output is correct
4 Correct 354 ms 63312 KB Output is correct
5 Correct 314 ms 47440 KB Output is correct
6 Correct 300 ms 45872 KB Output is correct
7 Correct 321 ms 46376 KB Output is correct
8 Correct 251 ms 48060 KB Output is correct
9 Correct 348 ms 74960 KB Output is correct
10 Correct 372 ms 72268 KB Output is correct
11 Correct 247 ms 46956 KB Output is correct
12 Correct 352 ms 47216 KB Output is correct
13 Correct 1760 ms 47620 KB Output is correct
14 Correct 1881 ms 47648 KB Output is correct
15 Correct 1242 ms 46272 KB Output is correct
16 Correct 1028 ms 46732 KB Output is correct
17 Correct 1508 ms 47420 KB Output is correct
18 Correct 6 ms 21336 KB Output is correct
19 Correct 6 ms 21084 KB Output is correct
20 Correct 5 ms 21084 KB Output is correct
21 Correct 5 ms 21168 KB Output is correct
22 Correct 5 ms 21168 KB Output is correct
23 Correct 5 ms 21164 KB Output is correct
24 Correct 327 ms 46748 KB Output is correct
25 Correct 478 ms 47476 KB Output is correct
26 Correct 418 ms 73512 KB Output is correct
27 Correct 373 ms 47028 KB Output is correct
28 Correct 372 ms 46552 KB Output is correct
29 Correct 372 ms 46124 KB Output is correct
30 Correct 602 ms 48224 KB Output is correct
31 Correct 347 ms 64592 KB Output is correct
32 Correct 392 ms 72276 KB Output is correct
33 Correct 278 ms 46776 KB Output is correct
34 Correct 489 ms 47440 KB Output is correct
35 Correct 5 ms 21084 KB Output is correct
36 Correct 7 ms 21340 KB Output is correct
37 Correct 5 ms 21084 KB Output is correct
38 Correct 5 ms 21084 KB Output is correct
39 Correct 5 ms 21084 KB Output is correct
40 Correct 5 ms 21164 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 21084 KB Output is correct
44 Correct 5 ms 21084 KB Output is correct
45 Correct 6 ms 21184 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 21124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 505 ms 71088 KB Output is correct
3 Correct 990 ms 63688 KB Output is correct
4 Correct 537 ms 64988 KB Output is correct
5 Correct 1458 ms 44108 KB Output is correct
6 Execution timed out 4027 ms 42660 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 476 ms 62552 KB Output is correct
3 Correct 1055 ms 56552 KB Output is correct
4 Correct 504 ms 60240 KB Output is correct
5 Correct 1430 ms 45872 KB Output is correct
6 Execution timed out 4054 ms 44024 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 5 ms 21084 KB Output is correct
3 Correct 5 ms 21084 KB Output is correct
4 Correct 6 ms 21336 KB Output is correct
5 Correct 7 ms 21488 KB Output is correct
6 Correct 8 ms 21084 KB Output is correct
7 Correct 9 ms 21128 KB Output is correct
8 Correct 7 ms 21080 KB Output is correct
9 Correct 5 ms 21084 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 5 ms 21176 KB Output is correct
12 Correct 5 ms 21084 KB Output is correct
13 Correct 5 ms 21084 KB Output is correct
14 Correct 5 ms 20940 KB Output is correct
15 Correct 5 ms 21176 KB Output is correct
16 Correct 6 ms 21084 KB Output is correct
17 Correct 5 ms 21084 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 21180 KB Output is correct
21 Correct 5 ms 21084 KB Output is correct
22 Correct 5 ms 21080 KB Output is correct
23 Correct 5 ms 21084 KB Output is correct
24 Correct 5 ms 21084 KB Output is correct
25 Correct 5 ms 21080 KB Output is correct
26 Correct 5 ms 21084 KB Output is correct
27 Correct 5 ms 21084 KB Output is correct
28 Correct 5 ms 21084 KB Output is correct
29 Correct 5 ms 21084 KB Output is correct
30 Correct 254 ms 46964 KB Output is correct
31 Correct 370 ms 47700 KB Output is correct
32 Correct 354 ms 63312 KB Output is correct
33 Correct 314 ms 47440 KB Output is correct
34 Correct 300 ms 45872 KB Output is correct
35 Correct 321 ms 46376 KB Output is correct
36 Correct 251 ms 48060 KB Output is correct
37 Correct 348 ms 74960 KB Output is correct
38 Correct 372 ms 72268 KB Output is correct
39 Correct 247 ms 46956 KB Output is correct
40 Correct 352 ms 47216 KB Output is correct
41 Correct 1760 ms 47620 KB Output is correct
42 Correct 1881 ms 47648 KB Output is correct
43 Correct 1242 ms 46272 KB Output is correct
44 Correct 1028 ms 46732 KB Output is correct
45 Correct 1508 ms 47420 KB Output is correct
46 Correct 6 ms 21336 KB Output is correct
47 Correct 6 ms 21084 KB Output is correct
48 Correct 5 ms 21084 KB Output is correct
49 Correct 5 ms 21168 KB Output is correct
50 Correct 5 ms 21168 KB Output is correct
51 Correct 5 ms 21164 KB Output is correct
52 Correct 327 ms 46748 KB Output is correct
53 Correct 478 ms 47476 KB Output is correct
54 Correct 418 ms 73512 KB Output is correct
55 Correct 373 ms 47028 KB Output is correct
56 Correct 372 ms 46552 KB Output is correct
57 Correct 372 ms 46124 KB Output is correct
58 Correct 602 ms 48224 KB Output is correct
59 Correct 347 ms 64592 KB Output is correct
60 Correct 392 ms 72276 KB Output is correct
61 Correct 278 ms 46776 KB Output is correct
62 Correct 489 ms 47440 KB Output is correct
63 Correct 5 ms 21084 KB Output is correct
64 Correct 7 ms 21340 KB Output is correct
65 Correct 5 ms 21084 KB Output is correct
66 Correct 5 ms 21084 KB Output is correct
67 Correct 5 ms 21084 KB Output is correct
68 Correct 5 ms 21164 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 21084 KB Output is correct
72 Correct 5 ms 21084 KB Output is correct
73 Correct 6 ms 21184 KB Output is correct
74 Correct 5 ms 21084 KB Output is correct
75 Correct 5 ms 21084 KB Output is correct
76 Correct 5 ms 21084 KB Output is correct
77 Correct 5 ms 21124 KB Output is correct
78 Correct 5 ms 21084 KB Output is correct
79 Correct 505 ms 71088 KB Output is correct
80 Correct 990 ms 63688 KB Output is correct
81 Correct 537 ms 64988 KB Output is correct
82 Correct 1458 ms 44108 KB Output is correct
83 Execution timed out 4027 ms 42660 KB Time limit exceeded
84 Halted 0 ms 0 KB -