답안 #312510

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
312510 2020-10-13T15:16:48 Z mosiashvililuka Birthday gift (IZhO18_treearray) C++14
100 / 100
1506 ms 84868 KB
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,tes,t,f[200009],lf[200009],rg[200009],tim,msh[200009][20],tp,pas1,pas2;
vector <int> v[200009];
set <int> s[200009],ss[200009];
set <int>::iterator it;
void dfs(int q, int w){
	tim++;
	lf[q]=rg[q]=tim;
	msh[q][0]=w;
	for(int h=1; h<=18; h++){
		msh[q][h]=msh[msh[q][h-1]][h-1];
	}
	for(vector <int>::iterator it=v[q].begin(); it!=v[q].end(); it++){
		if((*it)==w) continue;
		dfs((*it),q);
		if(rg[q]<rg[(*it)]) rg[q]=rg[(*it)];
	}
}
bool anc(int q, int w){
	if(lf[q]<=lf[w]&&rg[q]>=rg[w]) return 1; else return 0;
}
int lca(int q, int w){
	if(anc(q,w)) return q;
	if(anc(w,q)) return w;
	for(int h=18; h>=0; h--){
		if(msh[q][h]!=0&&anc(msh[q][h],w)==0) q=msh[q][h];
	}
	return msh[q][0];
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a>>b>>tes;
	for(i=1; i<a; i++){
		cin>>c>>d;
		v[c].push_back(d);
		v[d].push_back(c);
	}
	dfs(1,0);
	for(i=1; i<=b; i++){
		cin>>f[i];
		ss[f[i]].insert(i);
	}
	for(i=1; i<b; i++){
		s[lca(f[i],f[i+1])].insert(i);
	}
	for(t=1; t<=tes; t++){
		cin>>tp;
		if(tp==1){
			cin>>c>>d;
			ss[f[c]].erase(ss[f[c]].lower_bound(c));
			if(c!=1){
				zx=lca(f[c-1],f[c]);
				s[zx].erase(s[zx].lower_bound(c-1));
			}
			if(c!=b){
				zx=lca(f[c],f[c+1]);
				s[zx].erase(s[zx].lower_bound(c));
			}
			f[c]=d;
			ss[f[c]].insert(c);
			if(c!=1){
				zx=lca(f[c-1],f[c]);
				s[zx].insert(c-1);
			}
			if(c!=b){
				zx=lca(f[c],f[c+1]);
				s[zx].insert(c);
			}
		}else{
			cin>>c>>d>>e;
			it=ss[e].lower_bound(c);
			pas1=pas2=-1;
			if(it!=ss[e].end()){
				if((*it)<=d){
					pas1=pas2=(*it);
				}
			}
			it=s[e].lower_bound(c);
			if(it!=s[e].end()){
				if((*it)<d){
					pas1=(*it);
					pas2=(*it)+1;
				}
			}
			cout<<pas1<<" "<<pas2<<endl;
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB n=5
2 Correct 16 ms 23808 KB n=100
3 Correct 16 ms 23808 KB n=100
4 Correct 16 ms 23808 KB n=100
5 Correct 16 ms 23808 KB n=100
6 Correct 18 ms 23808 KB n=100
7 Correct 16 ms 23808 KB n=100
8 Correct 16 ms 23808 KB n=100
9 Correct 17 ms 23808 KB n=100
10 Correct 18 ms 23808 KB n=100
11 Correct 16 ms 23808 KB n=100
12 Correct 18 ms 23808 KB n=100
13 Correct 17 ms 23808 KB n=100
14 Correct 16 ms 23808 KB n=100
15 Correct 16 ms 23808 KB n=100
16 Correct 16 ms 23808 KB n=100
17 Correct 16 ms 23936 KB n=100
18 Correct 16 ms 23808 KB n=100
19 Correct 16 ms 23808 KB n=100
20 Correct 17 ms 23808 KB n=100
21 Correct 16 ms 23808 KB n=100
22 Correct 16 ms 23808 KB n=100
23 Correct 17 ms 23808 KB n=100
24 Correct 16 ms 23808 KB n=100
25 Correct 16 ms 23808 KB n=100
26 Correct 17 ms 23808 KB n=12
27 Correct 16 ms 23936 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB n=5
2 Correct 16 ms 23808 KB n=100
3 Correct 16 ms 23808 KB n=100
4 Correct 16 ms 23808 KB n=100
5 Correct 16 ms 23808 KB n=100
6 Correct 18 ms 23808 KB n=100
7 Correct 16 ms 23808 KB n=100
8 Correct 16 ms 23808 KB n=100
9 Correct 17 ms 23808 KB n=100
10 Correct 18 ms 23808 KB n=100
11 Correct 16 ms 23808 KB n=100
12 Correct 18 ms 23808 KB n=100
13 Correct 17 ms 23808 KB n=100
14 Correct 16 ms 23808 KB n=100
15 Correct 16 ms 23808 KB n=100
16 Correct 16 ms 23808 KB n=100
17 Correct 16 ms 23936 KB n=100
18 Correct 16 ms 23808 KB n=100
19 Correct 16 ms 23808 KB n=100
20 Correct 17 ms 23808 KB n=100
21 Correct 16 ms 23808 KB n=100
22 Correct 16 ms 23808 KB n=100
23 Correct 17 ms 23808 KB n=100
24 Correct 16 ms 23808 KB n=100
25 Correct 16 ms 23808 KB n=100
26 Correct 17 ms 23808 KB n=12
27 Correct 16 ms 23936 KB n=100
28 Correct 18 ms 23936 KB n=500
29 Correct 19 ms 23936 KB n=500
30 Correct 18 ms 24064 KB n=500
31 Correct 18 ms 23936 KB n=500
32 Correct 20 ms 23936 KB n=500
33 Correct 18 ms 23936 KB n=500
34 Correct 18 ms 23936 KB n=500
35 Correct 18 ms 23936 KB n=500
36 Correct 18 ms 23936 KB n=500
37 Correct 18 ms 24016 KB n=500
38 Correct 18 ms 23936 KB n=500
39 Correct 18 ms 23936 KB n=500
40 Correct 18 ms 23936 KB n=500
41 Correct 18 ms 23936 KB n=500
42 Correct 18 ms 23936 KB n=500
43 Correct 18 ms 23936 KB n=500
44 Correct 17 ms 23936 KB n=500
45 Correct 18 ms 23936 KB n=500
46 Correct 18 ms 23936 KB n=500
47 Correct 18 ms 24064 KB n=500
48 Correct 19 ms 23936 KB n=500
49 Correct 18 ms 23936 KB n=500
50 Correct 18 ms 23936 KB n=500
51 Correct 18 ms 23936 KB n=500
52 Correct 18 ms 23936 KB n=500
53 Correct 18 ms 23936 KB n=500
54 Correct 18 ms 23936 KB n=500
55 Correct 17 ms 23936 KB n=278
56 Correct 18 ms 23936 KB n=500
57 Correct 18 ms 23928 KB n=500
58 Correct 18 ms 23936 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB n=5
2 Correct 16 ms 23808 KB n=100
3 Correct 16 ms 23808 KB n=100
4 Correct 16 ms 23808 KB n=100
5 Correct 16 ms 23808 KB n=100
6 Correct 18 ms 23808 KB n=100
7 Correct 16 ms 23808 KB n=100
8 Correct 16 ms 23808 KB n=100
9 Correct 17 ms 23808 KB n=100
10 Correct 18 ms 23808 KB n=100
11 Correct 16 ms 23808 KB n=100
12 Correct 18 ms 23808 KB n=100
13 Correct 17 ms 23808 KB n=100
14 Correct 16 ms 23808 KB n=100
15 Correct 16 ms 23808 KB n=100
16 Correct 16 ms 23808 KB n=100
17 Correct 16 ms 23936 KB n=100
18 Correct 16 ms 23808 KB n=100
19 Correct 16 ms 23808 KB n=100
20 Correct 17 ms 23808 KB n=100
21 Correct 16 ms 23808 KB n=100
22 Correct 16 ms 23808 KB n=100
23 Correct 17 ms 23808 KB n=100
24 Correct 16 ms 23808 KB n=100
25 Correct 16 ms 23808 KB n=100
26 Correct 17 ms 23808 KB n=12
27 Correct 16 ms 23936 KB n=100
28 Correct 18 ms 23936 KB n=500
29 Correct 19 ms 23936 KB n=500
30 Correct 18 ms 24064 KB n=500
31 Correct 18 ms 23936 KB n=500
32 Correct 20 ms 23936 KB n=500
33 Correct 18 ms 23936 KB n=500
34 Correct 18 ms 23936 KB n=500
35 Correct 18 ms 23936 KB n=500
36 Correct 18 ms 23936 KB n=500
37 Correct 18 ms 24016 KB n=500
38 Correct 18 ms 23936 KB n=500
39 Correct 18 ms 23936 KB n=500
40 Correct 18 ms 23936 KB n=500
41 Correct 18 ms 23936 KB n=500
42 Correct 18 ms 23936 KB n=500
43 Correct 18 ms 23936 KB n=500
44 Correct 17 ms 23936 KB n=500
45 Correct 18 ms 23936 KB n=500
46 Correct 18 ms 23936 KB n=500
47 Correct 18 ms 24064 KB n=500
48 Correct 19 ms 23936 KB n=500
49 Correct 18 ms 23936 KB n=500
50 Correct 18 ms 23936 KB n=500
51 Correct 18 ms 23936 KB n=500
52 Correct 18 ms 23936 KB n=500
53 Correct 18 ms 23936 KB n=500
54 Correct 18 ms 23936 KB n=500
55 Correct 17 ms 23936 KB n=278
56 Correct 18 ms 23936 KB n=500
57 Correct 18 ms 23928 KB n=500
58 Correct 18 ms 23936 KB n=500
59 Correct 23 ms 24320 KB n=2000
60 Correct 22 ms 24448 KB n=2000
61 Correct 22 ms 24448 KB n=2000
62 Correct 27 ms 24424 KB n=2000
63 Correct 22 ms 24320 KB n=2000
64 Correct 23 ms 24448 KB n=2000
65 Correct 22 ms 24320 KB n=2000
66 Correct 22 ms 24448 KB n=2000
67 Correct 22 ms 24312 KB n=2000
68 Correct 22 ms 24448 KB n=2000
69 Correct 23 ms 24320 KB n=2000
70 Correct 24 ms 24320 KB n=2000
71 Correct 23 ms 24320 KB n=2000
72 Correct 23 ms 24352 KB n=2000
73 Correct 23 ms 24320 KB n=2000
74 Correct 23 ms 24448 KB n=1844
75 Correct 24 ms 24320 KB n=2000
76 Correct 22 ms 24320 KB n=2000
77 Correct 23 ms 24320 KB n=2000
78 Correct 22 ms 24312 KB n=2000
79 Correct 22 ms 24448 KB n=2000
80 Correct 22 ms 24440 KB n=2000
81 Correct 22 ms 24448 KB n=2000
82 Correct 22 ms 24312 KB n=2000
83 Correct 22 ms 24448 KB n=2000
84 Correct 22 ms 24320 KB n=2000
85 Correct 23 ms 24448 KB n=2000
86 Correct 22 ms 24320 KB n=2000
87 Correct 22 ms 24320 KB n=2000
88 Correct 22 ms 24448 KB n=2000
89 Correct 21 ms 24448 KB n=2000
90 Correct 22 ms 24440 KB n=2000
91 Correct 23 ms 24320 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB n=5
2 Correct 16 ms 23808 KB n=100
3 Correct 16 ms 23808 KB n=100
4 Correct 16 ms 23808 KB n=100
5 Correct 16 ms 23808 KB n=100
6 Correct 18 ms 23808 KB n=100
7 Correct 16 ms 23808 KB n=100
8 Correct 16 ms 23808 KB n=100
9 Correct 17 ms 23808 KB n=100
10 Correct 18 ms 23808 KB n=100
11 Correct 16 ms 23808 KB n=100
12 Correct 18 ms 23808 KB n=100
13 Correct 17 ms 23808 KB n=100
14 Correct 16 ms 23808 KB n=100
15 Correct 16 ms 23808 KB n=100
16 Correct 16 ms 23808 KB n=100
17 Correct 16 ms 23936 KB n=100
18 Correct 16 ms 23808 KB n=100
19 Correct 16 ms 23808 KB n=100
20 Correct 17 ms 23808 KB n=100
21 Correct 16 ms 23808 KB n=100
22 Correct 16 ms 23808 KB n=100
23 Correct 17 ms 23808 KB n=100
24 Correct 16 ms 23808 KB n=100
25 Correct 16 ms 23808 KB n=100
26 Correct 17 ms 23808 KB n=12
27 Correct 16 ms 23936 KB n=100
28 Correct 18 ms 23936 KB n=500
29 Correct 19 ms 23936 KB n=500
30 Correct 18 ms 24064 KB n=500
31 Correct 18 ms 23936 KB n=500
32 Correct 20 ms 23936 KB n=500
33 Correct 18 ms 23936 KB n=500
34 Correct 18 ms 23936 KB n=500
35 Correct 18 ms 23936 KB n=500
36 Correct 18 ms 23936 KB n=500
37 Correct 18 ms 24016 KB n=500
38 Correct 18 ms 23936 KB n=500
39 Correct 18 ms 23936 KB n=500
40 Correct 18 ms 23936 KB n=500
41 Correct 18 ms 23936 KB n=500
42 Correct 18 ms 23936 KB n=500
43 Correct 18 ms 23936 KB n=500
44 Correct 17 ms 23936 KB n=500
45 Correct 18 ms 23936 KB n=500
46 Correct 18 ms 23936 KB n=500
47 Correct 18 ms 24064 KB n=500
48 Correct 19 ms 23936 KB n=500
49 Correct 18 ms 23936 KB n=500
50 Correct 18 ms 23936 KB n=500
51 Correct 18 ms 23936 KB n=500
52 Correct 18 ms 23936 KB n=500
53 Correct 18 ms 23936 KB n=500
54 Correct 18 ms 23936 KB n=500
55 Correct 17 ms 23936 KB n=278
56 Correct 18 ms 23936 KB n=500
57 Correct 18 ms 23928 KB n=500
58 Correct 18 ms 23936 KB n=500
59 Correct 23 ms 24320 KB n=2000
60 Correct 22 ms 24448 KB n=2000
61 Correct 22 ms 24448 KB n=2000
62 Correct 27 ms 24424 KB n=2000
63 Correct 22 ms 24320 KB n=2000
64 Correct 23 ms 24448 KB n=2000
65 Correct 22 ms 24320 KB n=2000
66 Correct 22 ms 24448 KB n=2000
67 Correct 22 ms 24312 KB n=2000
68 Correct 22 ms 24448 KB n=2000
69 Correct 23 ms 24320 KB n=2000
70 Correct 24 ms 24320 KB n=2000
71 Correct 23 ms 24320 KB n=2000
72 Correct 23 ms 24352 KB n=2000
73 Correct 23 ms 24320 KB n=2000
74 Correct 23 ms 24448 KB n=1844
75 Correct 24 ms 24320 KB n=2000
76 Correct 22 ms 24320 KB n=2000
77 Correct 23 ms 24320 KB n=2000
78 Correct 22 ms 24312 KB n=2000
79 Correct 22 ms 24448 KB n=2000
80 Correct 22 ms 24440 KB n=2000
81 Correct 22 ms 24448 KB n=2000
82 Correct 22 ms 24312 KB n=2000
83 Correct 22 ms 24448 KB n=2000
84 Correct 22 ms 24320 KB n=2000
85 Correct 23 ms 24448 KB n=2000
86 Correct 22 ms 24320 KB n=2000
87 Correct 22 ms 24320 KB n=2000
88 Correct 22 ms 24448 KB n=2000
89 Correct 21 ms 24448 KB n=2000
90 Correct 22 ms 24440 KB n=2000
91 Correct 23 ms 24320 KB n=2000
92 Correct 1064 ms 75420 KB n=200000
93 Correct 1186 ms 80248 KB n=200000
94 Correct 957 ms 83576 KB n=200000
95 Correct 1042 ms 75176 KB n=200000
96 Correct 1044 ms 75240 KB n=200000
97 Correct 1292 ms 79480 KB n=200000
98 Correct 1054 ms 75240 KB n=200000
99 Correct 1238 ms 75376 KB n=200000
100 Correct 1069 ms 75248 KB n=200000
101 Correct 892 ms 84868 KB n=200000
102 Correct 917 ms 76408 KB n=200000
103 Correct 906 ms 76408 KB n=200000
104 Correct 910 ms 76408 KB n=200000
105 Correct 924 ms 76792 KB n=200000
106 Correct 922 ms 76792 KB n=200000
107 Correct 922 ms 76920 KB n=200000
108 Correct 1116 ms 75476 KB n=200000
109 Correct 1119 ms 75512 KB n=200000
110 Correct 1121 ms 75384 KB n=200000
111 Correct 1104 ms 74864 KB n=200000
112 Correct 939 ms 84008 KB n=200000
113 Correct 1259 ms 79480 KB n=200000
114 Correct 1096 ms 74988 KB n=200000
115 Correct 1506 ms 77688 KB n=200000
116 Correct 996 ms 75368 KB n=200000
117 Correct 896 ms 84344 KB n=200000
118 Correct 1356 ms 78520 KB n=200000
119 Correct 999 ms 75472 KB n=200000
120 Correct 828 ms 83832 KB n=200000
121 Correct 831 ms 84088 KB n=200000
122 Correct 835 ms 84216 KB n=200000
123 Correct 929 ms 76792 KB n=200000
124 Correct 293 ms 38904 KB n=25264