Submission #93954

# Submission time Handle Problem Language Result Execution time Memory
93954 2019-01-13T17:43:00 Z mrtsima22 Birthday gift (IZhO18_treearray) C++17
56 / 100
126 ms 47096 KB
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int n,k,q,t_out[100003],p[100003][33];
vector<int>a[100003];
int ba[100003],t_in[100004],T,x;
set<int>s1[100003],s2[100003];
set<int>::iterator it1,it2;
bool is_it(int a,int b){
	if (t_in[a]<=t_in[b]&&t_out[b]<=t_out[a]){
		return true;
	}else{
		return false;
	}
}
void go(int s,int parent){
	t_in[s]=++T;
	p[s][0]=parent;
	int j=s;	
	for (int i=1;i<=30;i++){
		p[j][i]=p[p[j][i-1]][i-1];
	}
	for(int i=0;i<(int)a[s].size();i++){
		if(a[s][i]==parent)continue;
		go(a[s][i],s);
	}
	t_out[s]=++T;
}
int lca(int a,int b){
	if(t_in[a]>t_in[b]){
		swap(a,b);
	}
	if(is_it(a,b)){
		return a;
	}
	if(is_it(b,a)){
		return b;
	}
	for(int i=30;i>=0;i--){
		if(p[a][i]==0)continue;
		if(is_it(p[a][i],b)==0){
			a=p[a][i];
		}
	}
	return p[a][0];
}
int u,v,tp;
int main() {ios_base::sync_with_stdio(false);
cin>>n>>k>>q;
for(int i=1;i<n;i++){
	cin>>v>>u;
	a[v].push_back(u);
	a[u].push_back(v);
}
for(int i=1;i<=k;i++){
	cin>>ba[i];
}

go(1,0);

for(int i=1;i<=k;i++){
	s2[ba[i]].insert(i);
}
for(int i=1;i<k;i++){
	s1[lca(ba[i],ba[i+1])].insert(i);
//	cout<<lca(ba[i],ba[i+1])<<endl;
}

while(q--){
	cin>>tp;
	if(tp==1){
		cin>>u>>v;
		if(u>1){
			s1[lca(ba[u-1],ba[u])].erase(u-1);
		}
		if(x<k){
			s1[lca(ba[u],ba[u+1])].erase(u);
		}
		s2[ba[u]].erase(u);
		ba[u]=v;
		if(u>1){
			s1[lca(ba[u-1],ba[u])].insert(u-1);
		}
		if(u<k){
			s1[lca(ba[u],ba[u+1])].insert(u);
		}
		s2[ba[u]].insert(u);
	}else{
		cin>>u>>v>>x;
		it1=s1[x].lower_bound(u);
		it2=s2[x].lower_bound(u);
		
		if(it2!=s2[x].end()&&(*it2)<=v){
			cout<<(*it2)<<" "<<(*it2)<<endl;
		}else{
			if(it1!=s1[x].end()){
				if((*it1)<v){
					cout<<(*it1)<<" "<<(*it1)+1<<endl;
				}
				else{
					cout<<-1<<" "<<-1<<endl;
				}
			}else
				cout<<-1<<" "<<-1<<endl;
		}
	}

}
return 0;
}
/*

5 4 4
 1 2
  3 1 
  3 4 
  5  3 
  4 5 
  2 3
    2 1
    3 1 
  1 3 5 
  2 3 4 5
   2 1 3 1


*/
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12152 KB n=5
2 Correct 10 ms 12152 KB n=100
3 Correct 10 ms 12152 KB n=100
4 Correct 10 ms 12152 KB n=100
5 Correct 10 ms 12152 KB n=100
6 Correct 42 ms 12152 KB n=100
7 Correct 10 ms 12152 KB n=100
8 Correct 10 ms 12152 KB n=100
9 Correct 10 ms 12152 KB n=100
10 Correct 10 ms 12152 KB n=100
11 Correct 10 ms 12152 KB n=100
12 Correct 11 ms 12112 KB n=100
13 Correct 10 ms 12152 KB n=100
14 Correct 10 ms 12152 KB n=100
15 Correct 10 ms 12152 KB n=100
16 Correct 10 ms 12152 KB n=100
17 Correct 10 ms 12152 KB n=100
18 Correct 10 ms 12152 KB n=100
19 Correct 12 ms 12152 KB n=100
20 Correct 24 ms 12152 KB n=100
21 Correct 10 ms 12152 KB n=100
22 Correct 10 ms 12152 KB n=100
23 Correct 10 ms 12152 KB n=100
24 Correct 10 ms 12152 KB n=100
25 Correct 10 ms 12152 KB n=100
26 Correct 10 ms 12024 KB n=12
27 Correct 11 ms 12152 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12152 KB n=5
2 Correct 10 ms 12152 KB n=100
3 Correct 10 ms 12152 KB n=100
4 Correct 10 ms 12152 KB n=100
5 Correct 10 ms 12152 KB n=100
6 Correct 42 ms 12152 KB n=100
7 Correct 10 ms 12152 KB n=100
8 Correct 10 ms 12152 KB n=100
9 Correct 10 ms 12152 KB n=100
10 Correct 10 ms 12152 KB n=100
11 Correct 10 ms 12152 KB n=100
12 Correct 11 ms 12112 KB n=100
13 Correct 10 ms 12152 KB n=100
14 Correct 10 ms 12152 KB n=100
15 Correct 10 ms 12152 KB n=100
16 Correct 10 ms 12152 KB n=100
17 Correct 10 ms 12152 KB n=100
18 Correct 10 ms 12152 KB n=100
19 Correct 12 ms 12152 KB n=100
20 Correct 24 ms 12152 KB n=100
21 Correct 10 ms 12152 KB n=100
22 Correct 10 ms 12152 KB n=100
23 Correct 10 ms 12152 KB n=100
24 Correct 10 ms 12152 KB n=100
25 Correct 10 ms 12152 KB n=100
26 Correct 10 ms 12024 KB n=12
27 Correct 11 ms 12152 KB n=100
28 Correct 13 ms 12280 KB n=500
29 Correct 11 ms 12280 KB n=500
30 Correct 11 ms 12280 KB n=500
31 Correct 11 ms 12280 KB n=500
32 Correct 11 ms 12280 KB n=500
33 Correct 11 ms 12280 KB n=500
34 Correct 11 ms 12280 KB n=500
35 Correct 13 ms 12280 KB n=500
36 Correct 11 ms 12280 KB n=500
37 Correct 11 ms 12280 KB n=500
38 Correct 13 ms 12280 KB n=500
39 Correct 13 ms 12156 KB n=500
40 Correct 12 ms 12280 KB n=500
41 Correct 11 ms 12280 KB n=500
42 Correct 11 ms 12280 KB n=500
43 Correct 11 ms 12280 KB n=500
44 Correct 11 ms 12280 KB n=500
45 Correct 11 ms 12280 KB n=500
46 Correct 11 ms 12280 KB n=500
47 Correct 11 ms 12280 KB n=500
48 Correct 11 ms 12156 KB n=500
49 Correct 13 ms 12280 KB n=500
50 Correct 13 ms 12284 KB n=500
51 Correct 13 ms 12280 KB n=500
52 Correct 13 ms 12280 KB n=500
53 Correct 13 ms 12280 KB n=500
54 Correct 11 ms 12536 KB n=500
55 Correct 10 ms 12156 KB n=278
56 Correct 11 ms 12408 KB n=500
57 Correct 11 ms 12280 KB n=500
58 Correct 11 ms 12280 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12152 KB n=5
2 Correct 10 ms 12152 KB n=100
3 Correct 10 ms 12152 KB n=100
4 Correct 10 ms 12152 KB n=100
5 Correct 10 ms 12152 KB n=100
6 Correct 42 ms 12152 KB n=100
7 Correct 10 ms 12152 KB n=100
8 Correct 10 ms 12152 KB n=100
9 Correct 10 ms 12152 KB n=100
10 Correct 10 ms 12152 KB n=100
11 Correct 10 ms 12152 KB n=100
12 Correct 11 ms 12112 KB n=100
13 Correct 10 ms 12152 KB n=100
14 Correct 10 ms 12152 KB n=100
15 Correct 10 ms 12152 KB n=100
16 Correct 10 ms 12152 KB n=100
17 Correct 10 ms 12152 KB n=100
18 Correct 10 ms 12152 KB n=100
19 Correct 12 ms 12152 KB n=100
20 Correct 24 ms 12152 KB n=100
21 Correct 10 ms 12152 KB n=100
22 Correct 10 ms 12152 KB n=100
23 Correct 10 ms 12152 KB n=100
24 Correct 10 ms 12152 KB n=100
25 Correct 10 ms 12152 KB n=100
26 Correct 10 ms 12024 KB n=12
27 Correct 11 ms 12152 KB n=100
28 Correct 13 ms 12280 KB n=500
29 Correct 11 ms 12280 KB n=500
30 Correct 11 ms 12280 KB n=500
31 Correct 11 ms 12280 KB n=500
32 Correct 11 ms 12280 KB n=500
33 Correct 11 ms 12280 KB n=500
34 Correct 11 ms 12280 KB n=500
35 Correct 13 ms 12280 KB n=500
36 Correct 11 ms 12280 KB n=500
37 Correct 11 ms 12280 KB n=500
38 Correct 13 ms 12280 KB n=500
39 Correct 13 ms 12156 KB n=500
40 Correct 12 ms 12280 KB n=500
41 Correct 11 ms 12280 KB n=500
42 Correct 11 ms 12280 KB n=500
43 Correct 11 ms 12280 KB n=500
44 Correct 11 ms 12280 KB n=500
45 Correct 11 ms 12280 KB n=500
46 Correct 11 ms 12280 KB n=500
47 Correct 11 ms 12280 KB n=500
48 Correct 11 ms 12156 KB n=500
49 Correct 13 ms 12280 KB n=500
50 Correct 13 ms 12284 KB n=500
51 Correct 13 ms 12280 KB n=500
52 Correct 13 ms 12280 KB n=500
53 Correct 13 ms 12280 KB n=500
54 Correct 11 ms 12536 KB n=500
55 Correct 10 ms 12156 KB n=278
56 Correct 11 ms 12408 KB n=500
57 Correct 11 ms 12280 KB n=500
58 Correct 11 ms 12280 KB n=500
59 Correct 16 ms 12664 KB n=2000
60 Correct 17 ms 12792 KB n=2000
61 Correct 16 ms 12776 KB n=2000
62 Correct 16 ms 12664 KB n=2000
63 Correct 17 ms 12792 KB n=2000
64 Correct 17 ms 12792 KB n=2000
65 Correct 17 ms 12664 KB n=2000
66 Correct 15 ms 12664 KB n=2000
67 Correct 16 ms 12664 KB n=2000
68 Correct 18 ms 12664 KB n=2000
69 Correct 16 ms 12664 KB n=2000
70 Correct 17 ms 12664 KB n=2000
71 Correct 17 ms 12664 KB n=2000
72 Correct 18 ms 12664 KB n=2000
73 Correct 18 ms 12664 KB n=2000
74 Correct 15 ms 12792 KB n=1844
75 Correct 16 ms 12664 KB n=2000
76 Correct 16 ms 12664 KB n=2000
77 Correct 18 ms 12664 KB n=2000
78 Correct 18 ms 12664 KB n=2000
79 Correct 18 ms 12664 KB n=2000
80 Correct 17 ms 12792 KB n=2000
81 Correct 18 ms 12664 KB n=2000
82 Correct 16 ms 12664 KB n=2000
83 Correct 17 ms 12792 KB n=2000
84 Correct 16 ms 12664 KB n=2000
85 Correct 16 ms 12664 KB n=2000
86 Correct 15 ms 12664 KB n=2000
87 Correct 15 ms 12664 KB n=2000
88 Correct 14 ms 12792 KB n=2000
89 Correct 15 ms 12792 KB n=2000
90 Correct 16 ms 12792 KB n=2000
91 Correct 18 ms 12708 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12152 KB n=5
2 Correct 10 ms 12152 KB n=100
3 Correct 10 ms 12152 KB n=100
4 Correct 10 ms 12152 KB n=100
5 Correct 10 ms 12152 KB n=100
6 Correct 42 ms 12152 KB n=100
7 Correct 10 ms 12152 KB n=100
8 Correct 10 ms 12152 KB n=100
9 Correct 10 ms 12152 KB n=100
10 Correct 10 ms 12152 KB n=100
11 Correct 10 ms 12152 KB n=100
12 Correct 11 ms 12112 KB n=100
13 Correct 10 ms 12152 KB n=100
14 Correct 10 ms 12152 KB n=100
15 Correct 10 ms 12152 KB n=100
16 Correct 10 ms 12152 KB n=100
17 Correct 10 ms 12152 KB n=100
18 Correct 10 ms 12152 KB n=100
19 Correct 12 ms 12152 KB n=100
20 Correct 24 ms 12152 KB n=100
21 Correct 10 ms 12152 KB n=100
22 Correct 10 ms 12152 KB n=100
23 Correct 10 ms 12152 KB n=100
24 Correct 10 ms 12152 KB n=100
25 Correct 10 ms 12152 KB n=100
26 Correct 10 ms 12024 KB n=12
27 Correct 11 ms 12152 KB n=100
28 Correct 13 ms 12280 KB n=500
29 Correct 11 ms 12280 KB n=500
30 Correct 11 ms 12280 KB n=500
31 Correct 11 ms 12280 KB n=500
32 Correct 11 ms 12280 KB n=500
33 Correct 11 ms 12280 KB n=500
34 Correct 11 ms 12280 KB n=500
35 Correct 13 ms 12280 KB n=500
36 Correct 11 ms 12280 KB n=500
37 Correct 11 ms 12280 KB n=500
38 Correct 13 ms 12280 KB n=500
39 Correct 13 ms 12156 KB n=500
40 Correct 12 ms 12280 KB n=500
41 Correct 11 ms 12280 KB n=500
42 Correct 11 ms 12280 KB n=500
43 Correct 11 ms 12280 KB n=500
44 Correct 11 ms 12280 KB n=500
45 Correct 11 ms 12280 KB n=500
46 Correct 11 ms 12280 KB n=500
47 Correct 11 ms 12280 KB n=500
48 Correct 11 ms 12156 KB n=500
49 Correct 13 ms 12280 KB n=500
50 Correct 13 ms 12284 KB n=500
51 Correct 13 ms 12280 KB n=500
52 Correct 13 ms 12280 KB n=500
53 Correct 13 ms 12280 KB n=500
54 Correct 11 ms 12536 KB n=500
55 Correct 10 ms 12156 KB n=278
56 Correct 11 ms 12408 KB n=500
57 Correct 11 ms 12280 KB n=500
58 Correct 11 ms 12280 KB n=500
59 Correct 16 ms 12664 KB n=2000
60 Correct 17 ms 12792 KB n=2000
61 Correct 16 ms 12776 KB n=2000
62 Correct 16 ms 12664 KB n=2000
63 Correct 17 ms 12792 KB n=2000
64 Correct 17 ms 12792 KB n=2000
65 Correct 17 ms 12664 KB n=2000
66 Correct 15 ms 12664 KB n=2000
67 Correct 16 ms 12664 KB n=2000
68 Correct 18 ms 12664 KB n=2000
69 Correct 16 ms 12664 KB n=2000
70 Correct 17 ms 12664 KB n=2000
71 Correct 17 ms 12664 KB n=2000
72 Correct 18 ms 12664 KB n=2000
73 Correct 18 ms 12664 KB n=2000
74 Correct 15 ms 12792 KB n=1844
75 Correct 16 ms 12664 KB n=2000
76 Correct 16 ms 12664 KB n=2000
77 Correct 18 ms 12664 KB n=2000
78 Correct 18 ms 12664 KB n=2000
79 Correct 18 ms 12664 KB n=2000
80 Correct 17 ms 12792 KB n=2000
81 Correct 18 ms 12664 KB n=2000
82 Correct 16 ms 12664 KB n=2000
83 Correct 17 ms 12792 KB n=2000
84 Correct 16 ms 12664 KB n=2000
85 Correct 16 ms 12664 KB n=2000
86 Correct 15 ms 12664 KB n=2000
87 Correct 15 ms 12664 KB n=2000
88 Correct 14 ms 12792 KB n=2000
89 Correct 15 ms 12792 KB n=2000
90 Correct 16 ms 12792 KB n=2000
91 Correct 18 ms 12708 KB n=2000
92 Runtime error 126 ms 47096 KB Execution killed with signal 11 (could be triggered by violating memory limits)
93 Halted 0 ms 0 KB -