Submission #239111

# Submission time Handle Problem Language Result Execution time Memory
239111 2020-06-14T12:35:10 Z kshitij_sodani Birthday gift (IZhO18_treearray) C++17
100 / 100
1439 ms 75556 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second

int n,m,q;
set<pair<int,int>> ac[200001];
vector<int> adj[200001];
int it[200001];
int tt[200001];
int par[200001][20];
int lev[200001];
void dfs(int no,int par2=-1,int levv=0){
	par[no][0]=par2;
	lev[no]=levv;
	for(auto j:adj[no]){
		if(j!=par2){
			dfs(j,no,levv+1);
		}
	}
}
int lca(int aa,int bb){
	if(lev[aa]>lev[bb]){
		swap(aa,bb);
	}
	int kk=lev[bb]-lev[aa];
	for(int j=19;j>=0;j--){
		if(kk&(1<<j)){
			bb=par[bb][j];
		}
	}
	if(aa==bb){
		return aa;
	}
	for(int j=19;j>=0;j--){
		if(par[aa][j]==par[bb][j]){
			continue;
		}
		aa=par[aa][j];
		bb=par[bb][j];
	}
	return par[aa][0];
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>m>>q;
	for(int i=0;i<n-1;i++){
		int aa,bb;
		cin>>aa>>bb;
		adj[aa-1].pb(bb-1);
		adj[bb-1].pb(aa-1);
	}
	for(int i=0;i<m;i++){
		cin>>it[i];
		it[i]--;
	}
	dfs(0);
	for(int j=1;j<20;j++){
		for(int i=0;i<n;i++){
			if(par[i][j-1]==-1){
				par[i][j]=-1;
			}
			else{
				par[i][j]=par[par[i][j-1]][j-1];
			}
		}
	}
	for(int i=0;i<m-1;i++){
		tt[i]=lca(it[i],it[i+1]);
		ac[tt[i]].insert({i,1});
	}
	for(int i=0;i<m;i++){
		ac[it[i]].insert({i,0});
	}
	for(int i=0;i<q;i++){
		int aa;
		cin>>aa;
		if(aa==2){
			int ind,l,r;
			cin>>l>>r>>ind;
			l--;
			r--;
			ind--;
			auto x=ac[ind].lower_bound({l,0});
			if(x!=ac[ind].end()){
				if((*x).b==0){
					if((*x).a<=r){
						cout<<(*x).a+1<<" "<<(*x).a+1<<endl;
						continue;
					}
				}
				else{
					if((*x).a+1<=r){
						cout<<(*x).a+1<<" "<<(*x).a+2<<endl;
						continue;
					}
				}
			}
			cout<<"-1 -1"<<endl;
		}
		else{
			int ind;
			int val;
			cin>>ind>>val;
			ind--;
			val--;
			ac[it[ind]].erase({ind,0});
			if(ind<m-1){
				ac[tt[ind]].erase({ind,1});
			}
			if(ind>0){
				ac[tt[ind-1]].erase({ind-1,1});
			}
			it[ind]=val;
			ac[it[ind]].insert({ind,0});
			if(ind<m-1){
				tt[ind]=lca(it[ind],it[ind+1]);
				ac[tt[ind]].insert({ind,1});
		//		cout<<tt[ind]<<endl;
			}
			if(ind>0){
				tt[ind-1]=lca(it[ind-1],it[ind]);
				ac[tt[ind-1]].insert({ind-1,1});
		//		cout<<tt[ind-1]<<endl;
			}
		}
	}







	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14464 KB n=5
2 Correct 13 ms 14464 KB n=100
3 Correct 13 ms 14464 KB n=100
4 Correct 12 ms 14464 KB n=100
5 Correct 13 ms 14464 KB n=100
6 Correct 13 ms 14464 KB n=100
7 Correct 13 ms 14336 KB n=100
8 Correct 13 ms 14464 KB n=100
9 Correct 13 ms 14464 KB n=100
10 Correct 13 ms 14464 KB n=100
11 Correct 13 ms 14464 KB n=100
12 Correct 13 ms 14464 KB n=100
13 Correct 13 ms 14464 KB n=100
14 Correct 13 ms 14464 KB n=100
15 Correct 13 ms 14464 KB n=100
16 Correct 13 ms 14464 KB n=100
17 Correct 13 ms 14464 KB n=100
18 Correct 13 ms 14464 KB n=100
19 Correct 13 ms 14592 KB n=100
20 Correct 13 ms 14464 KB n=100
21 Correct 13 ms 14464 KB n=100
22 Correct 13 ms 14464 KB n=100
23 Correct 13 ms 14464 KB n=100
24 Correct 13 ms 14464 KB n=100
25 Correct 13 ms 14464 KB n=100
26 Correct 12 ms 14464 KB n=12
27 Correct 13 ms 14464 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14464 KB n=5
2 Correct 13 ms 14464 KB n=100
3 Correct 13 ms 14464 KB n=100
4 Correct 12 ms 14464 KB n=100
5 Correct 13 ms 14464 KB n=100
6 Correct 13 ms 14464 KB n=100
7 Correct 13 ms 14336 KB n=100
8 Correct 13 ms 14464 KB n=100
9 Correct 13 ms 14464 KB n=100
10 Correct 13 ms 14464 KB n=100
11 Correct 13 ms 14464 KB n=100
12 Correct 13 ms 14464 KB n=100
13 Correct 13 ms 14464 KB n=100
14 Correct 13 ms 14464 KB n=100
15 Correct 13 ms 14464 KB n=100
16 Correct 13 ms 14464 KB n=100
17 Correct 13 ms 14464 KB n=100
18 Correct 13 ms 14464 KB n=100
19 Correct 13 ms 14592 KB n=100
20 Correct 13 ms 14464 KB n=100
21 Correct 13 ms 14464 KB n=100
22 Correct 13 ms 14464 KB n=100
23 Correct 13 ms 14464 KB n=100
24 Correct 13 ms 14464 KB n=100
25 Correct 13 ms 14464 KB n=100
26 Correct 12 ms 14464 KB n=12
27 Correct 13 ms 14464 KB n=100
28 Correct 14 ms 14592 KB n=500
29 Correct 14 ms 14592 KB n=500
30 Correct 14 ms 14592 KB n=500
31 Correct 14 ms 14592 KB n=500
32 Correct 14 ms 14592 KB n=500
33 Correct 14 ms 14592 KB n=500
34 Correct 14 ms 14592 KB n=500
35 Correct 16 ms 14592 KB n=500
36 Correct 14 ms 14592 KB n=500
37 Correct 14 ms 14592 KB n=500
38 Correct 14 ms 14592 KB n=500
39 Correct 14 ms 14592 KB n=500
40 Correct 14 ms 14592 KB n=500
41 Correct 14 ms 14592 KB n=500
42 Correct 14 ms 14592 KB n=500
43 Correct 14 ms 14592 KB n=500
44 Correct 14 ms 14592 KB n=500
45 Correct 14 ms 14592 KB n=500
46 Correct 14 ms 14592 KB n=500
47 Correct 14 ms 14592 KB n=500
48 Correct 14 ms 14592 KB n=500
49 Correct 14 ms 14592 KB n=500
50 Correct 14 ms 14592 KB n=500
51 Correct 14 ms 14516 KB n=500
52 Correct 14 ms 14592 KB n=500
53 Correct 14 ms 14592 KB n=500
54 Correct 15 ms 14592 KB n=500
55 Correct 13 ms 14592 KB n=278
56 Correct 14 ms 14592 KB n=500
57 Correct 14 ms 14592 KB n=500
58 Correct 14 ms 14592 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14464 KB n=5
2 Correct 13 ms 14464 KB n=100
3 Correct 13 ms 14464 KB n=100
4 Correct 12 ms 14464 KB n=100
5 Correct 13 ms 14464 KB n=100
6 Correct 13 ms 14464 KB n=100
7 Correct 13 ms 14336 KB n=100
8 Correct 13 ms 14464 KB n=100
9 Correct 13 ms 14464 KB n=100
10 Correct 13 ms 14464 KB n=100
11 Correct 13 ms 14464 KB n=100
12 Correct 13 ms 14464 KB n=100
13 Correct 13 ms 14464 KB n=100
14 Correct 13 ms 14464 KB n=100
15 Correct 13 ms 14464 KB n=100
16 Correct 13 ms 14464 KB n=100
17 Correct 13 ms 14464 KB n=100
18 Correct 13 ms 14464 KB n=100
19 Correct 13 ms 14592 KB n=100
20 Correct 13 ms 14464 KB n=100
21 Correct 13 ms 14464 KB n=100
22 Correct 13 ms 14464 KB n=100
23 Correct 13 ms 14464 KB n=100
24 Correct 13 ms 14464 KB n=100
25 Correct 13 ms 14464 KB n=100
26 Correct 12 ms 14464 KB n=12
27 Correct 13 ms 14464 KB n=100
28 Correct 14 ms 14592 KB n=500
29 Correct 14 ms 14592 KB n=500
30 Correct 14 ms 14592 KB n=500
31 Correct 14 ms 14592 KB n=500
32 Correct 14 ms 14592 KB n=500
33 Correct 14 ms 14592 KB n=500
34 Correct 14 ms 14592 KB n=500
35 Correct 16 ms 14592 KB n=500
36 Correct 14 ms 14592 KB n=500
37 Correct 14 ms 14592 KB n=500
38 Correct 14 ms 14592 KB n=500
39 Correct 14 ms 14592 KB n=500
40 Correct 14 ms 14592 KB n=500
41 Correct 14 ms 14592 KB n=500
42 Correct 14 ms 14592 KB n=500
43 Correct 14 ms 14592 KB n=500
44 Correct 14 ms 14592 KB n=500
45 Correct 14 ms 14592 KB n=500
46 Correct 14 ms 14592 KB n=500
47 Correct 14 ms 14592 KB n=500
48 Correct 14 ms 14592 KB n=500
49 Correct 14 ms 14592 KB n=500
50 Correct 14 ms 14592 KB n=500
51 Correct 14 ms 14516 KB n=500
52 Correct 14 ms 14592 KB n=500
53 Correct 14 ms 14592 KB n=500
54 Correct 15 ms 14592 KB n=500
55 Correct 13 ms 14592 KB n=278
56 Correct 14 ms 14592 KB n=500
57 Correct 14 ms 14592 KB n=500
58 Correct 14 ms 14592 KB n=500
59 Correct 21 ms 14976 KB n=2000
60 Correct 18 ms 15104 KB n=2000
61 Correct 18 ms 15104 KB n=2000
62 Correct 19 ms 14976 KB n=2000
63 Correct 18 ms 14976 KB n=2000
64 Correct 19 ms 14976 KB n=2000
65 Correct 19 ms 14976 KB n=2000
66 Correct 18 ms 14976 KB n=2000
67 Correct 18 ms 14976 KB n=2000
68 Correct 18 ms 14976 KB n=2000
69 Correct 19 ms 14976 KB n=2000
70 Correct 19 ms 14976 KB n=2000
71 Correct 20 ms 14976 KB n=2000
72 Correct 19 ms 14976 KB n=2000
73 Correct 19 ms 14976 KB n=2000
74 Correct 17 ms 14976 KB n=1844
75 Correct 19 ms 14976 KB n=2000
76 Correct 18 ms 14976 KB n=2000
77 Correct 18 ms 14976 KB n=2000
78 Correct 18 ms 14976 KB n=2000
79 Correct 18 ms 14976 KB n=2000
80 Correct 19 ms 14976 KB n=2000
81 Correct 18 ms 14976 KB n=2000
82 Correct 18 ms 14976 KB n=2000
83 Correct 18 ms 14976 KB n=2000
84 Correct 18 ms 14976 KB n=2000
85 Correct 18 ms 14976 KB n=2000
86 Correct 18 ms 14976 KB n=2000
87 Correct 18 ms 14976 KB n=2000
88 Correct 17 ms 15104 KB n=2000
89 Correct 18 ms 15104 KB n=2000
90 Correct 18 ms 15104 KB n=2000
91 Correct 19 ms 14976 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14464 KB n=5
2 Correct 13 ms 14464 KB n=100
3 Correct 13 ms 14464 KB n=100
4 Correct 12 ms 14464 KB n=100
5 Correct 13 ms 14464 KB n=100
6 Correct 13 ms 14464 KB n=100
7 Correct 13 ms 14336 KB n=100
8 Correct 13 ms 14464 KB n=100
9 Correct 13 ms 14464 KB n=100
10 Correct 13 ms 14464 KB n=100
11 Correct 13 ms 14464 KB n=100
12 Correct 13 ms 14464 KB n=100
13 Correct 13 ms 14464 KB n=100
14 Correct 13 ms 14464 KB n=100
15 Correct 13 ms 14464 KB n=100
16 Correct 13 ms 14464 KB n=100
17 Correct 13 ms 14464 KB n=100
18 Correct 13 ms 14464 KB n=100
19 Correct 13 ms 14592 KB n=100
20 Correct 13 ms 14464 KB n=100
21 Correct 13 ms 14464 KB n=100
22 Correct 13 ms 14464 KB n=100
23 Correct 13 ms 14464 KB n=100
24 Correct 13 ms 14464 KB n=100
25 Correct 13 ms 14464 KB n=100
26 Correct 12 ms 14464 KB n=12
27 Correct 13 ms 14464 KB n=100
28 Correct 14 ms 14592 KB n=500
29 Correct 14 ms 14592 KB n=500
30 Correct 14 ms 14592 KB n=500
31 Correct 14 ms 14592 KB n=500
32 Correct 14 ms 14592 KB n=500
33 Correct 14 ms 14592 KB n=500
34 Correct 14 ms 14592 KB n=500
35 Correct 16 ms 14592 KB n=500
36 Correct 14 ms 14592 KB n=500
37 Correct 14 ms 14592 KB n=500
38 Correct 14 ms 14592 KB n=500
39 Correct 14 ms 14592 KB n=500
40 Correct 14 ms 14592 KB n=500
41 Correct 14 ms 14592 KB n=500
42 Correct 14 ms 14592 KB n=500
43 Correct 14 ms 14592 KB n=500
44 Correct 14 ms 14592 KB n=500
45 Correct 14 ms 14592 KB n=500
46 Correct 14 ms 14592 KB n=500
47 Correct 14 ms 14592 KB n=500
48 Correct 14 ms 14592 KB n=500
49 Correct 14 ms 14592 KB n=500
50 Correct 14 ms 14592 KB n=500
51 Correct 14 ms 14516 KB n=500
52 Correct 14 ms 14592 KB n=500
53 Correct 14 ms 14592 KB n=500
54 Correct 15 ms 14592 KB n=500
55 Correct 13 ms 14592 KB n=278
56 Correct 14 ms 14592 KB n=500
57 Correct 14 ms 14592 KB n=500
58 Correct 14 ms 14592 KB n=500
59 Correct 21 ms 14976 KB n=2000
60 Correct 18 ms 15104 KB n=2000
61 Correct 18 ms 15104 KB n=2000
62 Correct 19 ms 14976 KB n=2000
63 Correct 18 ms 14976 KB n=2000
64 Correct 19 ms 14976 KB n=2000
65 Correct 19 ms 14976 KB n=2000
66 Correct 18 ms 14976 KB n=2000
67 Correct 18 ms 14976 KB n=2000
68 Correct 18 ms 14976 KB n=2000
69 Correct 19 ms 14976 KB n=2000
70 Correct 19 ms 14976 KB n=2000
71 Correct 20 ms 14976 KB n=2000
72 Correct 19 ms 14976 KB n=2000
73 Correct 19 ms 14976 KB n=2000
74 Correct 17 ms 14976 KB n=1844
75 Correct 19 ms 14976 KB n=2000
76 Correct 18 ms 14976 KB n=2000
77 Correct 18 ms 14976 KB n=2000
78 Correct 18 ms 14976 KB n=2000
79 Correct 18 ms 14976 KB n=2000
80 Correct 19 ms 14976 KB n=2000
81 Correct 18 ms 14976 KB n=2000
82 Correct 18 ms 14976 KB n=2000
83 Correct 18 ms 14976 KB n=2000
84 Correct 18 ms 14976 KB n=2000
85 Correct 18 ms 14976 KB n=2000
86 Correct 18 ms 14976 KB n=2000
87 Correct 18 ms 14976 KB n=2000
88 Correct 17 ms 15104 KB n=2000
89 Correct 18 ms 15104 KB n=2000
90 Correct 18 ms 15104 KB n=2000
91 Correct 19 ms 14976 KB n=2000
92 Correct 936 ms 66168 KB n=200000
93 Correct 1150 ms 70904 KB n=200000
94 Correct 1094 ms 74360 KB n=200000
95 Correct 924 ms 65896 KB n=200000
96 Correct 946 ms 65772 KB n=200000
97 Correct 1196 ms 70392 KB n=200000
98 Correct 935 ms 65900 KB n=200000
99 Correct 1116 ms 66296 KB n=200000
100 Correct 945 ms 65904 KB n=200000
101 Correct 1092 ms 75556 KB n=200000
102 Correct 845 ms 67064 KB n=200000
103 Correct 847 ms 66988 KB n=200000
104 Correct 848 ms 67112 KB n=200000
105 Correct 857 ms 67448 KB n=200000
106 Correct 848 ms 67576 KB n=200000
107 Correct 846 ms 67448 KB n=200000
108 Correct 1043 ms 65912 KB n=200000
109 Correct 1026 ms 65912 KB n=200000
110 Correct 1043 ms 66040 KB n=200000
111 Correct 916 ms 65268 KB n=200000
112 Correct 1197 ms 74520 KB n=200000
113 Correct 1317 ms 70008 KB n=200000
114 Correct 1049 ms 65516 KB n=200000
115 Correct 1278 ms 68048 KB n=200000
116 Correct 880 ms 66024 KB n=200000
117 Correct 1097 ms 74872 KB n=200000
118 Correct 1366 ms 68984 KB n=200000
119 Correct 911 ms 66152 KB n=200000
120 Correct 1201 ms 74660 KB n=200000
121 Correct 1439 ms 74600 KB n=200000
122 Correct 1106 ms 75020 KB n=200000
123 Correct 857 ms 67320 KB n=200000
124 Correct 425 ms 29688 KB n=25264