#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
using namespace std;
const int l = 18;
set <int> v[2 * 100002];
set<int> p[2 * 100002];
int a[2 * 100002];
int up[2 * 100002][l + 1], tin[2 * 100002], tout[2 * 100002], t;
vector<int> g[2 * 100002];
void Dfs(int v, int p)
{
tin[v] = ++t;
up[v][0] = p;
for (int i = 1; i <= l; i++)
if (up[v][i - 1] != -1)
up[v][i] = up[up[v][i - 1]][i - 1];
for (int to : g[v])
if (to != p)
Dfs(to, v);
tout[v] = t;
}
bool IsParent(int a, int b) {
return tin[a] <= tin[b] && tout[a] >= tout[b];
}
int Lca(int a, int b)
{
if (IsParent(a, b))return a;
if (IsParent(b, a))return b;
for (int i = l; i >= 0; --i)
if (up[a][i] != -1 && !IsParent(up[a][i], b))
a = up[a][i];
return up[a][0];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
for (int i = 0; i < n - 1; i++)
{
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
for (int i = 1; i <= n; i++)
for (int j = 0; j <= l; j++)
up[i][j] = -1;
Dfs(1, -1);
for (int i = 0; i < m; i++)
{
cin >> a[i];
v[a[i]].insert(i);
if (i > 0)
p[Lca(a[i], a[i - 1])].insert(i - 1);
}
while (q--)
{
int type;
cin >> type;
if (type == 1)
{
int pos, V;
cin >> pos >> V;
pos--;
v[a[pos]].erase(pos);
if (pos - 1 >= 0)
{
p[Lca(a[pos], a[pos - 1])].erase(pos - 1);
p[Lca(V, a[pos - 1])].insert(pos - 1);
}
if (pos + 1 < m)
{
p[Lca(a[pos], a[pos + 1])].erase(pos);
p[Lca(V, a[pos + 1])].insert(pos);
}
a[pos] = V;
v[V].insert(pos);
}
else
{
bool ok = false;
int l, r, V;
cin >> l >> r >> V;
l--;
r--;
auto it = v[V].lower_bound(l);
if (it != v[V].end() && *it <= r)
{
cout << *it + 1 << ' ' << *it + 1 << '\n';
ok = true;
}
if (!ok)
{
auto it = p[V].lower_bound(l);
if (it != p[V].end() && *it + 1 <= r)
{
cout << *it + 1 << ' ' << *it + 2 << '\n';
ok = true;
}
}
if (!ok)
cout << -1 << ' ' << -1 << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
n=5 |
2 |
Correct |
16 ms |
23916 KB |
n=100 |
3 |
Correct |
16 ms |
23916 KB |
n=100 |
4 |
Correct |
16 ms |
23916 KB |
n=100 |
5 |
Correct |
16 ms |
23916 KB |
n=100 |
6 |
Correct |
16 ms |
23916 KB |
n=100 |
7 |
Correct |
18 ms |
24044 KB |
n=100 |
8 |
Correct |
16 ms |
23916 KB |
n=100 |
9 |
Correct |
16 ms |
23916 KB |
n=100 |
10 |
Correct |
16 ms |
23916 KB |
n=100 |
11 |
Correct |
16 ms |
23916 KB |
n=100 |
12 |
Correct |
16 ms |
23916 KB |
n=100 |
13 |
Correct |
16 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
16 ms |
23916 KB |
n=100 |
16 |
Correct |
16 ms |
23916 KB |
n=100 |
17 |
Correct |
16 ms |
23916 KB |
n=100 |
18 |
Correct |
16 ms |
23916 KB |
n=100 |
19 |
Correct |
16 ms |
23916 KB |
n=100 |
20 |
Correct |
16 ms |
23916 KB |
n=100 |
21 |
Correct |
16 ms |
23916 KB |
n=100 |
22 |
Correct |
16 ms |
23916 KB |
n=100 |
23 |
Correct |
16 ms |
23916 KB |
n=100 |
24 |
Correct |
16 ms |
23916 KB |
n=100 |
25 |
Correct |
16 ms |
23916 KB |
n=100 |
26 |
Correct |
17 ms |
23788 KB |
n=12 |
27 |
Correct |
16 ms |
23916 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
n=5 |
2 |
Correct |
16 ms |
23916 KB |
n=100 |
3 |
Correct |
16 ms |
23916 KB |
n=100 |
4 |
Correct |
16 ms |
23916 KB |
n=100 |
5 |
Correct |
16 ms |
23916 KB |
n=100 |
6 |
Correct |
16 ms |
23916 KB |
n=100 |
7 |
Correct |
18 ms |
24044 KB |
n=100 |
8 |
Correct |
16 ms |
23916 KB |
n=100 |
9 |
Correct |
16 ms |
23916 KB |
n=100 |
10 |
Correct |
16 ms |
23916 KB |
n=100 |
11 |
Correct |
16 ms |
23916 KB |
n=100 |
12 |
Correct |
16 ms |
23916 KB |
n=100 |
13 |
Correct |
16 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
16 ms |
23916 KB |
n=100 |
16 |
Correct |
16 ms |
23916 KB |
n=100 |
17 |
Correct |
16 ms |
23916 KB |
n=100 |
18 |
Correct |
16 ms |
23916 KB |
n=100 |
19 |
Correct |
16 ms |
23916 KB |
n=100 |
20 |
Correct |
16 ms |
23916 KB |
n=100 |
21 |
Correct |
16 ms |
23916 KB |
n=100 |
22 |
Correct |
16 ms |
23916 KB |
n=100 |
23 |
Correct |
16 ms |
23916 KB |
n=100 |
24 |
Correct |
16 ms |
23916 KB |
n=100 |
25 |
Correct |
16 ms |
23916 KB |
n=100 |
26 |
Correct |
17 ms |
23788 KB |
n=12 |
27 |
Correct |
16 ms |
23916 KB |
n=100 |
28 |
Correct |
17 ms |
23916 KB |
n=500 |
29 |
Correct |
17 ms |
23916 KB |
n=500 |
30 |
Correct |
20 ms |
23916 KB |
n=500 |
31 |
Correct |
18 ms |
23916 KB |
n=500 |
32 |
Correct |
18 ms |
24044 KB |
n=500 |
33 |
Correct |
17 ms |
23916 KB |
n=500 |
34 |
Correct |
17 ms |
24016 KB |
n=500 |
35 |
Correct |
17 ms |
23916 KB |
n=500 |
36 |
Correct |
17 ms |
23916 KB |
n=500 |
37 |
Correct |
17 ms |
24044 KB |
n=500 |
38 |
Correct |
17 ms |
23916 KB |
n=500 |
39 |
Correct |
17 ms |
23916 KB |
n=500 |
40 |
Correct |
17 ms |
23916 KB |
n=500 |
41 |
Correct |
17 ms |
23916 KB |
n=500 |
42 |
Correct |
17 ms |
23916 KB |
n=500 |
43 |
Correct |
17 ms |
23916 KB |
n=500 |
44 |
Correct |
18 ms |
23916 KB |
n=500 |
45 |
Correct |
17 ms |
23916 KB |
n=500 |
46 |
Correct |
17 ms |
23916 KB |
n=500 |
47 |
Correct |
17 ms |
23916 KB |
n=500 |
48 |
Correct |
17 ms |
23916 KB |
n=500 |
49 |
Correct |
17 ms |
23916 KB |
n=500 |
50 |
Correct |
17 ms |
23916 KB |
n=500 |
51 |
Correct |
17 ms |
23916 KB |
n=500 |
52 |
Correct |
17 ms |
23916 KB |
n=500 |
53 |
Correct |
17 ms |
23916 KB |
n=500 |
54 |
Correct |
17 ms |
23916 KB |
n=500 |
55 |
Correct |
16 ms |
23916 KB |
n=278 |
56 |
Correct |
17 ms |
23916 KB |
n=500 |
57 |
Correct |
17 ms |
23916 KB |
n=500 |
58 |
Correct |
17 ms |
23916 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
n=5 |
2 |
Correct |
16 ms |
23916 KB |
n=100 |
3 |
Correct |
16 ms |
23916 KB |
n=100 |
4 |
Correct |
16 ms |
23916 KB |
n=100 |
5 |
Correct |
16 ms |
23916 KB |
n=100 |
6 |
Correct |
16 ms |
23916 KB |
n=100 |
7 |
Correct |
18 ms |
24044 KB |
n=100 |
8 |
Correct |
16 ms |
23916 KB |
n=100 |
9 |
Correct |
16 ms |
23916 KB |
n=100 |
10 |
Correct |
16 ms |
23916 KB |
n=100 |
11 |
Correct |
16 ms |
23916 KB |
n=100 |
12 |
Correct |
16 ms |
23916 KB |
n=100 |
13 |
Correct |
16 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
16 ms |
23916 KB |
n=100 |
16 |
Correct |
16 ms |
23916 KB |
n=100 |
17 |
Correct |
16 ms |
23916 KB |
n=100 |
18 |
Correct |
16 ms |
23916 KB |
n=100 |
19 |
Correct |
16 ms |
23916 KB |
n=100 |
20 |
Correct |
16 ms |
23916 KB |
n=100 |
21 |
Correct |
16 ms |
23916 KB |
n=100 |
22 |
Correct |
16 ms |
23916 KB |
n=100 |
23 |
Correct |
16 ms |
23916 KB |
n=100 |
24 |
Correct |
16 ms |
23916 KB |
n=100 |
25 |
Correct |
16 ms |
23916 KB |
n=100 |
26 |
Correct |
17 ms |
23788 KB |
n=12 |
27 |
Correct |
16 ms |
23916 KB |
n=100 |
28 |
Correct |
17 ms |
23916 KB |
n=500 |
29 |
Correct |
17 ms |
23916 KB |
n=500 |
30 |
Correct |
20 ms |
23916 KB |
n=500 |
31 |
Correct |
18 ms |
23916 KB |
n=500 |
32 |
Correct |
18 ms |
24044 KB |
n=500 |
33 |
Correct |
17 ms |
23916 KB |
n=500 |
34 |
Correct |
17 ms |
24016 KB |
n=500 |
35 |
Correct |
17 ms |
23916 KB |
n=500 |
36 |
Correct |
17 ms |
23916 KB |
n=500 |
37 |
Correct |
17 ms |
24044 KB |
n=500 |
38 |
Correct |
17 ms |
23916 KB |
n=500 |
39 |
Correct |
17 ms |
23916 KB |
n=500 |
40 |
Correct |
17 ms |
23916 KB |
n=500 |
41 |
Correct |
17 ms |
23916 KB |
n=500 |
42 |
Correct |
17 ms |
23916 KB |
n=500 |
43 |
Correct |
17 ms |
23916 KB |
n=500 |
44 |
Correct |
18 ms |
23916 KB |
n=500 |
45 |
Correct |
17 ms |
23916 KB |
n=500 |
46 |
Correct |
17 ms |
23916 KB |
n=500 |
47 |
Correct |
17 ms |
23916 KB |
n=500 |
48 |
Correct |
17 ms |
23916 KB |
n=500 |
49 |
Correct |
17 ms |
23916 KB |
n=500 |
50 |
Correct |
17 ms |
23916 KB |
n=500 |
51 |
Correct |
17 ms |
23916 KB |
n=500 |
52 |
Correct |
17 ms |
23916 KB |
n=500 |
53 |
Correct |
17 ms |
23916 KB |
n=500 |
54 |
Correct |
17 ms |
23916 KB |
n=500 |
55 |
Correct |
16 ms |
23916 KB |
n=278 |
56 |
Correct |
17 ms |
23916 KB |
n=500 |
57 |
Correct |
17 ms |
23916 KB |
n=500 |
58 |
Correct |
17 ms |
23916 KB |
n=500 |
59 |
Correct |
20 ms |
24300 KB |
n=2000 |
60 |
Correct |
19 ms |
24428 KB |
n=2000 |
61 |
Correct |
20 ms |
24300 KB |
n=2000 |
62 |
Correct |
20 ms |
24300 KB |
n=2000 |
63 |
Correct |
20 ms |
24300 KB |
n=2000 |
64 |
Correct |
19 ms |
24300 KB |
n=2000 |
65 |
Correct |
21 ms |
24300 KB |
n=2000 |
66 |
Correct |
19 ms |
24300 KB |
n=2000 |
67 |
Correct |
20 ms |
24300 KB |
n=2000 |
68 |
Correct |
20 ms |
24300 KB |
n=2000 |
69 |
Correct |
19 ms |
24300 KB |
n=2000 |
70 |
Correct |
19 ms |
24300 KB |
n=2000 |
71 |
Correct |
19 ms |
24300 KB |
n=2000 |
72 |
Correct |
19 ms |
24300 KB |
n=2000 |
73 |
Correct |
19 ms |
24300 KB |
n=2000 |
74 |
Correct |
19 ms |
24300 KB |
n=1844 |
75 |
Correct |
19 ms |
24300 KB |
n=2000 |
76 |
Correct |
20 ms |
24428 KB |
n=2000 |
77 |
Correct |
21 ms |
24300 KB |
n=2000 |
78 |
Correct |
20 ms |
24300 KB |
n=2000 |
79 |
Correct |
20 ms |
24300 KB |
n=2000 |
80 |
Correct |
19 ms |
24300 KB |
n=2000 |
81 |
Correct |
19 ms |
24300 KB |
n=2000 |
82 |
Correct |
19 ms |
24300 KB |
n=2000 |
83 |
Correct |
19 ms |
24300 KB |
n=2000 |
84 |
Correct |
22 ms |
24300 KB |
n=2000 |
85 |
Correct |
20 ms |
24300 KB |
n=2000 |
86 |
Correct |
20 ms |
24300 KB |
n=2000 |
87 |
Correct |
19 ms |
24300 KB |
n=2000 |
88 |
Correct |
19 ms |
24428 KB |
n=2000 |
89 |
Correct |
19 ms |
24428 KB |
n=2000 |
90 |
Correct |
19 ms |
24428 KB |
n=2000 |
91 |
Correct |
19 ms |
24300 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
n=5 |
2 |
Correct |
16 ms |
23916 KB |
n=100 |
3 |
Correct |
16 ms |
23916 KB |
n=100 |
4 |
Correct |
16 ms |
23916 KB |
n=100 |
5 |
Correct |
16 ms |
23916 KB |
n=100 |
6 |
Correct |
16 ms |
23916 KB |
n=100 |
7 |
Correct |
18 ms |
24044 KB |
n=100 |
8 |
Correct |
16 ms |
23916 KB |
n=100 |
9 |
Correct |
16 ms |
23916 KB |
n=100 |
10 |
Correct |
16 ms |
23916 KB |
n=100 |
11 |
Correct |
16 ms |
23916 KB |
n=100 |
12 |
Correct |
16 ms |
23916 KB |
n=100 |
13 |
Correct |
16 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
16 ms |
23916 KB |
n=100 |
16 |
Correct |
16 ms |
23916 KB |
n=100 |
17 |
Correct |
16 ms |
23916 KB |
n=100 |
18 |
Correct |
16 ms |
23916 KB |
n=100 |
19 |
Correct |
16 ms |
23916 KB |
n=100 |
20 |
Correct |
16 ms |
23916 KB |
n=100 |
21 |
Correct |
16 ms |
23916 KB |
n=100 |
22 |
Correct |
16 ms |
23916 KB |
n=100 |
23 |
Correct |
16 ms |
23916 KB |
n=100 |
24 |
Correct |
16 ms |
23916 KB |
n=100 |
25 |
Correct |
16 ms |
23916 KB |
n=100 |
26 |
Correct |
17 ms |
23788 KB |
n=12 |
27 |
Correct |
16 ms |
23916 KB |
n=100 |
28 |
Correct |
17 ms |
23916 KB |
n=500 |
29 |
Correct |
17 ms |
23916 KB |
n=500 |
30 |
Correct |
20 ms |
23916 KB |
n=500 |
31 |
Correct |
18 ms |
23916 KB |
n=500 |
32 |
Correct |
18 ms |
24044 KB |
n=500 |
33 |
Correct |
17 ms |
23916 KB |
n=500 |
34 |
Correct |
17 ms |
24016 KB |
n=500 |
35 |
Correct |
17 ms |
23916 KB |
n=500 |
36 |
Correct |
17 ms |
23916 KB |
n=500 |
37 |
Correct |
17 ms |
24044 KB |
n=500 |
38 |
Correct |
17 ms |
23916 KB |
n=500 |
39 |
Correct |
17 ms |
23916 KB |
n=500 |
40 |
Correct |
17 ms |
23916 KB |
n=500 |
41 |
Correct |
17 ms |
23916 KB |
n=500 |
42 |
Correct |
17 ms |
23916 KB |
n=500 |
43 |
Correct |
17 ms |
23916 KB |
n=500 |
44 |
Correct |
18 ms |
23916 KB |
n=500 |
45 |
Correct |
17 ms |
23916 KB |
n=500 |
46 |
Correct |
17 ms |
23916 KB |
n=500 |
47 |
Correct |
17 ms |
23916 KB |
n=500 |
48 |
Correct |
17 ms |
23916 KB |
n=500 |
49 |
Correct |
17 ms |
23916 KB |
n=500 |
50 |
Correct |
17 ms |
23916 KB |
n=500 |
51 |
Correct |
17 ms |
23916 KB |
n=500 |
52 |
Correct |
17 ms |
23916 KB |
n=500 |
53 |
Correct |
17 ms |
23916 KB |
n=500 |
54 |
Correct |
17 ms |
23916 KB |
n=500 |
55 |
Correct |
16 ms |
23916 KB |
n=278 |
56 |
Correct |
17 ms |
23916 KB |
n=500 |
57 |
Correct |
17 ms |
23916 KB |
n=500 |
58 |
Correct |
17 ms |
23916 KB |
n=500 |
59 |
Correct |
20 ms |
24300 KB |
n=2000 |
60 |
Correct |
19 ms |
24428 KB |
n=2000 |
61 |
Correct |
20 ms |
24300 KB |
n=2000 |
62 |
Correct |
20 ms |
24300 KB |
n=2000 |
63 |
Correct |
20 ms |
24300 KB |
n=2000 |
64 |
Correct |
19 ms |
24300 KB |
n=2000 |
65 |
Correct |
21 ms |
24300 KB |
n=2000 |
66 |
Correct |
19 ms |
24300 KB |
n=2000 |
67 |
Correct |
20 ms |
24300 KB |
n=2000 |
68 |
Correct |
20 ms |
24300 KB |
n=2000 |
69 |
Correct |
19 ms |
24300 KB |
n=2000 |
70 |
Correct |
19 ms |
24300 KB |
n=2000 |
71 |
Correct |
19 ms |
24300 KB |
n=2000 |
72 |
Correct |
19 ms |
24300 KB |
n=2000 |
73 |
Correct |
19 ms |
24300 KB |
n=2000 |
74 |
Correct |
19 ms |
24300 KB |
n=1844 |
75 |
Correct |
19 ms |
24300 KB |
n=2000 |
76 |
Correct |
20 ms |
24428 KB |
n=2000 |
77 |
Correct |
21 ms |
24300 KB |
n=2000 |
78 |
Correct |
20 ms |
24300 KB |
n=2000 |
79 |
Correct |
20 ms |
24300 KB |
n=2000 |
80 |
Correct |
19 ms |
24300 KB |
n=2000 |
81 |
Correct |
19 ms |
24300 KB |
n=2000 |
82 |
Correct |
19 ms |
24300 KB |
n=2000 |
83 |
Correct |
19 ms |
24300 KB |
n=2000 |
84 |
Correct |
22 ms |
24300 KB |
n=2000 |
85 |
Correct |
20 ms |
24300 KB |
n=2000 |
86 |
Correct |
20 ms |
24300 KB |
n=2000 |
87 |
Correct |
19 ms |
24300 KB |
n=2000 |
88 |
Correct |
19 ms |
24428 KB |
n=2000 |
89 |
Correct |
19 ms |
24428 KB |
n=2000 |
90 |
Correct |
19 ms |
24428 KB |
n=2000 |
91 |
Correct |
19 ms |
24300 KB |
n=2000 |
92 |
Correct |
779 ms |
68204 KB |
n=200000 |
93 |
Correct |
938 ms |
73580 KB |
n=200000 |
94 |
Correct |
708 ms |
77164 KB |
n=200000 |
95 |
Correct |
759 ms |
69872 KB |
n=200000 |
96 |
Correct |
720 ms |
69856 KB |
n=200000 |
97 |
Correct |
1018 ms |
72812 KB |
n=200000 |
98 |
Correct |
764 ms |
69856 KB |
n=200000 |
99 |
Correct |
937 ms |
69516 KB |
n=200000 |
100 |
Correct |
734 ms |
69988 KB |
n=200000 |
101 |
Correct |
621 ms |
78188 KB |
n=200000 |
102 |
Correct |
502 ms |
70764 KB |
n=200000 |
103 |
Correct |
498 ms |
70764 KB |
n=200000 |
104 |
Correct |
508 ms |
70764 KB |
n=200000 |
105 |
Correct |
509 ms |
70512 KB |
n=200000 |
106 |
Correct |
500 ms |
70508 KB |
n=200000 |
107 |
Correct |
493 ms |
70508 KB |
n=200000 |
108 |
Correct |
849 ms |
69612 KB |
n=200000 |
109 |
Correct |
856 ms |
69596 KB |
n=200000 |
110 |
Correct |
842 ms |
69572 KB |
n=200000 |
111 |
Correct |
755 ms |
69732 KB |
n=200000 |
112 |
Correct |
666 ms |
77164 KB |
n=200000 |
113 |
Correct |
983 ms |
73068 KB |
n=200000 |
114 |
Correct |
760 ms |
69728 KB |
n=200000 |
115 |
Correct |
1206 ms |
70636 KB |
n=200000 |
116 |
Correct |
706 ms |
69600 KB |
n=200000 |
117 |
Correct |
657 ms |
77676 KB |
n=200000 |
118 |
Correct |
1091 ms |
71660 KB |
n=200000 |
119 |
Correct |
700 ms |
69728 KB |
n=200000 |
120 |
Correct |
576 ms |
77932 KB |
n=200000 |
121 |
Correct |
574 ms |
77932 KB |
n=200000 |
122 |
Correct |
573 ms |
78316 KB |
n=200000 |
123 |
Correct |
512 ms |
70124 KB |
n=200000 |
124 |
Correct |
207 ms |
38636 KB |
n=25264 |