Submission #888982

# Submission time Handle Problem Language Result Execution time Memory
888982 2023-12-18T14:29:30 Z amirhoseinfar1385 Sprinkler (JOI22_sprinkler) C++17
41 / 100
4000 ms 56572 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=200000+10;
vector<int>adj[maxn];
int q,high[maxn],n,mod,timea=0,part[maxn];
pair<int,int>stf[maxn];
struct segment{
	vector<long long>seg;
	int sz=0;
	void create(){
		while(__builtin_popcount(sz)!=1){
			sz++;
		}
		seg.resize(sz*2,1);
	}
	void add(int i,int l,int r,int tl,int tr,int w){
		if(l>r||l>tr||r<tl||tl>tr){
			return ;
		}
		if(l>=tl&&r<=tr){
			seg[i]*=w;
			seg[i]%=mod;
			return ;
		}
		int m=(l+r)>>1;
		add((i<<1),l,m,tl,tr,w);
		add((i<<1)^1,m+1,r,tl,tr,w);
		return ;
	}
	int pors(int i){
		if(i==0){
			return 1;
		}
		int ret=seg[i]*pors((i>>1))%mod;
		return ret;
	}
}seg[maxn];
vector<pair<int,int>>alll[maxn];

void pre(int u=1,int par=1){
	part[u]=par;
	timea++;
	stf[u].first=timea;
	alll[high[u]].push_back(make_pair(stf[u].first,u));
	for(auto x:adj[u]){
		if(x!=par){
			high[x]=high[u]+1;
			pre(x,u);
		}
	}
	stf[u].second=timea;
}

void upd(int u,int dis,int w){
	int z=0;
	int lev=high[u]+dis;
	while(lev>=0&&high[u]<=lev){
		if(lev<maxn){
			int l=lower_bound(alll[lev].begin(),alll[lev].end(),make_pair(stf[u].first,-1))-alll[lev].begin();
			int r=lower_bound(alll[lev].begin(),alll[lev].end(),make_pair(stf[u].second+1,-1))-alll[lev].begin();
			r--;
			seg[lev].add(1,0,seg[lev].sz-1,l,r,w);
		}
		if(z==1){
			u=part[u];
			lev--;
			z=0;
		}
		else{
			lev--;
			z=1;
		}
	}
}

