#include <bits/stdc++.h>
#define All(x) x.begin(), x.end()
#define pb emplace_back
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
const int MAXN = 200000;
const int L = 20;
int N, M, Q;
int a, b, c;
vector <int> path[MAXN+1];
int anc[MAXN+1][L];
pii dfs[MAXN+1];
int cnt;
int v[MAXN*2+1];
set <int> pos[MAXN+1];
int typ;
void DFS(int now, int par) {
dfs[now].ff = ++cnt;
for (int i : path[now]) {
if (i == par) continue;
anc[i][0] = now;
DFS(i, now);
}
dfs[now].ss = ++cnt;
}
void build() {
for (int i = 1; i < L; i++) {
for (int j = 1; j <= N; j++) {
anc[j][i] = anc[anc[j][i-1]][i-1];
}
}
}
bool ancestor(int a, int b) {
return dfs[a].ff <= dfs[b].ff && dfs[b].ss <= dfs[a].ss;
}
int LCA(int a, int b) {
if (ancestor(a, b)) return a;
for (int i = L-1; i >= 0; i--) {
if (!ancestor(anc[a][i], b))
a = anc[a][i];
}
return anc[a][0];
}
void del(int x, int v) {
pos[x].erase(v);
}
void add(int x, int v) {
pos[x].insert(v);
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N >> M >> Q;
for (int i = 0; i < N-1; i++) {
cin >> a >> b;
path[a].pb(b);
path[b].pb(a);
}
anc[1][0] = 1;
DFS(1, 0);
build();
for (int i = 1; i <= M; i++) {
cin >> v[i*2];
if (i > 1)
v[i*2-1] = LCA(v[i*2-2], v[i*2]);
}
for (int i = 2; i <= 2*M; i++)
pos[v[i]].insert(i);
for (int i = 0; i < Q; i++) {
cin >> typ;
if (typ == 1) {
cin >> a >> c;
del(v[a*2], a*2);
v[a*2] = c;
add(v[a*2], a*2);
if (a > 1) {
del(v[a*2-1], a*2-1);
v[a*2-1] = LCA(v[a*2], v[a*2-2]);
add(v[a*2-1], a*2-1);
}
if (a < M) {
del(v[a*2+1], a*2+1);
v[a*2+1] = LCA(v[a*2], v[a*2+2]);
add(v[a*2+1], a*2+1);
}
} else {
cin >> a >> b >> c;
auto k = pos[c].lower_bound(a*2);
if (k != pos[c].end() && *k <= b*2) {
cout << *k/2 << ' ' << (*k+1)/2 << '\n';
} else {
cout << -1 << ' ' << -1 << '\n';
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
n=5 |
2 |
Correct |
10 ms |
14444 KB |
n=100 |
3 |
Correct |
10 ms |
14444 KB |
n=100 |
4 |
Correct |
10 ms |
14444 KB |
n=100 |
5 |
Correct |
10 ms |
14444 KB |
n=100 |
6 |
Correct |
11 ms |
14444 KB |
n=100 |
7 |
Correct |
10 ms |
14444 KB |
n=100 |
8 |
Correct |
10 ms |
14444 KB |
n=100 |
9 |
Correct |
10 ms |
14444 KB |
n=100 |
10 |
Correct |
11 ms |
14444 KB |
n=100 |
11 |
Correct |
10 ms |
14572 KB |
n=100 |
12 |
Correct |
10 ms |
14444 KB |
n=100 |
13 |
Correct |
10 ms |
14444 KB |
n=100 |
14 |
Correct |
10 ms |
14444 KB |
n=100 |
15 |
Correct |
10 ms |
14444 KB |
n=100 |
16 |
Correct |
10 ms |
14444 KB |
n=100 |
17 |
Correct |
10 ms |
14444 KB |
n=100 |
18 |
Correct |
10 ms |
14444 KB |
n=100 |
19 |
Correct |
10 ms |
14444 KB |
n=100 |
20 |
Correct |
10 ms |
14444 KB |
n=100 |
21 |
Correct |
10 ms |
14444 KB |
n=100 |
22 |
Correct |
10 ms |
14444 KB |
n=100 |
23 |
Correct |
10 ms |
14444 KB |
n=100 |
24 |
Correct |
10 ms |
14444 KB |
n=100 |
25 |
Correct |
10 ms |
14464 KB |
n=100 |
26 |
Correct |
10 ms |
14444 KB |
n=12 |
27 |
Correct |
10 ms |
14444 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
n=5 |
2 |
Correct |
10 ms |
14444 KB |
n=100 |
3 |
Correct |
10 ms |
14444 KB |
n=100 |
4 |
Correct |
10 ms |
14444 KB |
n=100 |
5 |
Correct |
10 ms |
14444 KB |
n=100 |
6 |
Correct |
11 ms |
14444 KB |
n=100 |
7 |
Correct |
10 ms |
14444 KB |
n=100 |
8 |
Correct |
10 ms |
14444 KB |
n=100 |
9 |
Correct |
10 ms |
14444 KB |
n=100 |
10 |
Correct |
11 ms |
14444 KB |
n=100 |
11 |
Correct |
10 ms |
14572 KB |
n=100 |
12 |
Correct |
10 ms |
14444 KB |
n=100 |
13 |
Correct |
10 ms |
14444 KB |
n=100 |
14 |
Correct |
10 ms |
14444 KB |
n=100 |
15 |
Correct |
10 ms |
14444 KB |
n=100 |
16 |
Correct |
10 ms |
14444 KB |
n=100 |
17 |
Correct |
10 ms |
14444 KB |
n=100 |
18 |
Correct |
10 ms |
14444 KB |
n=100 |
19 |
Correct |
10 ms |
14444 KB |
n=100 |
20 |
Correct |
10 ms |
14444 KB |
n=100 |
21 |
Correct |
10 ms |
14444 KB |
n=100 |
22 |
Correct |
10 ms |
14444 KB |
n=100 |
23 |
Correct |
10 ms |
14444 KB |
n=100 |
24 |
Correct |
10 ms |
14444 KB |
n=100 |
25 |
Correct |
10 ms |
14464 KB |
n=100 |
26 |
Correct |
10 ms |
14444 KB |
n=12 |
27 |
Correct |
10 ms |
14444 KB |
n=100 |
28 |
Correct |
11 ms |
14572 KB |
n=500 |
29 |
Correct |
11 ms |
14572 KB |
n=500 |
30 |
Correct |
11 ms |
14572 KB |
n=500 |
31 |
Correct |
11 ms |
14572 KB |
n=500 |
32 |
Correct |
11 ms |
14572 KB |
n=500 |
33 |
Correct |
11 ms |
14572 KB |
n=500 |
34 |
Correct |
11 ms |
14572 KB |
n=500 |
35 |
Correct |
11 ms |
14572 KB |
n=500 |
36 |
Correct |
11 ms |
14572 KB |
n=500 |
37 |
Correct |
11 ms |
14572 KB |
n=500 |
38 |
Correct |
11 ms |
14572 KB |
n=500 |
39 |
Correct |
11 ms |
14572 KB |
n=500 |
40 |
Correct |
11 ms |
14572 KB |
n=500 |
41 |
Correct |
11 ms |
14572 KB |
n=500 |
42 |
Correct |
11 ms |
14572 KB |
n=500 |
43 |
Correct |
11 ms |
14572 KB |
n=500 |
44 |
Correct |
11 ms |
14572 KB |
n=500 |
45 |
Correct |
11 ms |
14572 KB |
n=500 |
46 |
Correct |
11 ms |
14572 KB |
n=500 |
47 |
Correct |
11 ms |
14572 KB |
n=500 |
48 |
Correct |
11 ms |
14572 KB |
n=500 |
49 |
Correct |
11 ms |
14588 KB |
n=500 |
50 |
Correct |
11 ms |
14572 KB |
n=500 |
51 |
Correct |
11 ms |
14572 KB |
n=500 |
52 |
Correct |
12 ms |
14572 KB |
n=500 |
53 |
Correct |
11 ms |
14572 KB |
n=500 |
54 |
Correct |
12 ms |
14572 KB |
n=500 |
55 |
Correct |
12 ms |
14572 KB |
n=278 |
56 |
Correct |
11 ms |
14572 KB |
n=500 |
57 |
Correct |
11 ms |
14572 KB |
n=500 |
58 |
Correct |
11 ms |
14572 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
n=5 |
2 |
Correct |
10 ms |
14444 KB |
n=100 |
3 |
Correct |
10 ms |
14444 KB |
n=100 |
4 |
Correct |
10 ms |
14444 KB |
n=100 |
5 |
Correct |
10 ms |
14444 KB |
n=100 |
6 |
Correct |
11 ms |
14444 KB |
n=100 |
7 |
Correct |
10 ms |
14444 KB |
n=100 |
8 |
Correct |
10 ms |
14444 KB |
n=100 |
9 |
Correct |
10 ms |
14444 KB |
n=100 |
10 |
Correct |
11 ms |
14444 KB |
n=100 |
11 |
Correct |
10 ms |
14572 KB |
n=100 |
12 |
Correct |
10 ms |
14444 KB |
n=100 |
13 |
Correct |
10 ms |
14444 KB |
n=100 |
14 |
Correct |
10 ms |
14444 KB |
n=100 |
15 |
Correct |
10 ms |
14444 KB |
n=100 |
16 |
Correct |
10 ms |
14444 KB |
n=100 |
17 |
Correct |
10 ms |
14444 KB |
n=100 |
18 |
Correct |
10 ms |
14444 KB |
n=100 |
19 |
Correct |
10 ms |
14444 KB |
n=100 |
20 |
Correct |
10 ms |
14444 KB |
n=100 |
21 |
Correct |
10 ms |
14444 KB |
n=100 |
22 |
Correct |
10 ms |
14444 KB |
n=100 |
23 |
Correct |
10 ms |
14444 KB |
n=100 |
24 |
Correct |
10 ms |
14444 KB |
n=100 |
25 |
Correct |
10 ms |
14464 KB |
n=100 |
26 |
Correct |
10 ms |
14444 KB |
n=12 |
27 |
Correct |
10 ms |
14444 KB |
n=100 |
28 |
Correct |
11 ms |
14572 KB |
n=500 |
29 |
Correct |
11 ms |
14572 KB |
n=500 |
30 |
Correct |
11 ms |
14572 KB |
n=500 |
31 |
Correct |
11 ms |
14572 KB |
n=500 |
32 |
Correct |
11 ms |
14572 KB |
n=500 |
33 |
Correct |
11 ms |
14572 KB |
n=500 |
34 |
Correct |
11 ms |
14572 KB |
n=500 |
35 |
Correct |
11 ms |
14572 KB |
n=500 |
36 |
Correct |
11 ms |
14572 KB |
n=500 |
37 |
Correct |
11 ms |
14572 KB |
n=500 |
38 |
Correct |
11 ms |
14572 KB |
n=500 |
39 |
Correct |
11 ms |
14572 KB |
n=500 |
40 |
Correct |
11 ms |
14572 KB |
n=500 |
41 |
Correct |
11 ms |
14572 KB |
n=500 |
42 |
Correct |
11 ms |
14572 KB |
n=500 |
43 |
Correct |
11 ms |
14572 KB |
n=500 |
44 |
Correct |
11 ms |
14572 KB |
n=500 |
45 |
Correct |
11 ms |
14572 KB |
n=500 |
46 |
Correct |
11 ms |
14572 KB |
n=500 |
47 |
Correct |
11 ms |
14572 KB |
n=500 |
48 |
Correct |
11 ms |
14572 KB |
n=500 |
49 |
Correct |
11 ms |
14588 KB |
n=500 |
50 |
Correct |
11 ms |
14572 KB |
n=500 |
51 |
Correct |
11 ms |
14572 KB |
n=500 |
52 |
Correct |
12 ms |
14572 KB |
n=500 |
53 |
Correct |
11 ms |
14572 KB |
n=500 |
54 |
Correct |
12 ms |
14572 KB |
n=500 |
55 |
Correct |
12 ms |
14572 KB |
n=278 |
56 |
Correct |
11 ms |
14572 KB |
n=500 |
57 |
Correct |
11 ms |
14572 KB |
n=500 |
58 |
Correct |
11 ms |
14572 KB |
n=500 |
59 |
Correct |
15 ms |
14956 KB |
n=2000 |
60 |
Correct |
16 ms |
14956 KB |
n=2000 |
61 |
Correct |
14 ms |
14956 KB |
n=2000 |
62 |
Correct |
13 ms |
14956 KB |
n=2000 |
63 |
Correct |
16 ms |
14960 KB |
n=2000 |
64 |
Correct |
14 ms |
14956 KB |
n=2000 |
65 |
Correct |
14 ms |
14956 KB |
n=2000 |
66 |
Correct |
14 ms |
14956 KB |
n=2000 |
67 |
Correct |
17 ms |
14956 KB |
n=2000 |
68 |
Correct |
14 ms |
14956 KB |
n=2000 |
69 |
Correct |
14 ms |
14956 KB |
n=2000 |
70 |
Correct |
14 ms |
14956 KB |
n=2000 |
71 |
Correct |
16 ms |
14956 KB |
n=2000 |
72 |
Correct |
14 ms |
14956 KB |
n=2000 |
73 |
Correct |
13 ms |
14956 KB |
n=2000 |
74 |
Correct |
14 ms |
14836 KB |
n=1844 |
75 |
Correct |
14 ms |
14956 KB |
n=2000 |
76 |
Correct |
14 ms |
14956 KB |
n=2000 |
77 |
Correct |
13 ms |
14956 KB |
n=2000 |
78 |
Correct |
16 ms |
14956 KB |
n=2000 |
79 |
Correct |
16 ms |
14916 KB |
n=2000 |
80 |
Correct |
13 ms |
14956 KB |
n=2000 |
81 |
Correct |
16 ms |
14956 KB |
n=2000 |
82 |
Correct |
14 ms |
14956 KB |
n=2000 |
83 |
Correct |
13 ms |
14956 KB |
n=2000 |
84 |
Correct |
14 ms |
14956 KB |
n=2000 |
85 |
Correct |
14 ms |
14956 KB |
n=2000 |
86 |
Correct |
15 ms |
14956 KB |
n=2000 |
87 |
Correct |
14 ms |
14956 KB |
n=2000 |
88 |
Correct |
13 ms |
14956 KB |
n=2000 |
89 |
Correct |
13 ms |
14956 KB |
n=2000 |
90 |
Correct |
15 ms |
14956 KB |
n=2000 |
91 |
Correct |
14 ms |
14956 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
n=5 |
2 |
Correct |
10 ms |
14444 KB |
n=100 |
3 |
Correct |
10 ms |
14444 KB |
n=100 |
4 |
Correct |
10 ms |
14444 KB |
n=100 |
5 |
Correct |
10 ms |
14444 KB |
n=100 |
6 |
Correct |
11 ms |
14444 KB |
n=100 |
7 |
Correct |
10 ms |
14444 KB |
n=100 |
8 |
Correct |
10 ms |
14444 KB |
n=100 |
9 |
Correct |
10 ms |
14444 KB |
n=100 |
10 |
Correct |
11 ms |
14444 KB |
n=100 |
11 |
Correct |
10 ms |
14572 KB |
n=100 |
12 |
Correct |
10 ms |
14444 KB |
n=100 |
13 |
Correct |
10 ms |
14444 KB |
n=100 |
14 |
Correct |
10 ms |
14444 KB |
n=100 |
15 |
Correct |
10 ms |
14444 KB |
n=100 |
16 |
Correct |
10 ms |
14444 KB |
n=100 |
17 |
Correct |
10 ms |
14444 KB |
n=100 |
18 |
Correct |
10 ms |
14444 KB |
n=100 |
19 |
Correct |
10 ms |
14444 KB |
n=100 |
20 |
Correct |
10 ms |
14444 KB |
n=100 |
21 |
Correct |
10 ms |
14444 KB |
n=100 |
22 |
Correct |
10 ms |
14444 KB |
n=100 |
23 |
Correct |
10 ms |
14444 KB |
n=100 |
24 |
Correct |
10 ms |
14444 KB |
n=100 |
25 |
Correct |
10 ms |
14464 KB |
n=100 |
26 |
Correct |
10 ms |
14444 KB |
n=12 |
27 |
Correct |
10 ms |
14444 KB |
n=100 |
28 |
Correct |
11 ms |
14572 KB |
n=500 |
29 |
Correct |
11 ms |
14572 KB |
n=500 |
30 |
Correct |
11 ms |
14572 KB |
n=500 |
31 |
Correct |
11 ms |
14572 KB |
n=500 |
32 |
Correct |
11 ms |
14572 KB |
n=500 |
33 |
Correct |
11 ms |
14572 KB |
n=500 |
34 |
Correct |
11 ms |
14572 KB |
n=500 |
35 |
Correct |
11 ms |
14572 KB |
n=500 |
36 |
Correct |
11 ms |
14572 KB |
n=500 |
37 |
Correct |
11 ms |
14572 KB |
n=500 |
38 |
Correct |
11 ms |
14572 KB |
n=500 |
39 |
Correct |
11 ms |
14572 KB |
n=500 |
40 |
Correct |
11 ms |
14572 KB |
n=500 |
41 |
Correct |
11 ms |
14572 KB |
n=500 |
42 |
Correct |
11 ms |
14572 KB |
n=500 |
43 |
Correct |
11 ms |
14572 KB |
n=500 |
44 |
Correct |
11 ms |
14572 KB |
n=500 |
45 |
Correct |
11 ms |
14572 KB |
n=500 |
46 |
Correct |
11 ms |
14572 KB |
n=500 |
47 |
Correct |
11 ms |
14572 KB |
n=500 |
48 |
Correct |
11 ms |
14572 KB |
n=500 |
49 |
Correct |
11 ms |
14588 KB |
n=500 |
50 |
Correct |
11 ms |
14572 KB |
n=500 |
51 |
Correct |
11 ms |
14572 KB |
n=500 |
52 |
Correct |
12 ms |
14572 KB |
n=500 |
53 |
Correct |
11 ms |
14572 KB |
n=500 |
54 |
Correct |
12 ms |
14572 KB |
n=500 |
55 |
Correct |
12 ms |
14572 KB |
n=278 |
56 |
Correct |
11 ms |
14572 KB |
n=500 |
57 |
Correct |
11 ms |
14572 KB |
n=500 |
58 |
Correct |
11 ms |
14572 KB |
n=500 |
59 |
Correct |
15 ms |
14956 KB |
n=2000 |
60 |
Correct |
16 ms |
14956 KB |
n=2000 |
61 |
Correct |
14 ms |
14956 KB |
n=2000 |
62 |
Correct |
13 ms |
14956 KB |
n=2000 |
63 |
Correct |
16 ms |
14960 KB |
n=2000 |
64 |
Correct |
14 ms |
14956 KB |
n=2000 |
65 |
Correct |
14 ms |
14956 KB |
n=2000 |
66 |
Correct |
14 ms |
14956 KB |
n=2000 |
67 |
Correct |
17 ms |
14956 KB |
n=2000 |
68 |
Correct |
14 ms |
14956 KB |
n=2000 |
69 |
Correct |
14 ms |
14956 KB |
n=2000 |
70 |
Correct |
14 ms |
14956 KB |
n=2000 |
71 |
Correct |
16 ms |
14956 KB |
n=2000 |
72 |
Correct |
14 ms |
14956 KB |
n=2000 |
73 |
Correct |
13 ms |
14956 KB |
n=2000 |
74 |
Correct |
14 ms |
14836 KB |
n=1844 |
75 |
Correct |
14 ms |
14956 KB |
n=2000 |
76 |
Correct |
14 ms |
14956 KB |
n=2000 |
77 |
Correct |
13 ms |
14956 KB |
n=2000 |
78 |
Correct |
16 ms |
14956 KB |
n=2000 |
79 |
Correct |
16 ms |
14916 KB |
n=2000 |
80 |
Correct |
13 ms |
14956 KB |
n=2000 |
81 |
Correct |
16 ms |
14956 KB |
n=2000 |
82 |
Correct |
14 ms |
14956 KB |
n=2000 |
83 |
Correct |
13 ms |
14956 KB |
n=2000 |
84 |
Correct |
14 ms |
14956 KB |
n=2000 |
85 |
Correct |
14 ms |
14956 KB |
n=2000 |
86 |
Correct |
15 ms |
14956 KB |
n=2000 |
87 |
Correct |
14 ms |
14956 KB |
n=2000 |
88 |
Correct |
13 ms |
14956 KB |
n=2000 |
89 |
Correct |
13 ms |
14956 KB |
n=2000 |
90 |
Correct |
15 ms |
14956 KB |
n=2000 |
91 |
Correct |
14 ms |
14956 KB |
n=2000 |
92 |
Correct |
799 ms |
60184 KB |
n=200000 |
93 |
Correct |
1057 ms |
69188 KB |
n=200000 |
94 |
Correct |
1012 ms |
77664 KB |
n=200000 |
95 |
Correct |
785 ms |
66608 KB |
n=200000 |
96 |
Correct |
838 ms |
66872 KB |
n=200000 |
97 |
Correct |
1049 ms |
72092 KB |
n=200000 |
98 |
Correct |
785 ms |
66540 KB |
n=200000 |
99 |
Correct |
918 ms |
66872 KB |
n=200000 |
100 |
Correct |
831 ms |
66788 KB |
n=200000 |
101 |
Correct |
898 ms |
79596 KB |
n=200000 |
102 |
Correct |
517 ms |
67764 KB |
n=200000 |
103 |
Correct |
499 ms |
67820 KB |
n=200000 |
104 |
Correct |
499 ms |
67808 KB |
n=200000 |
105 |
Correct |
520 ms |
68204 KB |
n=200000 |
106 |
Correct |
511 ms |
68204 KB |
n=200000 |
107 |
Correct |
516 ms |
68340 KB |
n=200000 |
108 |
Correct |
839 ms |
66668 KB |
n=200000 |
109 |
Correct |
839 ms |
66832 KB |
n=200000 |
110 |
Correct |
844 ms |
66820 KB |
n=200000 |
111 |
Correct |
825 ms |
66348 KB |
n=200000 |
112 |
Correct |
886 ms |
78060 KB |
n=200000 |
113 |
Correct |
1036 ms |
72060 KB |
n=200000 |
114 |
Correct |
804 ms |
66232 KB |
n=200000 |
115 |
Correct |
1151 ms |
69356 KB |
n=200000 |
116 |
Correct |
742 ms |
66920 KB |
n=200000 |
117 |
Correct |
892 ms |
78828 KB |
n=200000 |
118 |
Correct |
1033 ms |
70644 KB |
n=200000 |
119 |
Correct |
722 ms |
67008 KB |
n=200000 |
120 |
Correct |
816 ms |
78444 KB |
n=200000 |
121 |
Correct |
841 ms |
78520 KB |
n=200000 |
122 |
Correct |
876 ms |
78744 KB |
n=200000 |
123 |
Correct |
515 ms |
68204 KB |
n=200000 |
124 |
Correct |
211 ms |
30188 KB |
n=25264 |