답안 #854217

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854217 2023-09-26T11:42:58 Z TakeMe Birthday gift (IZhO18_treearray) C++14
56 / 100
1805 ms 88104 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
 
const ll N = 2e5+5;
const ll LOG = 20;
 
ll n,m,q,u,v;
ll l,r,node,val;
ll upd,event;
bool ans;
ll depth[N],a[N];
ll anc[N][LOG];
vector<ll> adj[N];
set<pii> st,st2;
 
void dfs(ll x, ll y) {
	anc[x][0] = y;
	depth[x] = depth[y] + 1;
	for(int i=1; i<LOG; i++) {
		anc[x][i] = anc[anc[x][i-1]][i-1];
	}
	for(auto i : adj[x]) {
		if(i == y) continue;
		dfs(i,x);
	}
}
 
ll lca(ll x, ll y) {
	if(depth[x] < depth[y]) swap(x,y);
	for(int i=LOG-1; i>=0; i--) {
		if(depth[anc[x][i]] >= depth[y]) {
			x = anc[x][i];
		}
	}
	if(x == y) return x;
	for(int i=LOG-1; i>=0; i--) {
		if(anc[x][i] != anc[y][i]) {
			x = anc[x][i];
			y = anc[y][i];
		}
	}
	return anc[x][0];
}
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m >> q;
	for(int i=1; i<n; i++) {
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	dfs(1,0);
	for(int i=1; i<=m; i++) {
		cin >> a[i];
		st2.insert({a[i],i});
	}
	for(int i=1; i<m; i++) st.insert({lca(a[i],a[i+1]),i});
	while(q--) {
		cin >> event;
		if(event == 1) {
			cin >> upd >> val;
			if(upd > 1) st.erase({lca(a[upd],a[upd-1]),upd-1});
			if(upd < n) st.erase({lca(a[upd],a[upd+1]),upd});
			st2.erase({a[upd],upd});
			
			a[upd] = val;
			if(upd > 1) st.insert({lca(a[upd],a[upd-1]),upd-1});
			if(upd < n) st.insert({lca(a[upd],a[upd+1]),upd});
			st2.insert({a[upd],upd});
		}
		else {
			cin >> l >> r >> node;
			pii var = {node,l};
			auto temp = st.lb(var);
			auto temp2 = st2.lb(var);
			if(temp != st.end() && (*temp).fi == node && (*temp).se >= l && (*temp).se + 1 <= r) {
				cout << (*temp).se << " " << (*temp).se + 1 << endl;
			}
			else if(temp2 != st2.end() && (*temp2).fi == node && (*temp2).se <= r) {
				cout << (*temp2).se << " " << (*temp2).se << endl;
			}
			else cout << "-1 -1" << endl;
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB n=5
2 Correct 2 ms 8792 KB n=100
3 Correct 2 ms 8796 KB n=100
4 Correct 2 ms 8792 KB n=100
5 Correct 2 ms 8796 KB n=100
6 Correct 2 ms 8792 KB n=100
7 Correct 2 ms 8792 KB n=100
8 Correct 2 ms 8796 KB n=100
9 Correct 2 ms 8792 KB n=100
10 Correct 2 ms 8792 KB n=100
11 Correct 2 ms 8792 KB n=100
12 Correct 2 ms 8792 KB n=100
13 Correct 2 ms 8792 KB n=100
14 Correct 2 ms 8796 KB n=100
15 Correct 2 ms 8792 KB n=100
16 Correct 2 ms 8796 KB n=100
17 Correct 2 ms 8792 KB n=100
18 Correct 2 ms 8840 KB n=100
19 Correct 2 ms 8792 KB n=100
20 Correct 2 ms 8792 KB n=100
21 Correct 2 ms 8792 KB n=100
22 Correct 2 ms 8792 KB n=100
23 Correct 2 ms 8796 KB n=100
24 Correct 2 ms 8792 KB n=100
25 Correct 3 ms 8792 KB n=100
26 Correct 2 ms 8792 KB n=12
27 Correct 2 ms 8796 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB n=5
2 Correct 2 ms 8792 KB n=100
3 Correct 2 ms 8796 KB n=100
4 Correct 2 ms 8792 KB n=100
5 Correct 2 ms 8796 KB n=100
6 Correct 2 ms 8792 KB n=100
7 Correct 2 ms 8792 KB n=100
8 Correct 2 ms 8796 KB n=100
9 Correct 2 ms 8792 KB n=100
10 Correct 2 ms 8792 KB n=100
11 Correct 2 ms 8792 KB n=100
12 Correct 2 ms 8792 KB n=100
13 Correct 2 ms 8792 KB n=100
14 Correct 2 ms 8796 KB n=100
15 Correct 2 ms 8792 KB n=100
16 Correct 2 ms 8796 KB n=100
17 Correct 2 ms 8792 KB n=100
18 Correct 2 ms 8840 KB n=100
19 Correct 2 ms 8792 KB n=100
20 Correct 2 ms 8792 KB n=100
21 Correct 2 ms 8792 KB n=100
22 Correct 2 ms 8792 KB n=100
23 Correct 2 ms 8796 KB n=100
24 Correct 2 ms 8792 KB n=100
25 Correct 3 ms 8792 KB n=100
26 Correct 2 ms 8792 KB n=12
27 Correct 2 ms 8796 KB n=100
28 Correct 3 ms 8792 KB n=500
29 Correct 3 ms 8900 KB n=500
30 Correct 3 ms 8792 KB n=500
31 Correct 3 ms 8792 KB n=500
32 Correct 3 ms 9052 KB n=500
33 Correct 3 ms 8792 KB n=500
34 Correct 3 ms 8792 KB n=500
35 Correct 3 ms 8792 KB n=500
36 Correct 3 ms 8796 KB n=500
37 Correct 3 ms 8796 KB n=500
38 Correct 3 ms 8792 KB n=500
39 Correct 3 ms 8796 KB n=500
40 Correct 3 ms 8792 KB n=500
41 Correct 3 ms 8792 KB n=500
42 Correct 3 ms 8792 KB n=500
43 Correct 3 ms 8792 KB n=500
44 Correct 3 ms 8792 KB n=500
45 Correct 3 ms 8792 KB n=500
46 Correct 3 ms 8792 KB n=500
47 Correct 3 ms 8792 KB n=500
48 Correct 3 ms 8792 KB n=500
49 Correct 3 ms 8792 KB n=500
50 Correct 3 ms 8796 KB n=500
51 Correct 3 ms 8796 KB n=500
52 Correct 3 ms 8792 KB n=500
53 Correct 3 ms 8992 KB n=500
54 Correct 3 ms 8844 KB n=500
55 Correct 2 ms 8796 KB n=278
56 Correct 2 ms 8792 KB n=500
57 Correct 2 ms 8792 KB n=500
58 Correct 3 ms 8796 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB n=5
2 Correct 2 ms 8792 KB n=100
3 Correct 2 ms 8796 KB n=100
4 Correct 2 ms 8792 KB n=100
5 Correct 2 ms 8796 KB n=100
6 Correct 2 ms 8792 KB n=100
7 Correct 2 ms 8792 KB n=100
8 Correct 2 ms 8796 KB n=100
9 Correct 2 ms 8792 KB n=100
10 Correct 2 ms 8792 KB n=100
11 Correct 2 ms 8792 KB n=100
12 Correct 2 ms 8792 KB n=100
13 Correct 2 ms 8792 KB n=100
14 Correct 2 ms 8796 KB n=100
15 Correct 2 ms 8792 KB n=100
16 Correct 2 ms 8796 KB n=100
17 Correct 2 ms 8792 KB n=100
18 Correct 2 ms 8840 KB n=100
19 Correct 2 ms 8792 KB n=100
20 Correct 2 ms 8792 KB n=100
21 Correct 2 ms 8792 KB n=100
22 Correct 2 ms 8792 KB n=100
23 Correct 2 ms 8796 KB n=100
24 Correct 2 ms 8792 KB n=100
25 Correct 3 ms 8792 KB n=100
26 Correct 2 ms 8792 KB n=12
27 Correct 2 ms 8796 KB n=100
28 Correct 3 ms 8792 KB n=500
29 Correct 3 ms 8900 KB n=500
30 Correct 3 ms 8792 KB n=500
31 Correct 3 ms 8792 KB n=500
32 Correct 3 ms 9052 KB n=500
33 Correct 3 ms 8792 KB n=500
34 Correct 3 ms 8792 KB n=500
35 Correct 3 ms 8792 KB n=500
36 Correct 3 ms 8796 KB n=500
37 Correct 3 ms 8796 KB n=500
38 Correct 3 ms 8792 KB n=500
39 Correct 3 ms 8796 KB n=500
40 Correct 3 ms 8792 KB n=500
41 Correct 3 ms 8792 KB n=500
42 Correct 3 ms 8792 KB n=500
43 Correct 3 ms 8792 KB n=500
44 Correct 3 ms 8792 KB n=500
45 Correct 3 ms 8792 KB n=500
46 Correct 3 ms 8792 KB n=500
47 Correct 3 ms 8792 KB n=500
48 Correct 3 ms 8792 KB n=500
49 Correct 3 ms 8792 KB n=500
50 Correct 3 ms 8796 KB n=500
51 Correct 3 ms 8796 KB n=500
52 Correct 3 ms 8792 KB n=500
53 Correct 3 ms 8992 KB n=500
54 Correct 3 ms 8844 KB n=500
55 Correct 2 ms 8796 KB n=278
56 Correct 2 ms 8792 KB n=500
57 Correct 2 ms 8792 KB n=500
58 Correct 3 ms 8796 KB n=500
59 Correct 6 ms 9048 KB n=2000
60 Correct 7 ms 9304 KB n=2000
61 Correct 7 ms 9048 KB n=2000
62 Correct 7 ms 9048 KB n=2000
63 Correct 8 ms 9048 KB n=2000
64 Correct 7 ms 9048 KB n=2000
65 Correct 6 ms 9048 KB n=2000
66 Correct 7 ms 9304 KB n=2000
67 Correct 7 ms 9048 KB n=2000
68 Correct 7 ms 9048 KB n=2000
69 Correct 6 ms 9048 KB n=2000
70 Correct 6 ms 9048 KB n=2000
71 Correct 6 ms 9052 KB n=2000
72 Correct 6 ms 9048 KB n=2000
73 Correct 6 ms 9052 KB n=2000
74 Correct 6 ms 9048 KB n=1844
75 Correct 6 ms 9048 KB n=2000
76 Correct 7 ms 9048 KB n=2000
77 Correct 6 ms 9052 KB n=2000
78 Correct 6 ms 9048 KB n=2000
79 Correct 7 ms 9048 KB n=2000
80 Correct 7 ms 9560 KB n=2000
81 Correct 8 ms 9048 KB n=2000
82 Correct 6 ms 9048 KB n=2000
83 Correct 7 ms 9304 KB n=2000
84 Correct 6 ms 9048 KB n=2000
85 Correct 7 ms 9048 KB n=2000
86 Correct 7 ms 9048 KB n=2000
87 Correct 6 ms 9052 KB n=2000
88 Correct 7 ms 9304 KB n=2000
89 Correct 6 ms 9304 KB n=2000
90 Correct 6 ms 9304 KB n=2000
91 Correct 6 ms 9052 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB n=5
2 Correct 2 ms 8792 KB n=100
3 Correct 2 ms 8796 KB n=100
4 Correct 2 ms 8792 KB n=100
5 Correct 2 ms 8796 KB n=100
6 Correct 2 ms 8792 KB n=100
7 Correct 2 ms 8792 KB n=100
8 Correct 2 ms 8796 KB n=100
9 Correct 2 ms 8792 KB n=100
10 Correct 2 ms 8792 KB n=100
11 Correct 2 ms 8792 KB n=100
12 Correct 2 ms 8792 KB n=100
13 Correct 2 ms 8792 KB n=100
14 Correct 2 ms 8796 KB n=100
15 Correct 2 ms 8792 KB n=100
16 Correct 2 ms 8796 KB n=100
17 Correct 2 ms 8792 KB n=100
18 Correct 2 ms 8840 KB n=100
19 Correct 2 ms 8792 KB n=100
20 Correct 2 ms 8792 KB n=100
21 Correct 2 ms 8792 KB n=100
22 Correct 2 ms 8792 KB n=100
23 Correct 2 ms 8796 KB n=100
24 Correct 2 ms 8792 KB n=100
25 Correct 3 ms 8792 KB n=100
26 Correct 2 ms 8792 KB n=12
27 Correct 2 ms 8796 KB n=100
28 Correct 3 ms 8792 KB n=500
29 Correct 3 ms 8900 KB n=500
30 Correct 3 ms 8792 KB n=500
31 Correct 3 ms 8792 KB n=500
32 Correct 3 ms 9052 KB n=500
33 Correct 3 ms 8792 KB n=500
34 Correct 3 ms 8792 KB n=500
35 Correct 3 ms 8792 KB n=500
36 Correct 3 ms 8796 KB n=500
37 Correct 3 ms 8796 KB n=500
38 Correct 3 ms 8792 KB n=500
39 Correct 3 ms 8796 KB n=500
40 Correct 3 ms 8792 KB n=500
41 Correct 3 ms 8792 KB n=500
42 Correct 3 ms 8792 KB n=500
43 Correct 3 ms 8792 KB n=500
44 Correct 3 ms 8792 KB n=500
45 Correct 3 ms 8792 KB n=500
46 Correct 3 ms 8792 KB n=500
47 Correct 3 ms 8792 KB n=500
48 Correct 3 ms 8792 KB n=500
49 Correct 3 ms 8792 KB n=500
50 Correct 3 ms 8796 KB n=500
51 Correct 3 ms 8796 KB n=500
52 Correct 3 ms 8792 KB n=500
53 Correct 3 ms 8992 KB n=500
54 Correct 3 ms 8844 KB n=500
55 Correct 2 ms 8796 KB n=278
56 Correct 2 ms 8792 KB n=500
57 Correct 2 ms 8792 KB n=500
58 Correct 3 ms 8796 KB n=500
59 Correct 6 ms 9048 KB n=2000
60 Correct 7 ms 9304 KB n=2000
61 Correct 7 ms 9048 KB n=2000
62 Correct 7 ms 9048 KB n=2000
63 Correct 8 ms 9048 KB n=2000
64 Correct 7 ms 9048 KB n=2000
65 Correct 6 ms 9048 KB n=2000
66 Correct 7 ms 9304 KB n=2000
67 Correct 7 ms 9048 KB n=2000
68 Correct 7 ms 9048 KB n=2000
69 Correct 6 ms 9048 KB n=2000
70 Correct 6 ms 9048 KB n=2000
71 Correct 6 ms 9052 KB n=2000
72 Correct 6 ms 9048 KB n=2000
73 Correct 6 ms 9052 KB n=2000
74 Correct 6 ms 9048 KB n=1844
75 Correct 6 ms 9048 KB n=2000
76 Correct 7 ms 9048 KB n=2000
77 Correct 6 ms 9052 KB n=2000
78 Correct 6 ms 9048 KB n=2000
79 Correct 7 ms 9048 KB n=2000
80 Correct 7 ms 9560 KB n=2000
81 Correct 8 ms 9048 KB n=2000
82 Correct 6 ms 9048 KB n=2000
83 Correct 7 ms 9304 KB n=2000
84 Correct 6 ms 9048 KB n=2000
85 Correct 7 ms 9048 KB n=2000
86 Correct 7 ms 9048 KB n=2000
87 Correct 6 ms 9052 KB n=2000
88 Correct 7 ms 9304 KB n=2000
89 Correct 6 ms 9304 KB n=2000
90 Correct 6 ms 9304 KB n=2000
91 Correct 6 ms 9052 KB n=2000
92 Correct 966 ms 79432 KB n=200000
93 Correct 1670 ms 84364 KB n=200000
94 Correct 1732 ms 87352 KB n=200000
95 Correct 914 ms 79548 KB n=200000
96 Correct 914 ms 79552 KB n=200000
97 Correct 1732 ms 83380 KB n=200000
98 Correct 946 ms 79616 KB n=200000
99 Correct 1161 ms 79908 KB n=200000
100 Correct 913 ms 79300 KB n=200000
101 Correct 1775 ms 88104 KB n=200000
102 Correct 639 ms 80752 KB n=200000
103 Correct 638 ms 80964 KB n=200000
104 Correct 621 ms 80796 KB n=200000
105 Correct 614 ms 80976 KB n=200000
106 Correct 656 ms 80908 KB n=200000
107 Correct 627 ms 80784 KB n=200000
108 Correct 1050 ms 79664 KB n=200000
109 Correct 1077 ms 79992 KB n=200000
110 Correct 1014 ms 79728 KB n=200000
111 Correct 875 ms 78932 KB n=200000
112 Correct 1686 ms 87396 KB n=200000
113 Correct 1726 ms 83596 KB n=200000
114 Correct 834 ms 78916 KB n=200000
115 Correct 1574 ms 81468 KB n=200000
116 Correct 862 ms 79548 KB n=200000
117 Correct 1660 ms 87608 KB n=200000
118 Correct 1805 ms 82276 KB n=200000
119 Correct 868 ms 79728 KB n=200000
120 Correct 1519 ms 86960 KB n=200000
121 Correct 1612 ms 87252 KB n=200000
122 Correct 1637 ms 87576 KB n=200000
123 Correct 615 ms 80816 KB n=200000
124 Incorrect 278 ms 28596 KB Wrong range.
125 Halted 0 ms 0 KB -