답안 #966709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966709 2024-04-20T08:42:10 Z PM1 Sprinkler (JOI22_sprinkler) C++17
41 / 100
4000 ms 65816 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#define ll long long
const int mxn=2e5+5;
int n,M,q,h[mxn],st[mxn],fn[mxn],cnt,dis[mxn],par[mxn];
vector<ll>v[mxn],d[mxn];
struct segment{
	vector<ll>val;
	void build(int sz){
		while(__builtin_popcount(sz)!=1){
			sz++;
		}
		sz*=2;
		while(sz--)
			val.push_back(1);
	}
	void add(int id,int L,int R,int l,int r,ll w){
		if(L==l && R==r){
			val[id]=(val[id]*w)%M;
			return;
		}
		int mid=(L+R)/2;
		if(l<mid)
			add(id*2,L,mid,l,min(r,mid),w);
		if(r>mid)
			add(id*2+1,mid,R,max(l,mid),r,w);
	}
	ll get(int id,int L,int R,int l){
		if(L+1==R)
			return val[id];
		int mid=(L+R)/2;
		if(l<mid)
			return (get(id*2,L,mid,l)*val[id])%M;
		else
			return (get(id*2+1,mid,R,l)*val[id])%M;
	}
}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 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);
	if(l<r+1)
		seg[x].add(1,0,d[x].size(),l,r+1,w);
}
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 seg[z].get(1,0,d[z].size(),l);
}
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++){
		seg[i].build(d[i].size());
	}
	for(int i=1;i<=n;i++){
		int l=lower_bound(d[dis[i]].begin(),d[dis[i]].end(),st[i])-d[dis[i]].begin();
		seg[dis[i]].add(1,0,d[dis[i]].size(),l,l+1,h[i]);
	}
	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 4 ms 14936 KB Output is correct
