#include <bits/stdc++.h>
using namespace std;
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n, m, q; cin >> n >> m >> q;
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; i++)
{
int u, v; cin >> u >> v;
u--, v--;
g[u].push_back(v);
g[v].push_back(u);
}
vector<int> in(n), out(n);
vector<vector<int>> up(n, vector<int>(__lg(n) + 1));
{
int t = 0;
vector<bool> vis(n);
function<void(int)> dfs = [&](int u)
{
vis[u] = 1;
in[u] = t++;
for (int i = 1; i <= __lg(n); i++)
up[u][i] = up[up[u][i - 1]][i - 1];
for (auto &v : g[u])
{
if (vis[v])
continue;
up[v][0] = u;
dfs(v);
}
out[u] = t;
};
dfs(0);
}
auto anc = [&](int u, int v) -> bool
{
return in[u] <= in[v] && out[u] >= out[v];
};
auto lca = [&](int u, int v) -> int
{
if (anc(u, v))
return u;
for (int i = __lg(n); i >= 0; i--)
if (!anc(up[u][i], v))
u = up[u][i];
return up[u][0];
};
vector<int> a(m);
for (int i = 0; i < m; i++)
cin >> a[i], a[i]--;
map<int, set<pair<int, int>>> mp;
for (int i = 0; i < m; i++)
mp[a[i]].emplace(i, i);
for (int i = 0; i < m - 1; i++)
mp[lca(a[i], a[i + 1])].emplace(i, i + 1);
while (q--)
{
int ty; cin >> ty;
if (ty == 1)
{
int i, u; cin >> i >> u;
i--, u--;
if (i > 0)
mp[lca(a[i - 1], a[i])].erase(make_pair(i - 1, i));
if (i < m - 1)
mp[lca(a[i], a[i + 1])].erase(make_pair(i, i + 1));
mp[a[i]].erase(make_pair(i, i));
a[i] = u;
if (i > 0)
mp[lca(a[i - 1], a[i])].emplace(i - 1, i);
if (i < m - 1)
mp[lca(a[i], a[i + 1])].emplace(i, i + 1);
mp[a[i]].emplace(i, i);
}
else
{
int l, r, u; cin >> l >> r >> u;
l--, u--;
auto it = mp[u].lower_bound(make_pair(l, -1));
if (it != mp[u].end() && it->first < r && it->second < r)
cout << it->first + 1 << ' ' << it->second + 1 << '\n';
else
cout << "-1 -1\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n=5 |
2 |
Correct |
0 ms |
344 KB |
n=100 |
3 |
Correct |
1 ms |
344 KB |
n=100 |
4 |
Correct |
0 ms |
344 KB |
n=100 |
5 |
Correct |
1 ms |
344 KB |
n=100 |
6 |
Correct |
1 ms |
344 KB |
n=100 |
7 |
Correct |
1 ms |
344 KB |
n=100 |
8 |
Correct |
1 ms |
344 KB |
n=100 |
9 |
Correct |
1 ms |
344 KB |
n=100 |
10 |
Correct |
1 ms |
348 KB |
n=100 |
11 |
Correct |
0 ms |
344 KB |
n=100 |
12 |
Correct |
1 ms |
344 KB |
n=100 |
13 |
Correct |
1 ms |
344 KB |
n=100 |
14 |
Correct |
0 ms |
344 KB |
n=100 |
15 |
Correct |
0 ms |
344 KB |
n=100 |
16 |
Correct |
1 ms |
344 KB |
n=100 |
17 |
Correct |
0 ms |
344 KB |
n=100 |
18 |
Correct |
0 ms |
344 KB |
n=100 |
19 |
Correct |
1 ms |
344 KB |
n=100 |
20 |
Correct |
1 ms |
344 KB |
n=100 |
21 |
Correct |
1 ms |
344 KB |
n=100 |
22 |
Correct |
0 ms |
344 KB |
n=100 |
23 |
Correct |
1 ms |
344 KB |
n=100 |
24 |
Correct |
0 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
344 KB |
n=100 |
26 |
Correct |
0 ms |
344 KB |
n=12 |
27 |
Correct |
1 ms |
344 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n=5 |
2 |
Correct |
0 ms |
344 KB |
n=100 |
3 |
Correct |
1 ms |
344 KB |
n=100 |
4 |
Correct |
0 ms |
344 KB |
n=100 |
5 |
Correct |
1 ms |
344 KB |
n=100 |
6 |
Correct |
1 ms |
344 KB |
n=100 |
7 |
Correct |
1 ms |
344 KB |
n=100 |
8 |
Correct |
1 ms |
344 KB |
n=100 |
9 |
Correct |
1 ms |
344 KB |
n=100 |
10 |
Correct |
1 ms |
348 KB |
n=100 |
11 |
Correct |
0 ms |
344 KB |
n=100 |
12 |
Correct |
1 ms |
344 KB |
n=100 |
13 |
Correct |
1 ms |
344 KB |
n=100 |
14 |
Correct |
0 ms |
344 KB |
n=100 |
15 |
Correct |
0 ms |
344 KB |
n=100 |
16 |
Correct |
1 ms |
344 KB |
n=100 |
17 |
Correct |
0 ms |
344 KB |
n=100 |
18 |
Correct |
0 ms |
344 KB |
n=100 |
19 |
Correct |
1 ms |
344 KB |
n=100 |
20 |
Correct |
1 ms |
344 KB |
n=100 |
21 |
Correct |
1 ms |
344 KB |
n=100 |
22 |
Correct |
0 ms |
344 KB |
n=100 |
23 |
Correct |
1 ms |
344 KB |
n=100 |
24 |
Correct |
0 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
344 KB |
n=100 |
26 |
Correct |
0 ms |
344 KB |
n=12 |
27 |
Correct |
1 ms |
344 KB |
n=100 |
28 |
Correct |
1 ms |
600 KB |
n=500 |
29 |
Correct |
1 ms |
600 KB |
n=500 |
30 |
Correct |
1 ms |
600 KB |
n=500 |
31 |
Correct |
1 ms |
604 KB |
n=500 |
32 |
Correct |
1 ms |
600 KB |
n=500 |
33 |
Correct |
1 ms |
600 KB |
n=500 |
34 |
Correct |
1 ms |
600 KB |
n=500 |
35 |
Correct |
2 ms |
600 KB |
n=500 |
36 |
Correct |
1 ms |
348 KB |
n=500 |
37 |
Correct |
1 ms |
600 KB |
n=500 |
38 |
Correct |
1 ms |
600 KB |
n=500 |
39 |
Correct |
1 ms |
604 KB |
n=500 |
40 |
Correct |
1 ms |
600 KB |
n=500 |
41 |
Correct |
1 ms |
344 KB |
n=500 |
42 |
Correct |
1 ms |
600 KB |
n=500 |
43 |
Correct |
1 ms |
604 KB |
n=500 |
44 |
Correct |
1 ms |
600 KB |
n=500 |
45 |
Correct |
1 ms |
600 KB |
n=500 |
46 |
Correct |
1 ms |
600 KB |
n=500 |
47 |
Correct |
1 ms |
604 KB |
n=500 |
48 |
Correct |
1 ms |
604 KB |
n=500 |
49 |
Correct |
1 ms |
600 KB |
n=500 |
50 |
Correct |
1 ms |
600 KB |
n=500 |
51 |
Correct |
1 ms |
600 KB |
n=500 |
52 |
Correct |
1 ms |
600 KB |
n=500 |
53 |
Correct |
1 ms |
600 KB |
n=500 |
54 |
Correct |
1 ms |
600 KB |
n=500 |
55 |
Correct |
1 ms |
344 KB |
n=278 |
56 |
Correct |
1 ms |
600 KB |
n=500 |
57 |
Correct |
1 ms |
604 KB |
n=500 |
58 |
Correct |
1 ms |
600 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n=5 |
2 |
Correct |
0 ms |
344 KB |
n=100 |
3 |
Correct |
1 ms |
344 KB |
n=100 |
4 |
Correct |
0 ms |
344 KB |
n=100 |
5 |
Correct |
1 ms |
344 KB |
n=100 |
6 |
Correct |
1 ms |
344 KB |
n=100 |
7 |
Correct |
1 ms |
344 KB |
n=100 |
8 |
Correct |
1 ms |
344 KB |
n=100 |
9 |
Correct |
1 ms |
344 KB |
n=100 |
10 |
Correct |
1 ms |
348 KB |
n=100 |
11 |
Correct |
0 ms |
344 KB |
n=100 |
12 |
Correct |
1 ms |
344 KB |
n=100 |
13 |
Correct |
1 ms |
344 KB |
n=100 |
14 |
Correct |
0 ms |
344 KB |
n=100 |
15 |
Correct |
0 ms |
344 KB |
n=100 |
16 |
Correct |
1 ms |
344 KB |
n=100 |
17 |
Correct |
0 ms |
344 KB |
n=100 |
18 |
Correct |
0 ms |
344 KB |
n=100 |
19 |
Correct |
1 ms |
344 KB |
n=100 |
20 |
Correct |
1 ms |
344 KB |
n=100 |
21 |
Correct |
1 ms |
344 KB |
n=100 |
22 |
Correct |
0 ms |
344 KB |
n=100 |
23 |
Correct |
1 ms |
344 KB |
n=100 |
24 |
Correct |
0 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
344 KB |
n=100 |
26 |
Correct |
0 ms |
344 KB |
n=12 |
27 |
Correct |
1 ms |
344 KB |
n=100 |
28 |
Correct |
1 ms |
600 KB |
n=500 |
29 |
Correct |
1 ms |
600 KB |
n=500 |
30 |
Correct |
1 ms |
600 KB |
n=500 |
31 |
Correct |
1 ms |
604 KB |
n=500 |
32 |
Correct |
1 ms |
600 KB |
n=500 |
33 |
Correct |
1 ms |
600 KB |
n=500 |
34 |
Correct |
1 ms |
600 KB |
n=500 |
35 |
Correct |
2 ms |
600 KB |
n=500 |
36 |
Correct |
1 ms |
348 KB |
n=500 |
37 |
Correct |
1 ms |
600 KB |
n=500 |
38 |
Correct |
1 ms |
600 KB |
n=500 |
39 |
Correct |
1 ms |
604 KB |
n=500 |
40 |
Correct |
1 ms |
600 KB |
n=500 |
41 |
Correct |
1 ms |
344 KB |
n=500 |
42 |
Correct |
1 ms |
600 KB |
n=500 |
43 |
Correct |
1 ms |
604 KB |
n=500 |
44 |
Correct |
1 ms |
600 KB |
n=500 |
45 |
Correct |
1 ms |
600 KB |
n=500 |
46 |
Correct |
1 ms |
600 KB |
n=500 |
47 |
Correct |
1 ms |
604 KB |
n=500 |
48 |
Correct |
1 ms |
604 KB |
n=500 |
49 |
Correct |
1 ms |
600 KB |
n=500 |
50 |
Correct |
1 ms |
600 KB |
n=500 |
51 |
Correct |
1 ms |
600 KB |
n=500 |
52 |
Correct |
1 ms |
600 KB |
n=500 |
53 |
Correct |
1 ms |
600 KB |
n=500 |
54 |
Correct |
1 ms |
600 KB |
n=500 |
55 |
Correct |
1 ms |
344 KB |
n=278 |
56 |
Correct |
1 ms |
600 KB |
n=500 |
57 |
Correct |
1 ms |
604 KB |
n=500 |
58 |
Correct |
1 ms |
600 KB |
n=500 |
59 |
Correct |
3 ms |
1112 KB |
n=2000 |
60 |
Correct |
4 ms |
1112 KB |
n=2000 |
61 |
Correct |
4 ms |
1112 KB |
n=2000 |
62 |
Correct |
4 ms |
1112 KB |
n=2000 |
63 |
Correct |
3 ms |
1112 KB |
n=2000 |
64 |
Correct |
4 ms |
1112 KB |
n=2000 |
65 |
Correct |
3 ms |
1112 KB |
n=2000 |
66 |
Correct |
4 ms |
1112 KB |
n=2000 |
67 |
Correct |
3 ms |
1116 KB |
n=2000 |
68 |
Correct |
4 ms |
1112 KB |
n=2000 |
69 |
Correct |
3 ms |
856 KB |
n=2000 |
70 |
Correct |
3 ms |
856 KB |
n=2000 |
71 |
Correct |
2 ms |
856 KB |
n=2000 |
72 |
Correct |
2 ms |
856 KB |
n=2000 |
73 |
Correct |
2 ms |
856 KB |
n=2000 |
74 |
Correct |
3 ms |
856 KB |
n=1844 |
75 |
Correct |
2 ms |
1060 KB |
n=2000 |
76 |
Correct |
3 ms |
1112 KB |
n=2000 |
77 |
Correct |
3 ms |
1112 KB |
n=2000 |
78 |
Correct |
3 ms |
856 KB |
n=2000 |
79 |
Correct |
3 ms |
860 KB |
n=2000 |
80 |
Correct |
4 ms |
1112 KB |
n=2000 |
81 |
Correct |
4 ms |
1112 KB |
n=2000 |
82 |
Correct |
3 ms |
856 KB |
n=2000 |
83 |
Correct |
4 ms |
1112 KB |
n=2000 |
84 |
Correct |
3 ms |
1112 KB |
n=2000 |
85 |
Correct |
4 ms |
1112 KB |
n=2000 |
86 |
Correct |
4 ms |
1152 KB |
n=2000 |
87 |
Correct |
3 ms |
1112 KB |
n=2000 |
88 |
Correct |
3 ms |
1112 KB |
n=2000 |
89 |
Correct |
4 ms |
1112 KB |
n=2000 |
90 |
Correct |
4 ms |
1112 KB |
n=2000 |
91 |
Correct |
3 ms |
856 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n=5 |
2 |
Correct |
0 ms |
344 KB |
n=100 |
3 |
Correct |
1 ms |
344 KB |
n=100 |
4 |
Correct |
0 ms |
344 KB |
n=100 |
5 |
Correct |
1 ms |
344 KB |
n=100 |
6 |
Correct |
1 ms |
344 KB |
n=100 |
7 |
Correct |
1 ms |
344 KB |
n=100 |
8 |
Correct |
1 ms |
344 KB |
n=100 |
9 |
Correct |
1 ms |
344 KB |
n=100 |
10 |
Correct |
1 ms |
348 KB |
n=100 |
11 |
Correct |
0 ms |
344 KB |
n=100 |
12 |
Correct |
1 ms |
344 KB |
n=100 |
13 |
Correct |
1 ms |
344 KB |
n=100 |
14 |
Correct |
0 ms |
344 KB |
n=100 |
15 |
Correct |
0 ms |
344 KB |
n=100 |
16 |
Correct |
1 ms |
344 KB |
n=100 |
17 |
Correct |
0 ms |
344 KB |
n=100 |
18 |
Correct |
0 ms |
344 KB |
n=100 |
19 |
Correct |
1 ms |
344 KB |
n=100 |
20 |
Correct |
1 ms |
344 KB |
n=100 |
21 |
Correct |
1 ms |
344 KB |
n=100 |
22 |
Correct |
0 ms |
344 KB |
n=100 |
23 |
Correct |
1 ms |
344 KB |
n=100 |
24 |
Correct |
0 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
344 KB |
n=100 |
26 |
Correct |
0 ms |
344 KB |
n=12 |
27 |
Correct |
1 ms |
344 KB |
n=100 |
28 |
Correct |
1 ms |
600 KB |
n=500 |
29 |
Correct |
1 ms |
600 KB |
n=500 |
30 |
Correct |
1 ms |
600 KB |
n=500 |
31 |
Correct |
1 ms |
604 KB |
n=500 |
32 |
Correct |
1 ms |
600 KB |
n=500 |
33 |
Correct |
1 ms |
600 KB |
n=500 |
34 |
Correct |
1 ms |
600 KB |
n=500 |
35 |
Correct |
2 ms |
600 KB |
n=500 |
36 |
Correct |
1 ms |
348 KB |
n=500 |
37 |
Correct |
1 ms |
600 KB |
n=500 |
38 |
Correct |
1 ms |
600 KB |
n=500 |
39 |
Correct |
1 ms |
604 KB |
n=500 |
40 |
Correct |
1 ms |
600 KB |
n=500 |
41 |
Correct |
1 ms |
344 KB |
n=500 |
42 |
Correct |
1 ms |
600 KB |
n=500 |
43 |
Correct |
1 ms |
604 KB |
n=500 |
44 |
Correct |
1 ms |
600 KB |
n=500 |
45 |
Correct |
1 ms |
600 KB |
n=500 |
46 |
Correct |
1 ms |
600 KB |
n=500 |
47 |
Correct |
1 ms |
604 KB |
n=500 |
48 |
Correct |
1 ms |
604 KB |
n=500 |
49 |
Correct |
1 ms |
600 KB |
n=500 |
50 |
Correct |
1 ms |
600 KB |
n=500 |
51 |
Correct |
1 ms |
600 KB |
n=500 |
52 |
Correct |
1 ms |
600 KB |
n=500 |
53 |
Correct |
1 ms |
600 KB |
n=500 |
54 |
Correct |
1 ms |
600 KB |
n=500 |
55 |
Correct |
1 ms |
344 KB |
n=278 |
56 |
Correct |
1 ms |
600 KB |
n=500 |
57 |
Correct |
1 ms |
604 KB |
n=500 |
58 |
Correct |
1 ms |
600 KB |
n=500 |
59 |
Correct |
3 ms |
1112 KB |
n=2000 |
60 |
Correct |
4 ms |
1112 KB |
n=2000 |
61 |
Correct |
4 ms |
1112 KB |
n=2000 |
62 |
Correct |
4 ms |
1112 KB |
n=2000 |
63 |
Correct |
3 ms |
1112 KB |
n=2000 |
64 |
Correct |
4 ms |
1112 KB |
n=2000 |
65 |
Correct |
3 ms |
1112 KB |
n=2000 |
66 |
Correct |
4 ms |
1112 KB |
n=2000 |
67 |
Correct |
3 ms |
1116 KB |
n=2000 |
68 |
Correct |
4 ms |
1112 KB |
n=2000 |
69 |
Correct |
3 ms |
856 KB |
n=2000 |
70 |
Correct |
3 ms |
856 KB |
n=2000 |
71 |
Correct |
2 ms |
856 KB |
n=2000 |
72 |
Correct |
2 ms |
856 KB |
n=2000 |
73 |
Correct |
2 ms |
856 KB |
n=2000 |
74 |
Correct |
3 ms |
856 KB |
n=1844 |
75 |
Correct |
2 ms |
1060 KB |
n=2000 |
76 |
Correct |
3 ms |
1112 KB |
n=2000 |
77 |
Correct |
3 ms |
1112 KB |
n=2000 |
78 |
Correct |
3 ms |
856 KB |
n=2000 |
79 |
Correct |
3 ms |
860 KB |
n=2000 |
80 |
Correct |
4 ms |
1112 KB |
n=2000 |
81 |
Correct |
4 ms |
1112 KB |
n=2000 |
82 |
Correct |
3 ms |
856 KB |
n=2000 |
83 |
Correct |
4 ms |
1112 KB |
n=2000 |
84 |
Correct |
3 ms |
1112 KB |
n=2000 |
85 |
Correct |
4 ms |
1112 KB |
n=2000 |
86 |
Correct |
4 ms |
1152 KB |
n=2000 |
87 |
Correct |
3 ms |
1112 KB |
n=2000 |
88 |
Correct |
3 ms |
1112 KB |
n=2000 |
89 |
Correct |
4 ms |
1112 KB |
n=2000 |
90 |
Correct |
4 ms |
1112 KB |
n=2000 |
91 |
Correct |
3 ms |
856 KB |
n=2000 |
92 |
Correct |
996 ms |
71368 KB |
n=200000 |
93 |
Correct |
1555 ms |
82768 KB |
n=200000 |
94 |
Correct |
1449 ms |
88516 KB |
n=200000 |
95 |
Correct |
933 ms |
74716 KB |
n=200000 |
96 |
Correct |
951 ms |
74484 KB |
n=200000 |
97 |
Correct |
1484 ms |
81236 KB |
n=200000 |
98 |
Correct |
1002 ms |
74520 KB |
n=200000 |
99 |
Correct |
989 ms |
74644 KB |
n=200000 |
100 |
Correct |
925 ms |
74752 KB |
n=200000 |
101 |
Correct |
1359 ms |
90000 KB |
n=200000 |
102 |
Correct |
487 ms |
72784 KB |
n=200000 |
103 |
Correct |
445 ms |
72784 KB |
n=200000 |
104 |
Correct |
400 ms |
72756 KB |
n=200000 |
105 |
Correct |
422 ms |
73328 KB |
n=200000 |
106 |
Correct |
508 ms |
73320 KB |
n=200000 |
107 |
Correct |
407 ms |
73188 KB |
n=200000 |
108 |
Correct |
897 ms |
74568 KB |
n=200000 |
109 |
Correct |
964 ms |
74456 KB |
n=200000 |
110 |
Correct |
905 ms |
74364 KB |
n=200000 |
111 |
Correct |
862 ms |
71380 KB |
n=200000 |
112 |
Correct |
1506 ms |
88492 KB |
n=200000 |
113 |
Correct |
1665 ms |
80948 KB |
n=200000 |
114 |
Correct |
779 ms |
71364 KB |
n=200000 |
115 |
Correct |
1760 ms |
77148 KB |
n=200000 |
116 |
Correct |
1008 ms |
76144 KB |
n=200000 |
117 |
Correct |
1455 ms |
90984 KB |
n=200000 |
118 |
Correct |
1748 ms |
81160 KB |
n=200000 |
119 |
Correct |
1000 ms |
75956 KB |
n=200000 |
120 |
Correct |
1378 ms |
89448 KB |
n=200000 |
121 |
Correct |
1408 ms |
89280 KB |
n=200000 |
122 |
Correct |
1394 ms |
89624 KB |
n=200000 |
123 |
Correct |
418 ms |
72928 KB |
n=200000 |
124 |
Correct |
247 ms |
19792 KB |
n=25264 |