Submission #966698

# Submission time Handle Problem Language Result Execution time Memory
966698 2024-04-20T08:32:07 Z PM1 Sprinkler (JOI22_sprinkler) C++17
41 / 100
4000 ms 66228 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 id){
		int i=1;
		while(i<=id*2)i*=2;
		while(i--)
			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;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14936 KB Output is correct
2 Correct 4 ms 14940 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 4 ms 15196 KB Output is correct
5 Correct 5 ms 14940 KB Output is correct
6 Correct 5 ms 14940 KB Output is correct
7 Correct 6 ms 15196 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 4 ms 15032 KB Output is correct
10 Correct 4 ms 14936 KB Output is correct
11 Correct 5 ms 14936 KB Output is correct
12 Correct 4 ms 15024 KB Output is correct
13 Correct 4 ms 14936 KB Output is correct
14 Correct 3 ms 14936 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 5 ms 15004 KB Output is correct
17 Correct 3 ms 14940 KB Output is correct
18 Correct 4 ms 15000 KB Output is correct
19 Correct 3 ms 14940 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 3 ms 14940 KB Output is correct
22 Correct 3 ms 14940 KB Output is correct
23 Correct 4 ms 14940 KB Output is correct
24 Correct 3 ms 14940 KB Output is correct
25 Correct 3 ms 14936 KB Output is correct
26 Correct 5 ms 14940 KB Output is correct
27 Correct 4 ms 14940 KB Output is correct
28 Correct 4 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 342 ms 46968 KB Output is correct
3 Correct 468 ms 45612 KB Output is correct
4 Correct 314 ms 58448 KB Output is correct
5 Correct 434 ms 46820 KB Output is correct
6 Correct 454 ms 45432 KB Output is correct
7 Correct 447 ms 45968 KB Output is correct
8 Correct 387 ms 46280 KB Output is correct
9 Correct 319 ms 66228 KB Output is correct
10 Correct 433 ms 63780 KB Output is correct
11 Correct 291 ms 46660 KB Output is correct
12 Correct 413 ms 45688 KB Output is correct
13 Correct 276 ms 45496 KB Output is correct
14 Correct 353 ms 46056 KB Output is correct
15 Correct 377 ms 45272 KB Output is correct
16 Correct 388 ms 45444 KB Output is correct
17 Correct 418 ms 45504 KB Output is correct
18 Correct 3 ms 14936 KB Output is correct
19 Correct 4 ms 14788 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 3 ms 14784 KB Output is correct
22 Correct 4 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 342 ms 46968 KB Output is correct
3 Correct 468 ms 45612 KB Output is correct
4 Correct 314 ms 58448 KB Output is correct
5 Correct 434 ms 46820 KB Output is correct
6 Correct 454 ms 45432 KB Output is correct
7 Correct 447 ms 45968 KB Output is correct
8 Correct 387 ms 46280 KB Output is correct
9 Correct 319 ms 66228 KB Output is correct
10 Correct 433 ms 63780 KB Output is correct
11 Correct 291 ms 46660 KB Output is correct
12 Correct 413 ms 45688 KB Output is correct
13 Correct 276 ms 45496 KB Output is correct
14 Correct 353 ms 46056 KB Output is correct
15 Correct 377 ms 45272 KB Output is correct
16 Correct 388 ms 45444 KB Output is correct
17 Correct 418 ms 45504 KB Output is correct
18 Correct 3 ms 14936 KB Output is correct
19 Correct 4 ms 14788 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 3 ms 14784 KB Output is correct
22 Correct 4 ms 14940 KB Output is correct
23 Correct 4 ms 14940 KB Output is correct
24 Correct 346 ms 46724 KB Output is correct
25 Correct 543 ms 45468 KB Output is correct
26 Correct 424 ms 64772 KB Output is correct
27 Correct 388 ms 46036 KB Output is correct
28 Correct 495 ms 45944 KB Output is correct
29 Correct 504 ms 46168 KB Output is correct
30 Correct 342 ms 45492 KB Output is correct
31 Correct 337 ms 60164 KB Output is correct
32 Correct 387 ms 63408 KB Output is correct
33 Correct 374 ms 46924 KB Output is correct
34 Correct 607 ms 45584 KB Output is correct
35 Correct 4 ms 14936 KB Output is correct
36 Correct 5 ms 14940 KB Output is correct
37 Correct 5 ms 14940 KB Output is correct
38 Correct 4 ms 14936 KB Output is correct
39 Correct 3 ms 14940 KB Output is correct
40 Correct 3 ms 14940 KB Output is correct
41 Correct 4 ms 14936 KB Output is correct
42 Correct 4 ms 14940 KB Output is correct
43 Correct 4 ms 14940 KB Output is correct
44 Correct 3 ms 14936 KB Output is correct
45 Correct 3 ms 15192 KB Output is correct
46 Correct 4 ms 14940 KB Output is correct
47 Correct 4 ms 14940 KB Output is correct
48 Correct 4 ms 14940 KB Output is correct
49 Correct 3 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 453 ms 63596 KB Output is correct
3 Correct 1166 ms 58896 KB Output is correct
4 Correct 606 ms 59668 KB Output is correct
5 Correct 1811 ms 43976 KB Output is correct
6 Correct 1202 ms 43624 KB Output is correct
7 Correct 703 ms 44424 KB Output is correct
8 Correct 322 ms 43540 KB Output is correct
9 Correct 444 ms 57388 KB Output is correct
10 Correct 1106 ms 62024 KB Output is correct
11 Correct 913 ms 46608 KB Output is correct
12 Execution timed out 4101 ms 46080 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14992 KB Output is correct
2 Correct 423 ms 61576 KB Output is correct
3 Correct 1119 ms 56556 KB Output is correct
4 Correct 574 ms 59284 KB Output is correct
5 Correct 1662 ms 48040 KB Output is correct
6 Correct 1189 ms 45244 KB Output is correct
7 Correct 754 ms 44628 KB Output is correct
8 Correct 336 ms 44864 KB Output is correct
9 Correct 474 ms 64648 KB Output is correct
10 Correct 1101 ms 62748 KB Output is correct
11 Correct 897 ms 46416 KB Output is correct
12 Execution timed out 4101 ms 43584 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14936 KB Output is correct
2 Correct 4 ms 14940 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 4 ms 15196 KB Output is correct
5 Correct 5 ms 14940 KB Output is correct
6 Correct 5 ms 14940 KB Output is correct
7 Correct 6 ms 15196 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 4 ms 15032 KB Output is correct
10 Correct 4 ms 14936 KB Output is correct
11 Correct 5 ms 14936 KB Output is correct
12 Correct 4 ms 15024 KB Output is correct
13 Correct 4 ms 14936 KB Output is correct
14 Correct 3 ms 14936 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 5 ms 15004 KB Output is correct
17 Correct 3 ms 14940 KB Output is correct
18 Correct 4 ms 15000 KB Output is correct
19 Correct 3 ms 14940 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 3 ms 14940 KB Output is correct
22 Correct 3 ms 14940 KB Output is correct
23 Correct 4 ms 14940 KB Output is correct
24 Correct 3 ms 14940 KB Output is correct
25 Correct 3 ms 14936 KB Output is correct
26 Correct 5 ms 14940 KB Output is correct
27 Correct 4 ms 14940 KB Output is correct
28 Correct 4 ms 14940 KB Output is correct
29 Correct 3 ms 14940 KB Output is correct
30 Correct 342 ms 46968 KB Output is correct
31 Correct 468 ms 45612 KB Output is correct
32 Correct 314 ms 58448 KB Output is correct
33 Correct 434 ms 46820 KB Output is correct
34 Correct 454 ms 45432 KB Output is correct
35 Correct 447 ms 45968 KB Output is correct
36 Correct 387 ms 46280 KB Output is correct
37 Correct 319 ms 66228 KB Output is correct
38 Correct 433 ms 63780 KB Output is correct
39 Correct 291 ms 46660 KB Output is correct
40 Correct 413 ms 45688 KB Output is correct
41 Correct 276 ms 45496 KB Output is correct
42 Correct 353 ms 46056 KB Output is correct
43 Correct 377 ms 45272 KB Output is correct
44 Correct 388 ms 45444 KB Output is correct
45 Correct 418 ms 45504 KB Output is correct
46 Correct 3 ms 14936 KB Output is correct
47 Correct 4 ms 14788 KB Output is correct
48 Correct 4 ms 14940 KB Output is correct
49 Correct 3 ms 14784 KB Output is correct
50 Correct 4 ms 14940 KB Output is correct
51 Correct 4 ms 14940 KB Output is correct
52 Correct 346 ms 46724 KB Output is correct
53 Correct 543 ms 45468 KB Output is correct
54 Correct 424 ms 64772 KB Output is correct
55 Correct 388 ms 46036 KB Output is correct
56 Correct 495 ms 45944 KB Output is correct
57 Correct 504 ms 46168 KB Output is correct
58 Correct 342 ms 45492 KB Output is correct
59 Correct 337 ms 60164 KB Output is correct
60 Correct 387 ms 63408 KB Output is correct
61 Correct 374 ms 46924 KB Output is correct
62 Correct 607 ms 45584 KB Output is correct
63 Correct 4 ms 14936 KB Output is correct
64 Correct 5 ms 14940 KB Output is correct
65 Correct 5 ms 14940 KB Output is correct
66 Correct 4 ms 14936 KB Output is correct
67 Correct 3 ms 14940 KB Output is correct
68 Correct 3 ms 14940 KB Output is correct
69 Correct 4 ms 14936 KB Output is correct
70 Correct 4 ms 14940 KB Output is correct
71 Correct 4 ms 14940 KB Output is correct
72 Correct 3 ms 14936 KB Output is correct
73 Correct 3 ms 15192 KB Output is correct
74 Correct 4 ms 14940 KB Output is correct
75 Correct 4 ms 14940 KB Output is correct
76 Correct 4 ms 14940 KB Output is correct
77 Correct 3 ms 14940 KB Output is correct
78 Correct 3 ms 14940 KB Output is correct
79 Correct 453 ms 63596 KB Output is correct
80 Correct 1166 ms 58896 KB Output is correct
81 Correct 606 ms 59668 KB Output is correct
82 Correct 1811 ms 43976 KB Output is correct
83 Correct 1202 ms 43624 KB Output is correct
84 Correct 703 ms 44424 KB Output is correct
85 Correct 322 ms 43540 KB Output is correct
86 Correct 444 ms 57388 KB Output is correct
87 Correct 1106 ms 62024 KB Output is correct
88 Correct 913 ms 46608 KB Output is correct
89 Execution timed out 4101 ms 46080 KB Time limit exceeded
90 Halted 0 ms 0 KB -