2 Correct 3 ms 14996 KB Output is correct
3 Correct 5 ms 14940 KB Output is correct
4 Correct 5 ms 15196 KB Output is correct
5 Correct 5 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 6 ms 15040 KB Output is correct
9 Correct 4 ms 15196 KB Output is correct
10 Correct 4 ms 14936 KB Output is correct
11 Correct 4 ms 15008 KB Output is correct
12 Correct 5 ms 14940 KB Output is correct
13 Correct 4 ms 14788 KB Output is correct
14 Correct 4 ms 14936 KB Output is correct
15 Correct 7 ms 14940 KB Output is correct
16 Correct 5 ms 14940 KB Output is correct
17 Correct 6 ms 14936 KB Output is correct
18 Correct 4 ms 14936 KB Output is correct
19 Correct 4 ms 14940 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 4 ms 15004 KB Output is correct
22 Correct 4 ms 14940 KB Output is correct
23 Correct 4 ms 15000 KB Output is correct
24 Correct 4 ms 14940 KB Output is correct
25 Correct 5 ms 14940 KB Output is correct
26 Correct 5 ms 14940 KB Output is correct
27 Correct 5 ms 15192 KB Output is correct
28 Correct 4 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 388 ms 49204 KB Output is correct
3 Correct 553 ms 48804 KB Output is correct
4 Correct 380 ms 58364 KB Output is correct
5 Correct 459 ms 49004 KB Output is correct
6 Correct 517 ms 48372 KB Output is correct
7 Correct 452 ms 48620 KB Output is correct
8 Correct 435 ms 48316 KB Output is correct
9 Correct 331 ms 65816 KB Output is correct
10 Correct 366 ms 63636 KB Output is correct
11 Correct 322 ms 49072 KB Output is correct
12 Correct 450 ms 48660 KB Output is correct
13 Correct 347 ms 48336 KB Output is correct
14 Correct 399 ms 49324 KB Output is correct
15 Correct 369 ms 48236 KB Output is correct
16 Correct 399 ms 48768 KB Output is correct
17 Correct 449 ms 49036 KB Output is correct
18 Correct 3 ms 14940 KB Output is correct
19 Correct 4 ms 14940 KB Output is correct
20 Correct 3 ms 15028 KB Output is correct
21 Correct 3 ms 14940 KB Output is correct
22 Correct 3 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 388 ms 49204 KB Output is correct
3 Correct 553 ms 48804 KB Output is correct
4 Correct 380 ms 58364 KB Output is correct
5 Correct 459 ms 49004 KB Output is correct
6 Correct 517 ms 48372 KB Output is correct
7 Correct 452 ms 48620 KB Output is correct
8 Correct 435 ms 48316 KB Output is correct
9 Correct 331 ms 65816 KB Output is correct
10 Correct 366 ms 63636 KB Output is correct
11 Correct 322 ms 49072 KB Output is correct
12 Correct 450 ms 48660 KB Output is correct
13 Correct 347 ms 48336 KB Output is correct
14 Correct 399 ms 49324 KB Output is correct
15 Correct 369 ms 48236 KB Output is correct
16 Correct 399 ms 48768 KB Output is correct
17 Correct 449 ms 49036 KB Output is correct
18 Correct 3 ms 14940 KB Output is correct
19 Correct 4 ms 14940 KB Output is correct
20 Correct 3 ms 15028 KB Output is correct
21 Correct 3 ms 14940 KB Output is correct
22 Correct 3 ms 14940 KB Output is correct
23 Correct 3 ms 14940 KB Output is correct
24 Correct 335 ms 49144 KB Output is correct
25 Correct 599 ms 48964 KB Output is correct
26 Correct 407 ms 64648 KB Output is correct
27 Correct 385 ms 49104 KB Output is correct
28 Correct 477 ms 48764 KB Output is correct
29 Correct 538 ms 49032 KB Output is correct
30 Correct 397 ms 48480 KB Output is correct
31 Correct 340 ms 59324 KB Output is correct
32 Correct 403 ms 63796 KB Output is correct
33 Correct 325 ms 49328 KB Output is correct
34 Correct 596 ms 48656 KB Output is correct
35 Correct 3 ms 14940 KB Output is correct
36 Correct 4 ms 14940 KB Output is correct
37 Correct 3 ms 14936 KB Output is correct
38 Correct 4 ms 14940 KB Output is correct
39 Correct 3 ms 14940 KB Output is correct
40 Correct 4 ms 15000 KB Output is correct
41 Correct 3 ms 14940 KB Output is correct
42 Correct 3 ms 14940 KB Output is correct
43 Correct 3 ms 15000 KB Output is correct
44 Correct 3 ms 14940 KB Output is correct
45 Correct 4 ms 14780 KB Output is correct
46 Correct 3 ms 14936 KB Output is correct
47 Correct 5 ms 14940 KB Output is correct
48 Correct 4 ms 14936 KB Output is correct
49 Correct 4 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 411 ms 62772 KB Output is correct
3 Correct 1130 ms 57932 KB Output is correct
4 Correct 540 ms 58572 KB Output is correct
5 Correct 1885 ms 46432 KB Output is correct
6 Correct 1205 ms 46164 KB Output is correct
7 Correct 688 ms 46724 KB Output is correct
8 Correct 338 ms 45928 KB Output is correct
9 Correct 540 ms 56628 KB Output is correct
10 Correct 1028 ms 59504 KB Output is correct
11 Correct 884 ms 44100 KB Output is correct
12 Execution timed out 4040 ms 43612 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 483 ms 56152 KB Output is correct
3 Correct 1033 ms 51052 KB Output is correct
4 Correct 501 ms 55824 KB Output is correct
5 Correct 1825 ms 48080 KB Output is correct
6 Correct 1141 ms 48192 KB Output is correct
7 Correct 814 ms 47148 KB Output is correct
8 Correct 359 ms 47092 KB Output is correct
9 Correct 405 ms 63800 KB Output is correct
10 Correct 1014 ms 62228 KB Output is correct
11 Correct 913 ms 48628 KB Output is correct
12 Execution timed out 4008 ms 46232 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14936 KB Output is correct
2 Correct 3 ms 14996 KB Output is correct
3 Correct 5 ms 14940 KB Output is correct
4 Correct 5 ms 15196 KB Output is correct
5 Correct 5 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 6 ms 15040 KB Output is correct
9 Correct 4 ms 15196 KB Output is correct
10 Correct 4 ms 14936 KB Output is correct
11 Correct 4 ms 15008 KB Output is correct
12 Correct 5 ms 14940 KB Output is correct
13 Correct 4 ms 14788 KB Output is correct
14 Correct 4 ms 14936 KB Output is correct
15 Correct 7 ms 14940 KB Output is correct
16 Correct 5 ms 14940 KB Output is correct
17 Correct 6 ms 14936 KB Output is correct
18 Correct 4 ms 14936 KB Output is correct
19 Correct 4 ms 14940 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 4 ms 15004 KB Output is correct
22 Correct 4 ms 14940 KB Output is correct
23 Correct 4 ms 15000 KB Output is correct
24 Correct 4 ms 14940 KB Output is correct
25 Correct 5 ms 14940 KB Output is correct
26 Correct 5 ms 14940 KB Output is correct
27 Correct 5 ms 15192 KB Output is correct
28 Correct 4 ms 14940 KB Output is correct
29 Correct 3 ms 14940 KB Output is correct
30 Correct 388 ms 49204 KB Output is correct
31 Correct 553 ms 48804 KB Output is correct
32 Correct 380 ms 58364 KB Output is correct
33 Correct 459 ms 49004 KB Output is correct
34 Correct 517 ms 48372 KB Output is correct
35 Correct 452 ms 48620 KB Output is correct
36 Correct 435 ms 48316 KB Output is correct
37 Correct 331 ms 65816 KB Output is correct
38 Correct 366 ms 63636 KB Output is correct
39 Correct 322 ms 49072 KB Output is correct
40 Correct 450 ms 48660 KB Output is correct
41 Correct 347 ms 48336 KB Output is correct
42 Correct 399 ms 49324 KB Output is correct
43 Correct 369 ms 48236 KB Output is correct
44 Correct 399 ms 48768 KB Output is correct
45 Correct 449 ms 49036 KB Output is correct
46 Correct 3 ms 14940 KB Output is correct
47 Correct 4 ms 14940 KB Output is correct
48 Correct 3 ms 15028 KB Output is correct
49 Correct 3 ms 14940 KB Output is correct
50 Correct 3 ms 14940 KB Output is correct
51 Correct 3 ms 14940 KB Output is correct
52 Correct 335 ms 49144 KB Output is correct
53 Correct 599 ms 48964 KB Output is correct
54 Correct 407 ms 64648 KB Output is correct
55 Correct 385 ms 49104 KB Output is correct
56 Correct 477 ms 48764 KB Output is correct
57 Correct 538 ms 49032 KB Output is correct
58 Correct 397 ms 48480 KB Output is correct
59 Correct 340 ms 59324 KB Output is correct
60 Correct 403 ms 63796 KB Output is correct
61 Correct 325 ms 49328 KB Output is correct
62 Correct 596 ms 48656 KB Output is correct
63 Correct 3 ms 14940 KB Output is correct
64 Correct 4 ms 14940 KB Output is correct
65 Correct 3 ms 14936 KB Output is correct
66 Correct 4 ms 14940 KB Output is correct
67 Correct 3 ms 14940 KB Output is correct
68 Correct 4 ms 15000 KB Output is correct
69 Correct 3 ms 14940 KB Output is correct
70 Correct 3 ms 14940 KB Output is correct
71 Correct 3 ms 15000 KB Output is correct
72 Correct 3 ms 14940 KB Output is correct
73 Correct 4 ms 14780 KB Output is correct
74 Correct 3 ms 14936 KB Output is correct
75 Correct 5 ms 14940 KB Output is correct
76 Correct 4 ms 14936 KB Output is correct
77 Correct 4 ms 14940 KB Output is correct
78 Correct 3 ms 14940 KB Output is correct
79 Correct 411 ms 62772 KB Output is correct
80 Correct 1130 ms 57932 KB Output is correct
81 Correct 540 ms 58572 KB Output is correct
82 Correct 1885 ms 46432 KB Output is correct
83 Correct 1205 ms 46164 KB Output is correct
84 Correct 688 ms 46724 KB Output is correct
85 Correct 338 ms 45928 KB Output is correct
86 Correct 540 ms 56628 KB Output is correct
87 Correct 1028 ms 59504 KB Output is correct
88 Correct 884 ms 44100 KB Output is correct
89 Execution timed out 4040 ms 43612 KB Time limit exceeded
90 Halted 0 ms 0 KB -