Submission #90095

# Submission time Handle Problem Language Result Execution time Memory
90095 2018-12-20T07:54:00 Z nicksona Birthday gift (IZhO18_treearray) C++14
100 / 100
1818 ms 172592 KB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n,m,t;
int a,b;
vector <int> v[200001];
int par[200001][41];
int tin[200001],tout[200001];
int mas[200001];
int M=0;
set <int> s[200001];
set <int> s2[200001];
void go (int u,int p){
	par[u][0]=p;
	tin[u]=++M;
	for (int i=1;i<=30;i++){
		par[u][i]=par[par[u][i-1]][i-1];
	}
	
	for (int i=0;i<v[u].size();i++){
		int node=v[u][i];
		if (node!=p){
			go(node,u);
		}
	}
	tout[u]=++M;
}
bool is_par(int a,int b){
	if (tin[a]<=tin[b]&&tout[b]<=tout[a]){
		return true;
	}
	return false;
}
int lca (int a,int b){
	
	if (tin[a]>tin[b]){
		swap (a,b);
	}
	
	if (is_par(a,b)){
		return a;
	}
	
	if (is_par(b,a)){
		return b;
	}
	
	for (int i=30;i>=0;i--){
		if (par[a][i]!=0&&!is_par(par[a][i],b)){
			a=par[a][i];
		}
	}
	
	return par[a][0];
}
main () {
	ios::sync_with_stdio(false);
	//freopen ("damn.in","r",stdin);
	cin>>n>>m>>t;
	
	for (int i=1;i<n;i++){
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
 
	for (int i=1;i<=m;i++){
		cin>>mas[i];
	}	
	
	go (1,0);
	
	for (int i=1;i<m;i++){
		s[lca(mas[i],mas[i+1])].insert(i);
	}	
	
	for (int i=1;i<=m;i++){
		s2[mas[i]].insert(i);
	}	
	
	while (t--){
		int c;
		cin>>c;
		if (c==1){
			int x,y;
			cin>>x>>y;
			if (x!=1) s[lca(mas[x-1],mas[x])].erase(x-1);
			if (x!=m) s[lca(mas[x],mas[x+1])].erase(x);
			s2[mas[x]].erase(x);
			
			mas[x]=y;
			
			if (x!=1) s[lca(mas[x-1],mas[x])].insert(x-1);
			if (x!=m) s[lca(mas[x],mas[x+1])].insert(x);
			s2[mas[x]].insert(x);
		}
		else{
			int l,r,v2;
			cin>>l>>r>>v2;
			set<int>::iterator it,it2;
			it=s[v2].lower_bound(l);
			//cout<<"WOW"<<l<<" "<<r<<" "<<v<<endl;
			it2=s2[v2].lower_bound(l);
			int e;
			e=*it2;
			if (it2!=s2[v2].end()&&e<=r){
				cout<<e<<" "<<e<<endl;
				continue;
			}
			
			if (it!=s[v2].end()){
				e=*it;
				if (e<r){
					cout<<e<<" "<<e+1<<endl;
					continue;
				}
				else{
					cout<<-1<<" "<<-1<<endl;
					continue;
				}
			}
			cout<<-1<<" "<<-1<<endl;	
		}
	}
	return 0;
}
/*
  _   _   _          _
 | \ | | (_)        | |
 |  \| |  _    ___  | | __  ___    ___    _ __     __ _
 | . ` | | |  / __| | |/ / / __|  / _ \  | '_ \   / _` |
 | |\  | | | | (__  |   <  \__ \ | (_) | | | | | | (_| |
 |_| \_| |_|  \___| |_|\_\ |___/  \___/  |_| |_|  \__,_|
 
*/

Compilation message

treearray.cpp: In function 'void go(int, int)':
treearray.cpp:21:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<v[u].size();i++){
               ~^~~~~~~~~~~~
treearray.cpp: At global scope:
treearray.cpp:57:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23800 KB n=5
2 Correct 21 ms 24052 KB n=100
3 Correct 22 ms 24052 KB n=100
4 Correct 25 ms 24052 KB n=100
5 Correct 22 ms 24052 KB n=100
6 Correct 26 ms 24052 KB n=100
7 Correct 22 ms 24212 KB n=100
8 Correct 22 ms 24212 KB n=100
9 Correct 28 ms 24212 KB n=100
10 Correct 26 ms 24212 KB n=100
11 Correct 26 ms 24212 KB n=100
12 Correct 27 ms 24212 KB n=100
13 Correct 25 ms 24252 KB n=100
14 Correct 22 ms 24252 KB n=100
15 Correct 21 ms 24252 KB n=100
16 Correct 22 ms 24252 KB n=100
17 Correct 27 ms 24252 KB n=100
18 Correct 25 ms 24252 KB n=100
19 Correct 25 ms 24252 KB n=100
20 Correct 24 ms 24252 KB n=100
21 Correct 25 ms 24252 KB n=100
22 Correct 26 ms 24252 KB n=100
23 Correct 25 ms 24252 KB n=100
24 Correct 26 ms 24252 KB n=100
25 Correct 25 ms 24252 KB n=100
26 Correct 25 ms 24252 KB n=12
27 Correct 25 ms 24252 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23800 KB n=5
2 Correct 21 ms 24052 KB n=100
3 Correct 22 ms 24052 KB n=100
4 Correct 25 ms 24052 KB n=100
5 Correct 22 ms 24052 KB n=100
6 Correct 26 ms 24052 KB n=100
7 Correct 22 ms 24212 KB n=100
8 Correct 22 ms 24212 KB n=100
9 Correct 28 ms 24212 KB n=100
10 Correct 26 ms 24212 KB n=100
11 Correct 26 ms 24212 KB n=100
12 Correct 27 ms 24212 KB n=100
13 Correct 25 ms 24252 KB n=100
14 Correct 22 ms 24252 KB n=100
15 Correct 21 ms 24252 KB n=100
16 Correct 22 ms 24252 KB n=100
17 Correct 27 ms 24252 KB n=100
18 Correct 25 ms 24252 KB n=100
19 Correct 25 ms 24252 KB n=100
20 Correct 24 ms 24252 KB n=100
21 Correct 25 ms 24252 KB n=100
22 Correct 26 ms 24252 KB n=100
23 Correct 25 ms 24252 KB n=100
24 Correct 26 ms 24252 KB n=100
25 Correct 25 ms 24252 KB n=100
26 Correct 25 ms 24252 KB n=12
27 Correct 25 ms 24252 KB n=100
28 Correct 26 ms 24372 KB n=500
29 Correct 25 ms 24376 KB n=500
30 Correct 26 ms 24376 KB n=500
31 Correct 26 ms 24376 KB n=500
32 Correct 26 ms 24376 KB n=500
33 Correct 27 ms 24376 KB n=500
34 Correct 27 ms 24376 KB n=500
35 Correct 27 ms 24412 KB n=500
36 Correct 27 ms 24528 KB n=500
37 Correct 27 ms 24528 KB n=500
38 Correct 26 ms 24528 KB n=500
39 Correct 27 ms 24528 KB n=500
40 Correct 27 ms 24528 KB n=500
41 Correct 26 ms 24528 KB n=500
42 Correct 26 ms 24528 KB n=500
43 Correct 27 ms 24528 KB n=500
44 Correct 26 ms 24640 KB n=500
45 Correct 23 ms 24640 KB n=500
46 Correct 23 ms 24640 KB n=500
47 Correct 24 ms 24640 KB n=500
48 Correct 27 ms 24640 KB n=500
49 Correct 24 ms 24720 KB n=500
50 Correct 27 ms 24720 KB n=500
51 Correct 23 ms 24720 KB n=500
52 Correct 23 ms 24720 KB n=500
53 Correct 26 ms 24720 KB n=500
54 Correct 27 ms 24796 KB n=500
55 Correct 26 ms 24796 KB n=278
56 Correct 26 ms 24796 KB n=500
57 Correct 26 ms 24796 KB n=500
58 Correct 27 ms 24808 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23800 KB n=5
2 Correct 21 ms 24052 KB n=100
3 Correct 22 ms 24052 KB n=100
4 Correct 25 ms 24052 KB n=100
5 Correct 22 ms 24052 KB n=100
6 Correct 26 ms 24052 KB n=100
7 Correct 22 ms 24212 KB n=100
8 Correct 22 ms 24212 KB n=100
9 Correct 28 ms 24212 KB n=100
10 Correct 26 ms 24212 KB n=100
11 Correct 26 ms 24212 KB n=100
12 Correct 27 ms 24212 KB n=100
13 Correct 25 ms 24252 KB n=100
14 Correct 22 ms 24252 KB n=100
15 Correct 21 ms 24252 KB n=100
16 Correct 22 ms 24252 KB n=100
17 Correct 27 ms 24252 KB n=100
18 Correct 25 ms 24252 KB n=100
19 Correct 25 ms 24252 KB n=100
20 Correct 24 ms 24252 KB n=100
21 Correct 25 ms 24252 KB n=100
22 Correct 26 ms 24252 KB n=100
23 Correct 25 ms 24252 KB n=100
24 Correct 26 ms 24252 KB n=100
25 Correct 25 ms 24252 KB n=100
26 Correct 25 ms 24252 KB n=12
27 Correct 25 ms 24252 KB n=100
28 Correct 26 ms 24372 KB n=500
29 Correct 25 ms 24376 KB n=500
30 Correct 26 ms 24376 KB n=500
31 Correct 26 ms 24376 KB n=500
32 Correct 26 ms 24376 KB n=500
33 Correct 27 ms 24376 KB n=500
34 Correct 27 ms 24376 KB n=500
35 Correct 27 ms 24412 KB n=500
36 Correct 27 ms 24528 KB n=500
37 Correct 27 ms 24528 KB n=500
38 Correct 26 ms 24528 KB n=500
39 Correct 27 ms 24528 KB n=500
40 Correct 27 ms 24528 KB n=500
41 Correct 26 ms 24528 KB n=500
42 Correct 26 ms 24528 KB n=500
43 Correct 27 ms 24528 KB n=500
44 Correct 26 ms 24640 KB n=500
45 Correct 23 ms 24640 KB n=500
46 Correct 23 ms 24640 KB n=500
47 Correct 24 ms 24640 KB n=500
48 Correct 27 ms 24640 KB n=500
49 Correct 24 ms 24720 KB n=500
50 Correct 27 ms 24720 KB n=500
51 Correct 23 ms 24720 KB n=500
52 Correct 23 ms 24720 KB n=500
53 Correct 26 ms 24720 KB n=500
54 Correct 27 ms 24796 KB n=500
55 Correct 26 ms 24796 KB n=278
56 Correct 26 ms 24796 KB n=500
57 Correct 26 ms 24796 KB n=500
58 Correct 27 ms 24808 KB n=500
59 Correct 31 ms 25112 KB n=2000
60 Correct 30 ms 25288 KB n=2000
61 Correct 30 ms 25340 KB n=2000
62 Correct 31 ms 25432 KB n=2000
63 Correct 32 ms 25432 KB n=2000
64 Correct 31 ms 25552 KB n=2000
65 Correct 32 ms 25552 KB n=2000
66 Correct 31 ms 25656 KB n=2000
67 Correct 33 ms 25712 KB n=2000
68 Correct 32 ms 25784 KB n=2000
69 Correct 31 ms 25916 KB n=2000
70 Correct 31 ms 25916 KB n=2000
71 Correct 28 ms 25916 KB n=2000
72 Correct 28 ms 25916 KB n=2000
73 Correct 32 ms 25924 KB n=2000
74 Correct 46 ms 25980 KB n=1844
75 Correct 33 ms 26024 KB n=2000
76 Correct 32 ms 26080 KB n=2000
77 Correct 31 ms 26132 KB n=2000
78 Correct 31 ms 26300 KB n=2000
79 Correct 32 ms 26300 KB n=2000
80 Correct 30 ms 26412 KB n=2000
81 Correct 31 ms 26468 KB n=2000
82 Correct 31 ms 26468 KB n=2000
83 Correct 31 ms 26572 KB n=2000
84 Correct 31 ms 26572 KB n=2000
85 Correct 31 ms 26680 KB n=2000
86 Correct 31 ms 26708 KB n=2000
87 Correct 32 ms 26708 KB n=2000
88 Correct 30 ms 26972 KB n=2000
89 Correct 27 ms 26972 KB n=2000
90 Correct 27 ms 26984 KB n=2000
91 Correct 28 ms 26984 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23800 KB n=5
2 Correct 21 ms 24052 KB n=100
3 Correct 22 ms 24052 KB n=100
4 Correct 25 ms 24052 KB n=100
5 Correct 22 ms 24052 KB n=100
6 Correct 26 ms 24052 KB n=100
7 Correct 22 ms 24212 KB n=100
8 Correct 22 ms 24212 KB n=100
9 Correct 28 ms 24212 KB n=100
10 Correct 26 ms 24212 KB n=100
11 Correct 26 ms 24212 KB n=100
12 Correct 27 ms 24212 KB n=100
13 Correct 25 ms 24252 KB n=100
14 Correct 22 ms 24252 KB n=100
15 Correct 21 ms 24252 KB n=100
16 Correct 22 ms 24252 KB n=100
17 Correct 27 ms 24252 KB n=100
18 Correct 25 ms 24252 KB n=100
19 Correct 25 ms 24252 KB n=100
20 Correct 24 ms 24252 KB n=100
21 Correct 25 ms 24252 KB n=100
22 Correct 26 ms 24252 KB n=100
23 Correct 25 ms 24252 KB n=100
24 Correct 26 ms 24252 KB n=100
25 Correct 25 ms 24252 KB n=100
26 Correct 25 ms 24252 KB n=12
27 Correct 25 ms 24252 KB n=100
28 Correct 26 ms 24372 KB n=500
29 Correct 25 ms 24376 KB n=500
30 Correct 26 ms 24376 KB n=500
31 Correct 26 ms 24376 KB n=500
32 Correct 26 ms 24376 KB n=500
33 Correct 27 ms 24376 KB n=500
34 Correct 27 ms 24376 KB n=500
35 Correct 27 ms 24412 KB n=500
36 Correct 27 ms 24528 KB n=500
37 Correct 27 ms 24528 KB n=500
38 Correct 26 ms 24528 KB n=500
39 Correct 27 ms 24528 KB n=500
40 Correct 27 ms 24528 KB n=500
41 Correct 26 ms 24528 KB n=500
42 Correct 26 ms 24528 KB n=500
43 Correct 27 ms 24528 KB n=500
44 Correct 26 ms 24640 KB n=500
45 Correct 23 ms 24640 KB n=500
46 Correct 23 ms 24640 KB n=500
47 Correct 24 ms 24640 KB n=500
48 Correct 27 ms 24640 KB n=500
49 Correct 24 ms 24720 KB n=500
50 Correct 27 ms 24720 KB n=500
51 Correct 23 ms 24720 KB n=500
52 Correct 23 ms 24720 KB n=500
53 Correct 26 ms 24720 KB n=500
54 Correct 27 ms 24796 KB n=500
55 Correct 26 ms 24796 KB n=278
56 Correct 26 ms 24796 KB n=500
57 Correct 26 ms 24796 KB n=500
58 Correct 27 ms 24808 KB n=500
59 Correct 31 ms 25112 KB n=2000
60 Correct 30 ms 25288 KB n=2000
61 Correct 30 ms 25340 KB n=2000
62 Correct 31 ms 25432 KB n=2000
63 Correct 32 ms 25432 KB n=2000
64 Correct 31 ms 25552 KB n=2000
65 Correct 32 ms 25552 KB n=2000
66 Correct 31 ms 25656 KB n=2000
67 Correct 33 ms 25712 KB n=2000
68 Correct 32 ms 25784 KB n=2000
69 Correct 31 ms 25916 KB n=2000
70 Correct 31 ms 25916 KB n=2000
71 Correct 28 ms 25916 KB n=2000
72 Correct 28 ms 25916 KB n=2000
73 Correct 32 ms 25924 KB n=2000
74 Correct 46 ms 25980 KB n=1844
75 Correct 33 ms 26024 KB n=2000
76 Correct 32 ms 26080 KB n=2000
77 Correct 31 ms 26132 KB n=2000
78 Correct 31 ms 26300 KB n=2000
79 Correct 32 ms 26300 KB n=2000
80 Correct 30 ms 26412 KB n=2000
81 Correct 31 ms 26468 KB n=2000
82 Correct 31 ms 26468 KB n=2000
83 Correct 31 ms 26572 KB n=2000
84 Correct 31 ms 26572 KB n=2000
85 Correct 31 ms 26680 KB n=2000
86 Correct 31 ms 26708 KB n=2000
87 Correct 32 ms 26708 KB n=2000
88 Correct 30 ms 26972 KB n=2000
89 Correct 27 ms 26972 KB n=2000
90 Correct 27 ms 26984 KB n=2000
91 Correct 28 ms 26984 KB n=2000
92 Correct 1151 ms 94360 KB n=200000
93 Correct 1228 ms 105400 KB n=200000
94 Correct 1044 ms 109076 KB n=200000
95 Correct 1245 ms 109076 KB n=200000
96 Correct 1179 ms 109076 KB n=200000
97 Correct 1662 ms 109076 KB n=200000
98 Correct 1332 ms 109076 KB n=200000
99 Correct 1291 ms 109076 KB n=200000
100 Correct 1352 ms 109076 KB n=200000
101 Correct 1212 ms 122008 KB n=200000
102 Correct 942 ms 122008 KB n=200000
103 Correct 935 ms 122008 KB n=200000
104 Correct 904 ms 122008 KB n=200000
105 Correct 898 ms 126176 KB n=200000
106 Correct 874 ms 133576 KB n=200000
107 Correct 957 ms 140820 KB n=200000
108 Correct 1295 ms 146744 KB n=200000
109 Correct 1323 ms 148708 KB n=200000
110 Correct 1307 ms 148816 KB n=200000
111 Correct 1108 ms 149104 KB n=200000
112 Correct 961 ms 156524 KB n=200000
113 Correct 1458 ms 156524 KB n=200000
114 Correct 1397 ms 156524 KB n=200000
115 Correct 1818 ms 156524 KB n=200000
116 Correct 1047 ms 156524 KB n=200000
117 Correct 1029 ms 157012 KB n=200000
118 Correct 1764 ms 157012 KB n=200000
119 Correct 1256 ms 157012 KB n=200000
120 Correct 913 ms 161560 KB n=200000
121 Correct 920 ms 168604 KB n=200000
122 Correct 849 ms 172592 KB n=200000
123 Correct 832 ms 172592 KB n=200000
124 Correct 315 ms 172592 KB n=25264