void solve(int u){
	int ind=lower_bound(alll[high[u]].begin(),alll[high[u]].end(),make_pair(stf[u].first,u))-alll[high[u]].begin();
	cout<<seg[high[u]].pors(ind+seg[high[u]].sz)<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>mod;
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	pre(1);
	for(int i=0;i<maxn;i++){
		seg[i].sz=alll[i].size();
		seg[i].create();
	}
	for(int i=1;i<=n;i++){
		int d;
		cin>>d;
		upd(i,0,d);
	}
	cin>>q;
	for(int i=0;i<q;i++){
		int qq;
		cin>>qq;
		if(qq==1){
			int u,d,w;
			cin>>u>>d>>w;
			upd(u,d,w); 
		}
		else{
			int u;
			cin>>u;
			solve(u);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 25436 KB Output is correct
2 Correct 14 ms 25348 KB Output is correct
3 Correct 13 ms 25436 KB Output is correct
4 Correct 14 ms 25436 KB Output is correct
5 Correct 15 ms 25436 KB Output is correct
6 Correct 15 ms 25436 KB Output is correct
7 Correct 15 ms 25460 KB Output is correct
8 Correct 15 ms 25424 KB Output is correct
9 Correct 13 ms 25436 KB Output is correct
10 Correct 14 ms 25384 KB Output is correct
11 Correct 14 ms 25524 KB Output is correct
12 Correct 18 ms 25436 KB Output is correct
13 Correct 15 ms 25396 KB Output is correct
14 Correct 14 ms 25436 KB Output is correct
15 Correct 14 ms 25436 KB Output is correct
16 Correct 13 ms 25436 KB Output is correct
17 Correct 14 ms 25488 KB Output is correct
18 Correct 14 ms 25432 KB Output is correct
19 Correct 14 ms 25436 KB Output is correct
20 Correct 14 ms 25360 KB Output is correct
21 Correct 13 ms 25436 KB Output is correct
22 Correct 14 ms 25472 KB Output is correct
23 Correct 14 ms 25436 KB Output is correct
24 Correct 14 ms 25436 KB Output is correct
25 Correct 14 ms 25436 KB Output is correct
26 Correct 14 ms 25436 KB Output is correct
27 Correct 14 ms 25436 KB Output is correct
28 Correct 18 ms 25420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 25688 KB Output is correct
2 Correct 301 ms 42228 KB Output is correct
3 Correct 459 ms 39364 KB Output is correct
4 Correct 301 ms 48824 KB Output is correct
5 Correct 351 ms 41048 KB Output is correct
6 Correct 402 ms 40248 KB Output is correct
7 Correct 425 ms 40052 KB Output is correct
8 Correct 367 ms 40004 KB Output is correct
9 Correct 319 ms 56572 KB Output is correct
10 Correct 325 ms 51796 KB Output is correct
11 Correct 301 ms 42336 KB Output is correct
12 Correct 430 ms 38996 KB Output is correct
13 Correct 318 ms 39064 KB Output is correct
14 Correct 370 ms 39608 KB Output is correct
15 Correct 391 ms 39264 KB Output is correct
16 Correct 387 ms 39048 KB Output is correct
17 Correct 424 ms 39368 KB Output is correct
18 Correct 13 ms 25436 KB Output is correct
19 Correct 14 ms 25436 KB Output is correct
20 Correct 14 ms 25516 KB Output is correct
21 Correct 14 ms 25516 KB Output is correct
22 Correct 14 ms 25432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 25688 KB Output is correct
2 Correct 301 ms 42228 KB Output is correct
3 Correct 459 ms 39364 KB Output is correct
4 Correct 301 ms 48824 KB Output is correct
5 Correct 351 ms 41048 KB Output is correct
6 Correct 402 ms 40248 KB Output is correct
7 Correct 425 ms 40052 KB Output is correct
8 Correct 367 ms 40004 KB Output is correct
9 Correct 319 ms 56572 KB Output is correct
10 Correct 325 ms 51796 KB Output is correct
11 Correct 301 ms 42336 KB Output is correct
12 Correct 430 ms 38996 KB Output is correct
13 Correct 318 ms 39064 KB Output is correct
14 Correct 370 ms 39608 KB Output is correct
15 Correct 391 ms 39264 KB Output is correct
16 Correct 387 ms 39048 KB Output is correct
17 Correct 424 ms 39368 KB Output is correct
18 Correct 13 ms 25436 KB Output is correct
19 Correct 14 ms 25436 KB Output is correct
20 Correct 14 ms 25516 KB Output is correct
21 Correct 14 ms 25516 KB Output is correct
22 Correct 14 ms 25432 KB Output is correct
23 Correct 14 ms 25432 KB Output is correct
24 Correct 315 ms 41956 KB Output is correct
25 Correct 571 ms 39352 KB Output is correct
26 Correct 320 ms 54100 KB Output is correct
27 Correct 369 ms 41152 KB Output is correct
28 Correct 507 ms 40344 KB Output is correct
29 Correct 519 ms 40528 KB Output is correct
30 Correct 355 ms 40256 KB Output is correct
31 Correct 294 ms 50948 KB Output is correct
32 Correct 347 ms 52492 KB Output is correct
33 Correct 299 ms 42236 KB Output is correct
34 Correct 581 ms 38996 KB Output is correct
35 Correct 14 ms 25432 KB Output is correct
36 Correct 14 ms 25540 KB Output is correct
37 Correct 14 ms 25316 KB Output is correct
38 Correct 17 ms 25436 KB Output is correct
39 Correct 14 ms 25432 KB Output is correct
40 Correct 14 ms 25640 KB Output is correct
41 Correct 14 ms 25508 KB Output is correct
42 Correct 13 ms 25436 KB Output is correct
43 Correct 13 ms 25296 KB Output is correct
44 Correct 14 ms 25436 KB Output is correct
45 Correct 14 ms 25276 KB Output is correct
46 Correct 14 ms 25436 KB Output is correct
47 Correct 14 ms 25444 KB Output is correct
48 Correct 14 ms 25436 KB Output is correct
49 Correct 14 ms 25436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 25688 KB Output is correct
2 Correct 399 ms 53760 KB Output is correct
3 Correct 1000 ms 48756 KB Output is correct
4 Correct 485 ms 49856 KB Output is correct
5 Correct 1731 ms 38996 KB Output is correct
6 Correct 1187 ms 38656 KB Output is correct
7 Correct 755 ms 39248 KB Output is correct
8 Correct 326 ms 38580 KB Output is correct
9 Correct 361 ms 48532 KB Output is correct
10 Correct 928 ms 51552 KB Output is correct
11 Correct 820 ms 39776 KB Output is correct
12 Execution timed out 4045 ms 38868 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 25436 KB Output is correct
2 Correct 404 ms 50536 KB Output is correct
3 Correct 1008 ms 44872 KB Output is correct
4 Correct 575 ms 47952 KB Output is correct
5 Correct 1651 ms 40532 KB Output is correct
6 Correct 1133 ms 40560 KB Output is correct
7 Correct 814 ms 39760 KB Output is correct
8 Correct 345 ms 39800 KB Output is correct
9 Correct 386 ms 55444 KB Output is correct
10 Correct 961 ms 52304 KB Output is correct
11 Correct 808 ms 41896 KB Output is correct
12 Execution timed out 4035 ms 39368 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 25436 KB Output is correct
2 Correct 14 ms 25348 KB Output is correct
3 Correct 13 ms 25436 KB Output is correct
4 Correct 14 ms 25436 KB Output is correct
5 Correct 15 ms 25436 KB Output is correct
6 Correct 15 ms 25436 KB Output is correct
7 Correct 15 ms 25460 KB Output is correct
8 Correct 15 ms 25424 KB Output is correct
9 Correct 13 ms 25436 KB Output is correct
10 Correct 14 ms 25384 KB Output is correct
11 Correct 14 ms 25524 KB Output is correct
12 Correct 18 ms 25436 KB Output is correct
13 Correct 15 ms 25396 KB Output is correct
14 Correct 14 ms 25436 KB Output is correct
15 Correct 14 ms 25436 KB Output is correct
16 Correct 13 ms 25436 KB Output is correct
17 Correct 14 ms 25488 KB Output is correct
18 Correct 14 ms 25432 KB Output is correct
19 Correct 14 ms 25436 KB Output is correct
20 Correct 14 ms 25360 KB Output is correct
21 Correct 13 ms 25436 KB Output is correct
22 Correct 14 ms 25472 KB Output is correct
23 Correct 14 ms 25436 KB Output is correct
24 Correct 14 ms 25436 KB Output is correct
25 Correct 14 ms 25436 KB Output is correct
26 Correct 14 ms 25436 KB Output is correct
27 Correct 14 ms 25436 KB Output is correct
28 Correct 18 ms 25420 KB Output is correct
29 Correct 14 ms 25688 KB Output is correct
30 Correct 301 ms 42228 KB Output is correct
31 Correct 459 ms 39364 KB Output is correct
32 Correct 301 ms 48824 KB Output is correct
33 Correct 351 ms 41048 KB Output is correct
34 Correct 402 ms 40248 KB Output is correct
35 Correct 425 ms 40052 KB Output is correct
36 Correct 367 ms 40004 KB Output is correct
37 Correct 319 ms 56572 KB Output is correct
38 Correct 325 ms 51796 KB Output is correct
39 Correct 301 ms 42336 KB Output is correct
40 Correct 430 ms 38996 KB Output is correct
41 Correct 318 ms 39064 KB Output is correct
42 Correct 370 ms 39608 KB Output is correct
43 Correct 391 ms 39264 KB Output is correct
44 Correct 387 ms 39048 KB Output is correct
45 Correct 424 ms 39368 KB Output is correct
46 Correct 13 ms 25436 KB Output is correct
47 Correct 14 ms 25436 KB Output is correct
48 Correct 14 ms 25516 KB Output is correct
49 Correct 14 ms 25516 KB Output is correct
50 Correct 14 ms 25432 KB Output is correct
51 Correct 14 ms 25432 KB Output is correct
52 Correct 315 ms 41956 KB Output is correct
53 Correct 571 ms 39352 KB Output is correct
54 Correct 320 ms 54100 KB Output is correct
55 Correct 369 ms 41152 KB Output is correct
56 Correct 507 ms 40344 KB Output is correct
57 Correct 519 ms 40528 KB Output is correct
58 Correct 355 ms 40256 KB Output is correct
59 Correct 294 ms 50948 KB Output is correct
60 Correct 347 ms 52492 KB Output is correct
61 Correct 299 ms 42236 KB Output is correct
62 Correct 581 ms 38996 KB Output is correct
63 Correct 14 ms 25432 KB Output is correct
64 Correct 14 ms 25540 KB Output is correct
65 Correct 14 ms 25316 KB Output is correct
66 Correct 17 ms 25436 KB Output is correct
67 Correct 14 ms 25432 KB Output is correct
68 Correct 14 ms 25640 KB Output is correct
69 Correct 14 ms 25508 KB Output is correct
70 Correct 13 ms 25436 KB Output is correct
71 Correct 13 ms 25296 KB Output is correct
72 Correct 14 ms 25436 KB Output is correct
73 Correct 14 ms 25276 KB Output is correct
74 Correct 14 ms 25436 KB Output is correct
75 Correct 14 ms 25444 KB Output is correct
76 Correct 14 ms 25436 KB Output is correct
77 Correct 14 ms 25436 KB Output is correct
78 Correct 13 ms 25688 KB Output is correct
79 Correct 399 ms 53760 KB Output is correct
80 Correct 1000 ms 48756 KB Output is correct
81 Correct 485 ms 49856 KB Output is correct
82 Correct 1731 ms 38996 KB Output is correct
83 Correct 1187 ms 38656 KB Output is correct
84 Correct 755 ms 39248 KB Output is correct
85 Correct 326 ms 38580 KB Output is correct
86 Correct 361 ms 48532 KB Output is correct
87 Correct 928 ms 51552 KB Output is correct
88 Correct 820 ms 39776 KB Output is correct
89 Execution timed out 4045 ms 38868 KB Time limit exceeded
90 Halted 0 ms 0 KB -