#include <iostream>
#include <vector>
#include <set>
#define LOG 20
#define MAX 200000
using namespace std;
///ifstream cin ("c.in");
///ofstream cout ("c.out");
int a[MAX + 10], level[MAX + 10], ancestor[LOG + 10][MAX + 10];
vector <int> graph[MAX + 10];
set <int> posSequence[MAX + 10], posLca[MAX + 10];
void dfs(int node, int parent, int depth)
{
level[node] = depth;
for (auto next : graph[node])
if (next != parent)
{
ancestor[0][next] = node;
dfs(next, node, depth + 1);
}
}
int lca(int x, int y)
{
if (level[y] > level[x])
swap(x, y);
for (int p = LOG; p >= 0; p--)
if (level[ancestor[p][x]] >= level[y])
x = ancestor[p][x];
if (x == y)
return x;
for (int p = LOG; p >= 0; p--)
if (ancestor[p][x] != ancestor[p][y])
{
x = ancestor[p][x];
y = ancestor[p][y];
}
return ancestor[0][x];
}
int main()
{
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i < n; i++)
{
int x, y;
cin >> x >> y;
graph[x].push_back(y);
graph[y].push_back(x);
}
for (int p = 0; p <= LOG; p++)
ancestor[p][1] = 1;
dfs(1, 0, 0);
for (int p = 1; p <= LOG; p++)
for (int node = 2; node <= n; node++)
ancestor[p][node] = ancestor[p - 1][ancestor[p - 1][node]];
for (int i = 1; i <= m; i++)
{
cin >> a[i];
posSequence[a[i]].insert(i);
}
for (int i = 1; i < m; i++)
posLca[lca(a[i], a[i + 1])].insert(i);
for (int qq = 1; qq <= q; qq++)
{
int type;
cin >> type;
if (type == 1)
{
int pos, val;
cin >> pos >> val;
posSequence[a[pos]].erase(pos);
posSequence[val].insert(pos);
if (pos < n)
{
posLca[lca(a[pos], a[pos + 1])].erase(pos);
posLca[lca(val, a[pos + 1])].insert(pos);
}
if (pos > 1)
{
posLca[lca(a[pos - 1], a[pos])].erase(pos - 1);
posLca[lca(a[pos - 1], val)].insert(pos - 1);
}
a[pos] = val;
}
else
{
int l, r, valLca;
cin >> l >> r >> valLca;
auto it = posSequence[valLca].lower_bound(l);
if (it != posSequence[valLca].end() && *it <= r)
cout << *it << ' ' << *it << '\n';
else
{
it = posLca[valLca].lower_bound(l);
if (it != posLca[valLca].end() && *it < r)
cout << *it << ' ' << (*it) + 1 << '\n';
else
cout << "-1 1\n";
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23892 KB |
n=5 |
2 |
Correct |
12 ms |
23872 KB |
n=100 |
3 |
Correct |
12 ms |
23932 KB |
n=100 |
4 |
Correct |
13 ms |
23892 KB |
n=100 |
5 |
Correct |
12 ms |
23892 KB |
n=100 |
6 |
Correct |
12 ms |
23892 KB |
n=100 |
7 |
Correct |
13 ms |
23892 KB |
n=100 |
8 |
Correct |
12 ms |
23892 KB |
n=100 |
9 |
Correct |
13 ms |
23824 KB |
n=100 |
10 |
Correct |
12 ms |
23892 KB |
n=100 |
11 |
Correct |
12 ms |
23892 KB |
n=100 |
12 |
Correct |
13 ms |
23892 KB |
n=100 |
13 |
Correct |
13 ms |
23876 KB |
n=100 |
14 |
Correct |
13 ms |
23848 KB |
n=100 |
15 |
Correct |
14 ms |
23892 KB |
n=100 |
16 |
Correct |
14 ms |
23924 KB |
n=100 |
17 |
Correct |
13 ms |
23892 KB |
n=100 |
18 |
Correct |
12 ms |
23892 KB |
n=100 |
19 |
Correct |
13 ms |
23892 KB |
n=100 |
20 |
Correct |
12 ms |
23892 KB |
n=100 |
21 |
Correct |
13 ms |
23892 KB |
n=100 |
22 |
Correct |
12 ms |
23892 KB |
n=100 |
23 |
Correct |
13 ms |
23868 KB |
n=100 |
24 |
Correct |
13 ms |
23928 KB |
n=100 |
25 |
Correct |
15 ms |
23932 KB |
n=100 |
26 |
Correct |
13 ms |
23800 KB |
n=12 |
27 |
Correct |
12 ms |
23892 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23892 KB |
n=5 |
2 |
Correct |
12 ms |
23872 KB |
n=100 |
3 |
Correct |
12 ms |
23932 KB |
n=100 |
4 |
Correct |
13 ms |
23892 KB |
n=100 |
5 |
Correct |
12 ms |
23892 KB |
n=100 |
6 |
Correct |
12 ms |
23892 KB |
n=100 |
7 |
Correct |
13 ms |
23892 KB |
n=100 |
8 |
Correct |
12 ms |
23892 KB |
n=100 |
9 |
Correct |
13 ms |
23824 KB |
n=100 |
10 |
Correct |
12 ms |
23892 KB |
n=100 |
11 |
Correct |
12 ms |
23892 KB |
n=100 |
12 |
Correct |
13 ms |
23892 KB |
n=100 |
13 |
Correct |
13 ms |
23876 KB |
n=100 |
14 |
Correct |
13 ms |
23848 KB |
n=100 |
15 |
Correct |
14 ms |
23892 KB |
n=100 |
16 |
Correct |
14 ms |
23924 KB |
n=100 |
17 |
Correct |
13 ms |
23892 KB |
n=100 |
18 |
Correct |
12 ms |
23892 KB |
n=100 |
19 |
Correct |
13 ms |
23892 KB |
n=100 |
20 |
Correct |
12 ms |
23892 KB |
n=100 |
21 |
Correct |
13 ms |
23892 KB |
n=100 |
22 |
Correct |
12 ms |
23892 KB |
n=100 |
23 |
Correct |
13 ms |
23868 KB |
n=100 |
24 |
Correct |
13 ms |
23928 KB |
n=100 |
25 |
Correct |
15 ms |
23932 KB |
n=100 |
26 |
Correct |
13 ms |
23800 KB |
n=12 |
27 |
Correct |
12 ms |
23892 KB |
n=100 |
28 |
Correct |
15 ms |
23936 KB |
n=500 |
29 |
Correct |
16 ms |
24020 KB |
n=500 |
30 |
Correct |
14 ms |
23932 KB |
n=500 |
31 |
Correct |
14 ms |
23972 KB |
n=500 |
32 |
Correct |
14 ms |
23944 KB |
n=500 |
33 |
Correct |
14 ms |
24020 KB |
n=500 |
34 |
Correct |
14 ms |
23916 KB |
n=500 |
35 |
Correct |
14 ms |
24020 KB |
n=500 |
36 |
Correct |
14 ms |
23980 KB |
n=500 |
37 |
Correct |
14 ms |
24020 KB |
n=500 |
38 |
Correct |
14 ms |
23944 KB |
n=500 |
39 |
Correct |
13 ms |
24020 KB |
n=500 |
40 |
Correct |
13 ms |
24020 KB |
n=500 |
41 |
Correct |
14 ms |
24020 KB |
n=500 |
42 |
Correct |
15 ms |
24020 KB |
n=500 |
43 |
Correct |
14 ms |
24020 KB |
n=500 |
44 |
Correct |
14 ms |
24020 KB |
n=500 |
45 |
Correct |
14 ms |
24020 KB |
n=500 |
46 |
Correct |
14 ms |
23924 KB |
n=500 |
47 |
Correct |
14 ms |
24020 KB |
n=500 |
48 |
Correct |
14 ms |
24020 KB |
n=500 |
49 |
Correct |
14 ms |
24020 KB |
n=500 |
50 |
Correct |
14 ms |
24020 KB |
n=500 |
51 |
Correct |
14 ms |
24020 KB |
n=500 |
52 |
Correct |
15 ms |
24020 KB |
n=500 |
53 |
Correct |
16 ms |
24016 KB |
n=500 |
54 |
Correct |
16 ms |
23984 KB |
n=500 |
55 |
Correct |
14 ms |
23892 KB |
n=278 |
56 |
Correct |
15 ms |
24020 KB |
n=500 |
57 |
Correct |
14 ms |
24020 KB |
n=500 |
58 |
Correct |
15 ms |
24020 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23892 KB |
n=5 |
2 |
Correct |
12 ms |
23872 KB |
n=100 |
3 |
Correct |
12 ms |
23932 KB |
n=100 |
4 |
Correct |
13 ms |
23892 KB |
n=100 |
5 |
Correct |
12 ms |
23892 KB |
n=100 |
6 |
Correct |
12 ms |
23892 KB |
n=100 |
7 |
Correct |
13 ms |
23892 KB |
n=100 |
8 |
Correct |
12 ms |
23892 KB |
n=100 |
9 |
Correct |
13 ms |
23824 KB |
n=100 |
10 |
Correct |
12 ms |
23892 KB |
n=100 |
11 |
Correct |
12 ms |
23892 KB |
n=100 |
12 |
Correct |
13 ms |
23892 KB |
n=100 |
13 |
Correct |
13 ms |
23876 KB |
n=100 |
14 |
Correct |
13 ms |
23848 KB |
n=100 |
15 |
Correct |
14 ms |
23892 KB |
n=100 |
16 |
Correct |
14 ms |
23924 KB |
n=100 |
17 |
Correct |
13 ms |
23892 KB |
n=100 |
18 |
Correct |
12 ms |
23892 KB |
n=100 |
19 |
Correct |
13 ms |
23892 KB |
n=100 |
20 |
Correct |
12 ms |
23892 KB |
n=100 |
21 |
Correct |
13 ms |
23892 KB |
n=100 |
22 |
Correct |
12 ms |
23892 KB |
n=100 |
23 |
Correct |
13 ms |
23868 KB |
n=100 |
24 |
Correct |
13 ms |
23928 KB |
n=100 |
25 |
Correct |
15 ms |
23932 KB |
n=100 |
26 |
Correct |
13 ms |
23800 KB |
n=12 |
27 |
Correct |
12 ms |
23892 KB |
n=100 |
28 |
Correct |
15 ms |
23936 KB |
n=500 |
29 |
Correct |
16 ms |
24020 KB |
n=500 |
30 |
Correct |
14 ms |
23932 KB |
n=500 |
31 |
Correct |
14 ms |
23972 KB |
n=500 |
32 |
Correct |
14 ms |
23944 KB |
n=500 |
33 |
Correct |
14 ms |
24020 KB |
n=500 |
34 |
Correct |
14 ms |
23916 KB |
n=500 |
35 |
Correct |
14 ms |
24020 KB |
n=500 |
36 |
Correct |
14 ms |
23980 KB |
n=500 |
37 |
Correct |
14 ms |
24020 KB |
n=500 |
38 |
Correct |
14 ms |
23944 KB |
n=500 |
39 |
Correct |
13 ms |
24020 KB |
n=500 |
40 |
Correct |
13 ms |
24020 KB |
n=500 |
41 |
Correct |
14 ms |
24020 KB |
n=500 |
42 |
Correct |
15 ms |
24020 KB |
n=500 |
43 |
Correct |
14 ms |
24020 KB |
n=500 |
44 |
Correct |
14 ms |
24020 KB |
n=500 |
45 |
Correct |
14 ms |
24020 KB |
n=500 |
46 |
Correct |
14 ms |
23924 KB |
n=500 |
47 |
Correct |
14 ms |
24020 KB |
n=500 |
48 |
Correct |
14 ms |
24020 KB |
n=500 |
49 |
Correct |
14 ms |
24020 KB |
n=500 |
50 |
Correct |
14 ms |
24020 KB |
n=500 |
51 |
Correct |
14 ms |
24020 KB |
n=500 |
52 |
Correct |
15 ms |
24020 KB |
n=500 |
53 |
Correct |
16 ms |
24016 KB |
n=500 |
54 |
Correct |
16 ms |
23984 KB |
n=500 |
55 |
Correct |
14 ms |
23892 KB |
n=278 |
56 |
Correct |
15 ms |
24020 KB |
n=500 |
57 |
Correct |
14 ms |
24020 KB |
n=500 |
58 |
Correct |
15 ms |
24020 KB |
n=500 |
59 |
Correct |
19 ms |
24276 KB |
n=2000 |
60 |
Correct |
19 ms |
24368 KB |
n=2000 |
61 |
Correct |
20 ms |
24328 KB |
n=2000 |
62 |
Correct |
20 ms |
24336 KB |
n=2000 |
63 |
Correct |
20 ms |
24308 KB |
n=2000 |
64 |
Correct |
20 ms |
24336 KB |
n=2000 |
65 |
Correct |
20 ms |
24296 KB |
n=2000 |
66 |
Correct |
20 ms |
24276 KB |
n=2000 |
67 |
Correct |
19 ms |
24276 KB |
n=2000 |
68 |
Correct |
21 ms |
24276 KB |
n=2000 |
69 |
Correct |
24 ms |
24276 KB |
n=2000 |
70 |
Correct |
18 ms |
24240 KB |
n=2000 |
71 |
Correct |
19 ms |
24276 KB |
n=2000 |
72 |
Correct |
20 ms |
24436 KB |
n=2000 |
73 |
Correct |
19 ms |
24276 KB |
n=2000 |
74 |
Correct |
19 ms |
24276 KB |
n=1844 |
75 |
Correct |
21 ms |
24448 KB |
n=2000 |
76 |
Correct |
20 ms |
24276 KB |
n=2000 |
77 |
Correct |
19 ms |
24320 KB |
n=2000 |
78 |
Correct |
19 ms |
24276 KB |
n=2000 |
79 |
Correct |
19 ms |
24260 KB |
n=2000 |
80 |
Correct |
19 ms |
24276 KB |
n=2000 |
81 |
Correct |
19 ms |
24276 KB |
n=2000 |
82 |
Correct |
23 ms |
24304 KB |
n=2000 |
83 |
Correct |
19 ms |
24276 KB |
n=2000 |
84 |
Correct |
22 ms |
24348 KB |
n=2000 |
85 |
Correct |
19 ms |
24248 KB |
n=2000 |
86 |
Correct |
19 ms |
24240 KB |
n=2000 |
87 |
Correct |
19 ms |
24304 KB |
n=2000 |
88 |
Correct |
19 ms |
24276 KB |
n=2000 |
89 |
Correct |
20 ms |
24404 KB |
n=2000 |
90 |
Correct |
21 ms |
24440 KB |
n=2000 |
91 |
Correct |
18 ms |
24276 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23892 KB |
n=5 |
2 |
Correct |
12 ms |
23872 KB |
n=100 |
3 |
Correct |
12 ms |
23932 KB |
n=100 |
4 |
Correct |
13 ms |
23892 KB |
n=100 |
5 |
Correct |
12 ms |
23892 KB |
n=100 |
6 |
Correct |
12 ms |
23892 KB |
n=100 |
7 |
Correct |
13 ms |
23892 KB |
n=100 |
8 |
Correct |
12 ms |
23892 KB |
n=100 |
9 |
Correct |
13 ms |
23824 KB |
n=100 |
10 |
Correct |
12 ms |
23892 KB |
n=100 |
11 |
Correct |
12 ms |
23892 KB |
n=100 |
12 |
Correct |
13 ms |
23892 KB |
n=100 |
13 |
Correct |
13 ms |
23876 KB |
n=100 |
14 |
Correct |
13 ms |
23848 KB |
n=100 |
15 |
Correct |
14 ms |
23892 KB |
n=100 |
16 |
Correct |
14 ms |
23924 KB |
n=100 |
17 |
Correct |
13 ms |
23892 KB |
n=100 |
18 |
Correct |
12 ms |
23892 KB |
n=100 |
19 |
Correct |
13 ms |
23892 KB |
n=100 |
20 |
Correct |
12 ms |
23892 KB |
n=100 |
21 |
Correct |
13 ms |
23892 KB |
n=100 |
22 |
Correct |
12 ms |
23892 KB |
n=100 |
23 |
Correct |
13 ms |
23868 KB |
n=100 |
24 |
Correct |
13 ms |
23928 KB |
n=100 |
25 |
Correct |
15 ms |
23932 KB |
n=100 |
26 |
Correct |
13 ms |
23800 KB |
n=12 |
27 |
Correct |
12 ms |
23892 KB |
n=100 |
28 |
Correct |
15 ms |
23936 KB |
n=500 |
29 |
Correct |
16 ms |
24020 KB |
n=500 |
30 |
Correct |
14 ms |
23932 KB |
n=500 |
31 |
Correct |
14 ms |
23972 KB |
n=500 |
32 |
Correct |
14 ms |
23944 KB |
n=500 |
33 |
Correct |
14 ms |
24020 KB |
n=500 |
34 |
Correct |
14 ms |
23916 KB |
n=500 |
35 |
Correct |
14 ms |
24020 KB |
n=500 |
36 |
Correct |
14 ms |
23980 KB |
n=500 |
37 |
Correct |
14 ms |
24020 KB |
n=500 |
38 |
Correct |
14 ms |
23944 KB |
n=500 |
39 |
Correct |
13 ms |
24020 KB |
n=500 |
40 |
Correct |
13 ms |
24020 KB |
n=500 |
41 |
Correct |
14 ms |
24020 KB |
n=500 |
42 |
Correct |
15 ms |
24020 KB |
n=500 |
43 |
Correct |
14 ms |
24020 KB |
n=500 |
44 |
Correct |
14 ms |
24020 KB |
n=500 |
45 |
Correct |
14 ms |
24020 KB |
n=500 |
46 |
Correct |
14 ms |
23924 KB |
n=500 |
47 |
Correct |
14 ms |
24020 KB |
n=500 |
48 |
Correct |
14 ms |
24020 KB |
n=500 |
49 |
Correct |
14 ms |
24020 KB |
n=500 |
50 |
Correct |
14 ms |
24020 KB |
n=500 |
51 |
Correct |
14 ms |
24020 KB |
n=500 |
52 |
Correct |
15 ms |
24020 KB |
n=500 |
53 |
Correct |
16 ms |
24016 KB |
n=500 |
54 |
Correct |
16 ms |
23984 KB |
n=500 |
55 |
Correct |
14 ms |
23892 KB |
n=278 |
56 |
Correct |
15 ms |
24020 KB |
n=500 |
57 |
Correct |
14 ms |
24020 KB |
n=500 |
58 |
Correct |
15 ms |
24020 KB |
n=500 |
59 |
Correct |
19 ms |
24276 KB |
n=2000 |
60 |
Correct |
19 ms |
24368 KB |
n=2000 |
61 |
Correct |
20 ms |
24328 KB |
n=2000 |
62 |
Correct |
20 ms |
24336 KB |
n=2000 |
63 |
Correct |
20 ms |
24308 KB |
n=2000 |
64 |
Correct |
20 ms |
24336 KB |
n=2000 |
65 |
Correct |
20 ms |
24296 KB |
n=2000 |
66 |
Correct |
20 ms |
24276 KB |
n=2000 |
67 |
Correct |
19 ms |
24276 KB |
n=2000 |
68 |
Correct |
21 ms |
24276 KB |
n=2000 |
69 |
Correct |
24 ms |
24276 KB |
n=2000 |
70 |
Correct |
18 ms |
24240 KB |
n=2000 |
71 |
Correct |
19 ms |
24276 KB |
n=2000 |
72 |
Correct |
20 ms |
24436 KB |
n=2000 |
73 |
Correct |
19 ms |
24276 KB |
n=2000 |
74 |
Correct |
19 ms |
24276 KB |
n=1844 |
75 |
Correct |
21 ms |
24448 KB |
n=2000 |
76 |
Correct |
20 ms |
24276 KB |
n=2000 |
77 |
Correct |
19 ms |
24320 KB |
n=2000 |
78 |
Correct |
19 ms |
24276 KB |
n=2000 |
79 |
Correct |
19 ms |
24260 KB |
n=2000 |
80 |
Correct |
19 ms |
24276 KB |
n=2000 |
81 |
Correct |
19 ms |
24276 KB |
n=2000 |
82 |
Correct |
23 ms |
24304 KB |
n=2000 |
83 |
Correct |
19 ms |
24276 KB |
n=2000 |
84 |
Correct |
22 ms |
24348 KB |
n=2000 |
85 |
Correct |
19 ms |
24248 KB |
n=2000 |
86 |
Correct |
19 ms |
24240 KB |
n=2000 |
87 |
Correct |
19 ms |
24304 KB |
n=2000 |
88 |
Correct |
19 ms |
24276 KB |
n=2000 |
89 |
Correct |
20 ms |
24404 KB |
n=2000 |
90 |
Correct |
21 ms |
24440 KB |
n=2000 |
91 |
Correct |
18 ms |
24276 KB |
n=2000 |
92 |
Correct |
1640 ms |
69032 KB |
n=200000 |
93 |
Correct |
2007 ms |
70660 KB |
n=200000 |
94 |
Correct |
2013 ms |
72516 KB |
n=200000 |
95 |
Correct |
1617 ms |
68856 KB |
n=200000 |
96 |
Correct |
1523 ms |
68880 KB |
n=200000 |
97 |
Correct |
2029 ms |
70028 KB |
n=200000 |
98 |
Correct |
1592 ms |
68948 KB |
n=200000 |
99 |
Correct |
1770 ms |
68208 KB |
n=200000 |
100 |
Correct |
1532 ms |
68896 KB |
n=200000 |
101 |
Correct |
1825 ms |
73088 KB |
n=200000 |
102 |
Correct |
1008 ms |
69880 KB |
n=200000 |
103 |
Correct |
1020 ms |
69780 KB |
n=200000 |
104 |
Correct |
1033 ms |
69728 KB |
n=200000 |
105 |
Correct |
1075 ms |
69476 KB |
n=200000 |
106 |
Correct |
1016 ms |
69692 KB |
n=200000 |
107 |
Correct |
1012 ms |
69580 KB |
n=200000 |
108 |
Correct |
1772 ms |
68612 KB |
n=200000 |
109 |
Correct |
1722 ms |
68596 KB |
n=200000 |
110 |
Correct |
1719 ms |
68636 KB |
n=200000 |
111 |
Correct |
1402 ms |
68824 KB |
n=200000 |
112 |
Correct |
1966 ms |
72384 KB |
n=200000 |
113 |
Correct |
2001 ms |
69952 KB |
n=200000 |
114 |
Correct |
1388 ms |
68624 KB |
n=200000 |
115 |
Correct |
2129 ms |
68816 KB |
n=200000 |
116 |
Correct |
1547 ms |
68464 KB |
n=200000 |
117 |
Correct |
1826 ms |
72620 KB |
n=200000 |
118 |
Correct |
1946 ms |
69348 KB |
n=200000 |
119 |
Correct |
1489 ms |
68536 KB |
n=200000 |
120 |
Correct |
1778 ms |
72780 KB |
n=200000 |
121 |
Correct |
1885 ms |
72728 KB |
n=200000 |
122 |
Correct |
1803 ms |
73140 KB |
n=200000 |
123 |
Correct |
1234 ms |
68984 KB |
n=200000 |
124 |
Incorrect |
355 ms |
36676 KB |
Wrong range. |
125 |
Halted |
0 ms |
0 KB |
- |