답안 #888983

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888983 2023-12-18T14:30:18 Z amirhoseinfar1385 Sprinkler (JOI22_sprinkler) C++17
41 / 100
4000 ms 56544 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;
			if(d>40){
				assert(0);
			}
			upd(u,d,w); 
		}
		else{
			int u;
			cin>>u;
			solve(u);
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 25392 KB Output is correct
2 Correct 14 ms 25460 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 25436 KB Output is correct
8 Correct 14 ms 25576 KB Output is correct
9 Correct 14 ms 25428 KB Output is correct
10 Correct 14 ms 25436 KB Output is correct
11 Correct 15 ms 25436 KB Output is correct
12 Correct 15 ms 25280 KB Output is correct
13 Correct 14 ms 25436 KB Output is correct
14 Correct 14 ms 25436 KB Output is correct
15 Correct 14 ms 25340 KB Output is correct
16 Correct 16 ms 25436 KB Output is correct
17 Correct 14 ms 25400 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 25436 KB Output is correct
21 Correct 14 ms 25312 KB Output is correct
22 Correct 14 ms 25944 KB Output is correct
23 Correct 14 ms 25516 KB Output is correct
24 Correct 14 ms 25400 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 25432 KB Output is correct
28 Correct 14 ms 25436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 25436 KB Output is correct
2 Correct 296 ms 42068 KB Output is correct
3 Correct 467 ms 39192 KB Output is correct
4 Correct 296 ms 48720 KB Output is correct
5 Correct 349 ms 40804 KB Output is correct
6 Correct 409 ms 40252 KB Output is correct
7 Correct 425 ms 40000 KB Output is correct
8 Correct 367 ms 40284 KB Output is correct
9 Correct 314 ms 56544 KB Output is correct
10 Correct 351 ms 51900 KB Output is correct
11 Correct 293 ms 41940 KB Output is correct
12 Correct 438 ms 39152 KB Output is correct
13 Correct 342 ms 39160 KB Output is correct
14 Correct 399 ms 39704 KB Output is correct
15 Correct 388 ms 39196 KB Output is correct
16 Correct 413 ms 39232 KB Output is correct
17 Correct 430 ms 39312 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 25436 KB Output is correct
21 Correct 14 ms 25436 KB Output is correct
22 Correct 14 ms 25308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 25436 KB Output is correct
2 Correct 296 ms 42068 KB Output is correct
3 Correct 467 ms 39192 KB Output is correct
4 Correct 296 ms 48720 KB Output is correct
5 Correct 349 ms 40804 KB Output is correct
6 Correct 409 ms 40252 KB Output is correct
7 Correct 425 ms 40000 KB Output is correct
8 Correct 367 ms 40284 KB Output is correct
9 Correct 314 ms 56544 KB Output is correct
10 Correct 351 ms 51900 KB Output is correct
11 Correct 293 ms 41940 KB Output is correct
12 Correct 438 ms 39152 KB Output is correct
13 Correct 342 ms 39160 KB Output is correct
14 Correct 399 ms 39704 KB Output is correct
15 Correct 388 ms 39196 KB Output is correct
16 Correct 413 ms 39232 KB Output is correct
17 Correct 430 ms 39312 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 25436 KB Output is correct
21 Correct 14 ms 25436 KB Output is correct
22 Correct 14 ms 25308 KB Output is correct
23 Correct 14 ms 25508 KB Output is correct
24 Correct 336 ms 42060 KB Output is correct
25 Correct 569 ms 38900 KB Output is correct
26 Correct 326 ms 54100 KB Output is correct
27 Correct 369 ms 40552 KB Output is correct
28 Correct 483 ms 40364 KB Output is correct
29 Correct 473 ms 40708 KB Output is correct
30 Correct 356 ms 40252 KB Output is correct
31 Correct 302 ms 51024 KB Output is correct
32 Correct 360 ms 51952 KB Output is correct
33 Correct 302 ms 42068 KB Output is correct
34 Correct 576 ms 38768 KB Output is correct
35 Correct 14 ms 25432 KB Output is correct
36 Correct 14 ms 25436 KB Output is correct
37 Correct 16 ms 25692 KB Output is correct
38 Correct 14 ms 25432 KB Output is correct
39 Correct 14 ms 25468 KB Output is correct
40 Correct 14 ms 25432 KB Output is correct
41 Correct 14 ms 25436 KB Output is correct
42 Correct 14 ms 25364 KB Output is correct
43 Correct 14 ms 25436 KB Output is correct
44 Correct 14 ms 25368 KB Output is correct
45 Correct 14 ms 25436 KB Output is correct
46 Correct 14 ms 25384 KB Output is correct
47 Correct 14 ms 25516 KB Output is correct
48 Correct 14 ms 25520 KB Output is correct
49 Correct 14 ms 25436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 25436 KB Output is correct
2 Correct 393 ms 53452 KB Output is correct
3 Correct 970 ms 48720 KB Output is correct
4 Correct 505 ms 50000 KB Output is correct
5 Correct 1780 ms 38948 KB Output is correct
6 Correct 1216 ms 38560 KB Output is correct
7 Correct 823 ms 39496 KB Output is correct
8 Correct 325 ms 38460 KB Output is correct
9 Correct 346 ms 48444 KB Output is correct
10 Correct 1195 ms 51356 KB Output is correct
11 Correct 903 ms 39420 KB Output is correct
12 Execution timed out 4050 ms 38668 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 25436 KB Output is correct
2 Correct 382 ms 50260 KB Output is correct
3 Correct 1071 ms 44640 KB Output is correct
4 Correct 478 ms 47700 KB Output is correct
5 Correct 1698 ms 40700 KB Output is correct
6 Correct 1169 ms 40456 KB Output is correct
7 Correct 834 ms 39652 KB Output is correct
8 Correct 340 ms 39816 KB Output is correct
9 Correct 382 ms 55120 KB Output is correct
10 Correct 876 ms 52320 KB Output is correct
11 Correct 836 ms 41904 KB Output is correct
12 Execution timed out 4046 ms 39180 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 25392 KB Output is correct
2 Correct 14 ms 25460 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 25436 KB Output is correct
8 Correct 14 ms 25576 KB Output is correct
9 Correct 14 ms 25428 KB Output is correct
10 Correct 14 ms 25436 KB Output is correct
11 Correct 15 ms 25436 KB Output is correct
12 Correct 15 ms 25280 KB Output is correct
13 Correct 14 ms 25436 KB Output is correct
14 Correct 14 ms 25436 KB Output is correct
15 Correct 14 ms 25340 KB Output is correct
16 Correct 16 ms 25436 KB Output is correct
17 Correct 14 ms 25400 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 25436 KB Output is correct
21 Correct 14 ms 25312 KB Output is correct
22 Correct 14 ms 25944 KB Output is correct
23 Correct 14 ms 25516 KB Output is correct
24 Correct 14 ms 25400 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 25432 KB Output is correct
28 Correct 14 ms 25436 KB Output is correct
29 Correct 13 ms 25436 KB Output is correct
30 Correct 296 ms 42068 KB Output is correct
31 Correct 467 ms 39192 KB Output is correct
32 Correct 296 ms 48720 KB Output is correct
33 Correct 349 ms 40804 KB Output is correct
34 Correct 409 ms 40252 KB Output is correct
35 Correct 425 ms 40000 KB Output is correct
36 Correct 367 ms 40284 KB Output is correct
37 Correct 314 ms 56544 KB Output is correct
38 Correct 351 ms 51900 KB Output is correct
39 Correct 293 ms 41940 KB Output is correct
40 Correct 438 ms 39152 KB Output is correct
41 Correct 342 ms 39160 KB Output is correct
42 Correct 399 ms 39704 KB Output is correct
43 Correct 388 ms 39196 KB Output is correct
44 Correct 413 ms 39232 KB Output is correct
45 Correct 430 ms 39312 KB Output is correct
46 Correct 14 ms 25432 KB Output is correct
47 Correct 14 ms 25436 KB Output is correct
48 Correct 14 ms 25436 KB Output is correct
49 Correct 14 ms 25436 KB Output is correct
50 Correct 14 ms 25308 KB Output is correct
51 Correct 14 ms 25508 KB Output is correct
52 Correct 336 ms 42060 KB Output is correct
53 Correct 569 ms 38900 KB Output is correct
54 Correct 326 ms 54100 KB Output is correct
55 Correct 369 ms 40552 KB Output is correct
56 Correct 483 ms 40364 KB Output is correct
57 Correct 473 ms 40708 KB Output is correct
58 Correct 356 ms 40252 KB Output is correct
59 Correct 302 ms 51024 KB Output is correct
60 Correct 360 ms 51952 KB Output is correct
61 Correct 302 ms 42068 KB Output is correct
62 Correct 576 ms 38768 KB Output is correct
63 Correct 14 ms 25432 KB Output is correct
64 Correct 14 ms 25436 KB Output is correct
65 Correct 16 ms 25692 KB Output is correct
66 Correct 14 ms 25432 KB Output is correct
67 Correct 14 ms 25468 KB Output is correct
68 Correct 14 ms 25432 KB Output is correct
69 Correct 14 ms 25436 KB Output is correct
70 Correct 14 ms 25364 KB Output is correct
71 Correct 14 ms 25436 KB Output is correct
72 Correct 14 ms 25368 KB Output is correct
73 Correct 14 ms 25436 KB Output is correct
74 Correct 14 ms 25384 KB Output is correct
75 Correct 14 ms 25516 KB Output is correct
76 Correct 14 ms 25520 KB Output is correct
77 Correct 14 ms 25436 KB Output is correct
78 Correct 13 ms 25436 KB Output is correct
79 Correct 393 ms 53452 KB Output is correct
80 Correct 970 ms 48720 KB Output is correct
81 Correct 505 ms 50000 KB Output is correct
82 Correct 1780 ms 38948 KB Output is correct
83 Correct 1216 ms 38560 KB Output is correct
84 Correct 823 ms 39496 KB Output is correct
85 Correct 325 ms 38460 KB Output is correct
86 Correct 346 ms 48444 KB Output is correct
87 Correct 1195 ms 51356 KB Output is correct
88 Correct 903 ms 39420 KB Output is correct
89 Execution timed out 4050 ms 38668 KB Time limit exceeded
90 Halted 0 ms 0 KB -