#include <bits/stdc++.h>
#define fr first
#define sc second
#define mk make_pair
#define pb emplace_back
#define all(s) s.begin(), s.end()
using namespace std;
const int N = 2e5 + 5;
int n, m, q, x, y, up[20][N], h[N], a[N], type, l, r;
vector < vector <int> > g;
void dfs (int v, int p = 0)
{
h[v] = h[p] + 1;
up[0][v] = p;
for (int i = 1; i < 20; i++)
up[i][v] = up[i - 1][ up[i - 1][v] ];
for (auto to : g[v])
{
if (to == p) continue;
dfs(to, v);
}
}
int lca (int a, int b)
{
if(h[a] > h[b]) swap(a, b);
int cnt = h[b] - h[a];
for (int i = 19; i >= 0; i--)
{
if (cnt & (1 << i) )
b = up[i][b];
}
if (a == b) return a;
assert( h[a] == h[b] );
for (int i = 19; i >= 0; i--)
{
if (up[i][a] != up[i][b])
a = up[i][a], b = up[i][b];
}
return up[0][a];
}
set < pair <int, int> > st, st2;
main()
{
cin >> n >> m >> q;
g.resize(n + 1);
for (int i = 1; i < n; i++)
{
scanf("%d%d", &x, &y);
g[x].pb(y);
g[y].pb(x);
}
dfs(1);
for (int i = 1; i <= m; i++)
{
scanf("%d", &a[i]);
if (i > 1)
st.insert( mk( lca( a[i - 1], a[i] ), i - 1 ) );
st2.insert( mk(a[i], i) );
}
while (q--)
{
scanf("%d%d%d", &type, &l, &r);
if (type == 1){
st2.erase( mk(a[l], l) );
if (l > 1)
st.erase( mk( lca( a[l - 1], a[l] ), l - 1 ) );
if (l < m)
st.erase( mk( lca( a[l], a[l + 1] ), l ) );
a[l] = r;
if (l > 1)
st.insert( mk( lca( a[l - 1], a[l] ), l - 1 ) );
if (l < m)
st.insert( mk( lca( a[l], a[l + 1] ), l ) );
st2.insert( mk(a[l], l) );
}
else{
scanf("%d", &x);
auto it = st2.lower_bound( mk(x, l) );
if ( it != st2.end() && it->fr == x && it->sc <= r )
printf("%d %d\n", it->sc, it->sc);
else
{
auto it = st.lower_bound( mk( x, l ) );
if ( it != st.end() && it->fr == x && it->sc + 1 <= r )
printf("%d %d\n", it->sc, it->sc + 1);
else
printf("-1 -1\n");
}
}
}
}
/**
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
**/
Compilation message
treearray.cpp:55:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
treearray.cpp: In function 'int main()':
treearray.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &x, &y);
~~~~~^~~~~~~~~~~~~~~~
treearray.cpp:70:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
~~~~~^~~~~~~~~~~~~
treearray.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &type, &l, &r);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:94:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &x);
~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=5 |
2 |
Correct |
2 ms |
504 KB |
n=100 |
3 |
Correct |
2 ms |
504 KB |
n=100 |
4 |
Correct |
2 ms |
504 KB |
n=100 |
5 |
Correct |
2 ms |
508 KB |
n=100 |
6 |
Correct |
2 ms |
504 KB |
n=100 |
7 |
Correct |
2 ms |
504 KB |
n=100 |
8 |
Correct |
2 ms |
504 KB |
n=100 |
9 |
Correct |
2 ms |
508 KB |
n=100 |
10 |
Correct |
2 ms |
504 KB |
n=100 |
11 |
Correct |
2 ms |
504 KB |
n=100 |
12 |
Correct |
2 ms |
504 KB |
n=100 |
13 |
Correct |
2 ms |
504 KB |
n=100 |
14 |
Correct |
2 ms |
508 KB |
n=100 |
15 |
Correct |
2 ms |
504 KB |
n=100 |
16 |
Correct |
2 ms |
504 KB |
n=100 |
17 |
Correct |
2 ms |
504 KB |
n=100 |
18 |
Correct |
2 ms |
504 KB |
n=100 |
19 |
Correct |
2 ms |
504 KB |
n=100 |
20 |
Correct |
2 ms |
504 KB |
n=100 |
21 |
Correct |
2 ms |
504 KB |
n=100 |
22 |
Correct |
2 ms |
504 KB |
n=100 |
23 |
Correct |
2 ms |
504 KB |
n=100 |
24 |
Correct |
2 ms |
504 KB |
n=100 |
25 |
Correct |
2 ms |
504 KB |
n=100 |
26 |
Correct |
2 ms |
376 KB |
n=12 |
27 |
Correct |
2 ms |
504 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=5 |
2 |
Correct |
2 ms |
504 KB |
n=100 |
3 |
Correct |
2 ms |
504 KB |
n=100 |
4 |
Correct |
2 ms |
504 KB |
n=100 |
5 |
Correct |
2 ms |
508 KB |
n=100 |
6 |
Correct |
2 ms |
504 KB |
n=100 |
7 |
Correct |
2 ms |
504 KB |
n=100 |
8 |
Correct |
2 ms |
504 KB |
n=100 |
9 |
Correct |
2 ms |
508 KB |
n=100 |
10 |
Correct |
2 ms |
504 KB |
n=100 |
11 |
Correct |
2 ms |
504 KB |
n=100 |
12 |
Correct |
2 ms |
504 KB |
n=100 |
13 |
Correct |
2 ms |
504 KB |
n=100 |
14 |
Correct |
2 ms |
508 KB |
n=100 |
15 |
Correct |
2 ms |
504 KB |
n=100 |
16 |
Correct |
2 ms |
504 KB |
n=100 |
17 |
Correct |
2 ms |
504 KB |
n=100 |
18 |
Correct |
2 ms |
504 KB |
n=100 |
19 |
Correct |
2 ms |
504 KB |
n=100 |
20 |
Correct |
2 ms |
504 KB |
n=100 |
21 |
Correct |
2 ms |
504 KB |
n=100 |
22 |
Correct |
2 ms |
504 KB |
n=100 |
23 |
Correct |
2 ms |
504 KB |
n=100 |
24 |
Correct |
2 ms |
504 KB |
n=100 |
25 |
Correct |
2 ms |
504 KB |
n=100 |
26 |
Correct |
2 ms |
376 KB |
n=12 |
27 |
Correct |
2 ms |
504 KB |
n=100 |
28 |
Correct |
3 ms |
632 KB |
n=500 |
29 |
Correct |
3 ms |
632 KB |
n=500 |
30 |
Correct |
3 ms |
632 KB |
n=500 |
31 |
Correct |
3 ms |
632 KB |
n=500 |
32 |
Correct |
3 ms |
632 KB |
n=500 |
33 |
Correct |
3 ms |
504 KB |
n=500 |
34 |
Correct |
2 ms |
504 KB |
n=500 |
35 |
Correct |
3 ms |
632 KB |
n=500 |
36 |
Correct |
2 ms |
504 KB |
n=500 |
37 |
Correct |
2 ms |
632 KB |
n=500 |
38 |
Correct |
2 ms |
632 KB |
n=500 |
39 |
Correct |
2 ms |
636 KB |
n=500 |
40 |
Correct |
2 ms |
504 KB |
n=500 |
41 |
Correct |
2 ms |
644 KB |
n=500 |
42 |
Correct |
3 ms |
632 KB |
n=500 |
43 |
Correct |
3 ms |
676 KB |
n=500 |
44 |
Correct |
5 ms |
632 KB |
n=500 |
45 |
Correct |
3 ms |
632 KB |
n=500 |
46 |
Correct |
3 ms |
632 KB |
n=500 |
47 |
Correct |
3 ms |
608 KB |
n=500 |
48 |
Correct |
2 ms |
632 KB |
n=500 |
49 |
Correct |
3 ms |
632 KB |
n=500 |
50 |
Correct |
3 ms |
632 KB |
n=500 |
51 |
Correct |
3 ms |
504 KB |
n=500 |
52 |
Correct |
3 ms |
632 KB |
n=500 |
53 |
Correct |
3 ms |
632 KB |
n=500 |
54 |
Correct |
3 ms |
548 KB |
n=500 |
55 |
Correct |
2 ms |
504 KB |
n=278 |
56 |
Correct |
3 ms |
632 KB |
n=500 |
57 |
Correct |
3 ms |
604 KB |
n=500 |
58 |
Correct |
3 ms |
504 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=5 |
2 |
Correct |
2 ms |
504 KB |
n=100 |
3 |
Correct |
2 ms |
504 KB |
n=100 |
4 |
Correct |
2 ms |
504 KB |
n=100 |
5 |
Correct |
2 ms |
508 KB |
n=100 |
6 |
Correct |
2 ms |
504 KB |
n=100 |
7 |
Correct |
2 ms |
504 KB |
n=100 |
8 |
Correct |
2 ms |
504 KB |
n=100 |
9 |
Correct |
2 ms |
508 KB |
n=100 |
10 |
Correct |
2 ms |
504 KB |
n=100 |
11 |
Correct |
2 ms |
504 KB |
n=100 |
12 |
Correct |
2 ms |
504 KB |
n=100 |
13 |
Correct |
2 ms |
504 KB |
n=100 |
14 |
Correct |
2 ms |
508 KB |
n=100 |
15 |
Correct |
2 ms |
504 KB |
n=100 |
16 |
Correct |
2 ms |
504 KB |
n=100 |
17 |
Correct |
2 ms |
504 KB |
n=100 |
18 |
Correct |
2 ms |
504 KB |
n=100 |
19 |
Correct |
2 ms |
504 KB |
n=100 |
20 |
Correct |
2 ms |
504 KB |
n=100 |
21 |
Correct |
2 ms |
504 KB |
n=100 |
22 |
Correct |
2 ms |
504 KB |
n=100 |
23 |
Correct |
2 ms |
504 KB |
n=100 |
24 |
Correct |
2 ms |
504 KB |
n=100 |
25 |
Correct |
2 ms |
504 KB |
n=100 |
26 |
Correct |
2 ms |
376 KB |
n=12 |
27 |
Correct |
2 ms |
504 KB |
n=100 |
28 |
Correct |
3 ms |
632 KB |
n=500 |
29 |
Correct |
3 ms |
632 KB |
n=500 |
30 |
Correct |
3 ms |
632 KB |
n=500 |
31 |
Correct |
3 ms |
632 KB |
n=500 |
32 |
Correct |
3 ms |
632 KB |
n=500 |
33 |
Correct |
3 ms |
504 KB |
n=500 |
34 |
Correct |
2 ms |
504 KB |
n=500 |
35 |
Correct |
3 ms |
632 KB |
n=500 |
36 |
Correct |
2 ms |
504 KB |
n=500 |
37 |
Correct |
2 ms |
632 KB |
n=500 |
38 |
Correct |
2 ms |
632 KB |
n=500 |
39 |
Correct |
2 ms |
636 KB |
n=500 |
40 |
Correct |
2 ms |
504 KB |
n=500 |
41 |
Correct |
2 ms |
644 KB |
n=500 |
42 |
Correct |
3 ms |
632 KB |
n=500 |
43 |
Correct |
3 ms |
676 KB |
n=500 |
44 |
Correct |
5 ms |
632 KB |
n=500 |
45 |
Correct |
3 ms |
632 KB |
n=500 |
46 |
Correct |
3 ms |
632 KB |
n=500 |
47 |
Correct |
3 ms |
608 KB |
n=500 |
48 |
Correct |
2 ms |
632 KB |
n=500 |
49 |
Correct |
3 ms |
632 KB |
n=500 |
50 |
Correct |
3 ms |
632 KB |
n=500 |
51 |
Correct |
3 ms |
504 KB |
n=500 |
52 |
Correct |
3 ms |
632 KB |
n=500 |
53 |
Correct |
3 ms |
632 KB |
n=500 |
54 |
Correct |
3 ms |
548 KB |
n=500 |
55 |
Correct |
2 ms |
504 KB |
n=278 |
56 |
Correct |
3 ms |
632 KB |
n=500 |
57 |
Correct |
3 ms |
604 KB |
n=500 |
58 |
Correct |
3 ms |
504 KB |
n=500 |
59 |
Correct |
6 ms |
1016 KB |
n=2000 |
60 |
Correct |
6 ms |
1016 KB |
n=2000 |
61 |
Correct |
6 ms |
1016 KB |
n=2000 |
62 |
Correct |
7 ms |
1016 KB |
n=2000 |
63 |
Correct |
6 ms |
1016 KB |
n=2000 |
64 |
Correct |
7 ms |
1016 KB |
n=2000 |
65 |
Correct |
6 ms |
1016 KB |
n=2000 |
66 |
Correct |
6 ms |
1016 KB |
n=2000 |
67 |
Correct |
7 ms |
1016 KB |
n=2000 |
68 |
Correct |
6 ms |
1016 KB |
n=2000 |
69 |
Correct |
5 ms |
1016 KB |
n=2000 |
70 |
Correct |
5 ms |
1016 KB |
n=2000 |
71 |
Correct |
5 ms |
1016 KB |
n=2000 |
72 |
Correct |
5 ms |
1016 KB |
n=2000 |
73 |
Correct |
5 ms |
1016 KB |
n=2000 |
74 |
Correct |
6 ms |
1016 KB |
n=1844 |
75 |
Correct |
5 ms |
1016 KB |
n=2000 |
76 |
Correct |
7 ms |
1012 KB |
n=2000 |
77 |
Correct |
7 ms |
1016 KB |
n=2000 |
78 |
Correct |
6 ms |
1016 KB |
n=2000 |
79 |
Correct |
6 ms |
1016 KB |
n=2000 |
80 |
Correct |
6 ms |
1016 KB |
n=2000 |
81 |
Correct |
7 ms |
1016 KB |
n=2000 |
82 |
Correct |
6 ms |
888 KB |
n=2000 |
83 |
Correct |
6 ms |
1016 KB |
n=2000 |
84 |
Correct |
6 ms |
1016 KB |
n=2000 |
85 |
Correct |
7 ms |
1020 KB |
n=2000 |
86 |
Correct |
7 ms |
956 KB |
n=2000 |
87 |
Correct |
7 ms |
1016 KB |
n=2000 |
88 |
Correct |
6 ms |
1016 KB |
n=2000 |
89 |
Correct |
6 ms |
1016 KB |
n=2000 |
90 |
Correct |
6 ms |
988 KB |
n=2000 |
91 |
Correct |
5 ms |
1016 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=5 |
2 |
Correct |
2 ms |
504 KB |
n=100 |
3 |
Correct |
2 ms |
504 KB |
n=100 |
4 |
Correct |
2 ms |
504 KB |
n=100 |
5 |
Correct |
2 ms |
508 KB |
n=100 |
6 |
Correct |
2 ms |
504 KB |
n=100 |
7 |
Correct |
2 ms |
504 KB |
n=100 |
8 |
Correct |
2 ms |
504 KB |
n=100 |
9 |
Correct |
2 ms |
508 KB |
n=100 |
10 |
Correct |
2 ms |
504 KB |
n=100 |
11 |
Correct |
2 ms |
504 KB |
n=100 |
12 |
Correct |
2 ms |
504 KB |
n=100 |
13 |
Correct |
2 ms |
504 KB |
n=100 |
14 |
Correct |
2 ms |
508 KB |
n=100 |
15 |
Correct |
2 ms |
504 KB |
n=100 |
16 |
Correct |
2 ms |
504 KB |
n=100 |
17 |
Correct |
2 ms |
504 KB |
n=100 |
18 |
Correct |
2 ms |
504 KB |
n=100 |
19 |
Correct |
2 ms |
504 KB |
n=100 |
20 |
Correct |
2 ms |
504 KB |
n=100 |
21 |
Correct |
2 ms |
504 KB |
n=100 |
22 |
Correct |
2 ms |
504 KB |
n=100 |
23 |
Correct |
2 ms |
504 KB |
n=100 |
24 |
Correct |
2 ms |
504 KB |
n=100 |
25 |
Correct |
2 ms |
504 KB |
n=100 |
26 |
Correct |
2 ms |
376 KB |
n=12 |
27 |
Correct |
2 ms |
504 KB |
n=100 |
28 |
Correct |
3 ms |
632 KB |
n=500 |
29 |
Correct |
3 ms |
632 KB |
n=500 |
30 |
Correct |
3 ms |
632 KB |
n=500 |
31 |
Correct |
3 ms |
632 KB |
n=500 |
32 |
Correct |
3 ms |
632 KB |
n=500 |
33 |
Correct |
3 ms |
504 KB |
n=500 |
34 |
Correct |
2 ms |
504 KB |
n=500 |
35 |
Correct |
3 ms |
632 KB |
n=500 |
36 |
Correct |
2 ms |
504 KB |
n=500 |
37 |
Correct |
2 ms |
632 KB |
n=500 |
38 |
Correct |
2 ms |
632 KB |
n=500 |
39 |
Correct |
2 ms |
636 KB |
n=500 |
40 |
Correct |
2 ms |
504 KB |
n=500 |
41 |
Correct |
2 ms |
644 KB |
n=500 |
42 |
Correct |
3 ms |
632 KB |
n=500 |
43 |
Correct |
3 ms |
676 KB |
n=500 |
44 |
Correct |
5 ms |
632 KB |
n=500 |
45 |
Correct |
3 ms |
632 KB |
n=500 |
46 |
Correct |
3 ms |
632 KB |
n=500 |
47 |
Correct |
3 ms |
608 KB |
n=500 |
48 |
Correct |
2 ms |
632 KB |
n=500 |
49 |
Correct |
3 ms |
632 KB |
n=500 |
50 |
Correct |
3 ms |
632 KB |
n=500 |
51 |
Correct |
3 ms |
504 KB |
n=500 |
52 |
Correct |
3 ms |
632 KB |
n=500 |
53 |
Correct |
3 ms |
632 KB |
n=500 |
54 |
Correct |
3 ms |
548 KB |
n=500 |
55 |
Correct |
2 ms |
504 KB |
n=278 |
56 |
Correct |
3 ms |
632 KB |
n=500 |
57 |
Correct |
3 ms |
604 KB |
n=500 |
58 |
Correct |
3 ms |
504 KB |
n=500 |
59 |
Correct |
6 ms |
1016 KB |
n=2000 |
60 |
Correct |
6 ms |
1016 KB |
n=2000 |
61 |
Correct |
6 ms |
1016 KB |
n=2000 |
62 |
Correct |
7 ms |
1016 KB |
n=2000 |
63 |
Correct |
6 ms |
1016 KB |
n=2000 |
64 |
Correct |
7 ms |
1016 KB |
n=2000 |
65 |
Correct |
6 ms |
1016 KB |
n=2000 |
66 |
Correct |
6 ms |
1016 KB |
n=2000 |
67 |
Correct |
7 ms |
1016 KB |
n=2000 |
68 |
Correct |
6 ms |
1016 KB |
n=2000 |
69 |
Correct |
5 ms |
1016 KB |
n=2000 |
70 |
Correct |
5 ms |
1016 KB |
n=2000 |
71 |
Correct |
5 ms |
1016 KB |
n=2000 |
72 |
Correct |
5 ms |
1016 KB |
n=2000 |
73 |
Correct |
5 ms |
1016 KB |
n=2000 |
74 |
Correct |
6 ms |
1016 KB |
n=1844 |
75 |
Correct |
5 ms |
1016 KB |
n=2000 |
76 |
Correct |
7 ms |
1012 KB |
n=2000 |
77 |
Correct |
7 ms |
1016 KB |
n=2000 |
78 |
Correct |
6 ms |
1016 KB |
n=2000 |
79 |
Correct |
6 ms |
1016 KB |
n=2000 |
80 |
Correct |
6 ms |
1016 KB |
n=2000 |
81 |
Correct |
7 ms |
1016 KB |
n=2000 |
82 |
Correct |
6 ms |
888 KB |
n=2000 |
83 |
Correct |
6 ms |
1016 KB |
n=2000 |
84 |
Correct |
6 ms |
1016 KB |
n=2000 |
85 |
Correct |
7 ms |
1020 KB |
n=2000 |
86 |
Correct |
7 ms |
956 KB |
n=2000 |
87 |
Correct |
7 ms |
1016 KB |
n=2000 |
88 |
Correct |
6 ms |
1016 KB |
n=2000 |
89 |
Correct |
6 ms |
1016 KB |
n=2000 |
90 |
Correct |
6 ms |
988 KB |
n=2000 |
91 |
Correct |
5 ms |
1016 KB |
n=2000 |
92 |
Correct |
1314 ms |
55768 KB |
n=200000 |
93 |
Correct |
1955 ms |
60940 KB |
n=200000 |
94 |
Correct |
1916 ms |
64040 KB |
n=200000 |
95 |
Correct |
1489 ms |
55788 KB |
n=200000 |
96 |
Correct |
1223 ms |
55736 KB |
n=200000 |
97 |
Correct |
2134 ms |
59836 KB |
n=200000 |
98 |
Correct |
1504 ms |
55672 KB |
n=200000 |
99 |
Correct |
1711 ms |
55856 KB |
n=200000 |
100 |
Correct |
1598 ms |
55704 KB |
n=200000 |
101 |
Correct |
2033 ms |
65436 KB |
n=200000 |
102 |
Correct |
860 ms |
56820 KB |
n=200000 |
103 |
Correct |
795 ms |
56796 KB |
n=200000 |
104 |
Correct |
662 ms |
56908 KB |
n=200000 |
105 |
Correct |
748 ms |
57208 KB |
n=200000 |
106 |
Correct |
756 ms |
57300 KB |
n=200000 |
107 |
Correct |
810 ms |
57076 KB |
n=200000 |
108 |
Correct |
1372 ms |
55608 KB |
n=200000 |
109 |
Correct |
1455 ms |
55728 KB |
n=200000 |
110 |
Correct |
1365 ms |
55896 KB |
n=200000 |
111 |
Correct |
1196 ms |
55224 KB |
n=200000 |
112 |
Correct |
1868 ms |
64296 KB |
n=200000 |
113 |
Correct |
1820 ms |
59772 KB |
n=200000 |
114 |
Correct |
1296 ms |
55172 KB |
n=200000 |
115 |
Correct |
1898 ms |
57668 KB |
n=200000 |
116 |
Correct |
1363 ms |
55968 KB |
n=200000 |
117 |
Correct |
1724 ms |
64724 KB |
n=200000 |
118 |
Correct |
1967 ms |
58732 KB |
n=200000 |
119 |
Correct |
1442 ms |
55836 KB |
n=200000 |
120 |
Correct |
1714 ms |
64352 KB |
n=200000 |
121 |
Correct |
1555 ms |
64392 KB |
n=200000 |
122 |
Correct |
1884 ms |
64604 KB |
n=200000 |
123 |
Correct |
831 ms |
56952 KB |
n=200000 |
124 |
Correct |
353 ms |
16000 KB |
n=25264 |