#include <bits/stdc++.h>
// author : aykhn
using namespace std;
typedef long long ll;
#define pb push_back
#define ins insert
#define mpr make_pair
#define all(v) v.begin(), v.end()
#define bpc __builtin_popcount
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define int ll
#define infll 0x3F3F3F3F3F3F3F3F
#define inf 0x3F3F3F3F
const int MXN = 2e5 + 5;
const int LOG = 19;
int n, sz = 1;
int a[MXN];
int par[LOG][MXN], in[MXN], out[MXN];
vector<int> adj[MXN];
set<int> idx[MXN], id[MXN];
int tim = -1;
void dfs(int a, int p)
{
in[a] = ++tim;
for (int v : adj[a])
{
if (v == p) continue;
par[0][v] = a;
dfs(v, a);
}
out[a] = ++tim;
}
bool anc(int u, int v)
{
return in[u] <= in[v] && out[v] <= out[u];
}
int LCA(int u, int v)
{
if (anc(u, v)) return u;
if (anc(v, u)) return v;
for (int i = LOG - 1; i >= 0; i--)
{
if (anc(par[i][u], v)) continue;
u = par[i][u];
}
return par[0][u];
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i < n; i++)
{
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
par[0][1] = 1;
dfs(1, 1);
for (int i = 1; i < LOG; i++)
{
for (int j = 1; j <= n; j++) par[i][j] = par[i - 1][par[i - 1][j]];
}
for (int i = 0; i < m; i++)
{
cin >> a[i];
id[a[i]].ins(i);
}
for (int i = 0; i + 1 < m; i++)
{
int lca = LCA(a[i], a[i + 1]);
idx[lca].ins(i);
}
while (q--)
{
int type;
cin >> type;
if (type == 1)
{
int pos, v;
cin >> pos >> v;
pos--;
id[a[pos]].erase(pos);
id[v].ins(pos);
if (pos)
{
int lca = LCA(a[pos - 1], a[pos]);
idx[lca].erase(pos - 1);
}
if (pos + 1 < m)
{
int lca = LCA(a[pos], a[pos + 1]);
idx[lca].erase(pos);
}
a[pos] = v;
if (pos)
{
int lca = LCA(a[pos - 1], a[pos]);
idx[lca].ins(pos - 1);
}
if (pos + 1 < m)
{
int lca = LCA(a[pos], a[pos + 1]);
idx[lca].ins(pos);
}
}
else
{
int l, r, v;
cin >> l >> r >> v;
l--;
r--;
auto it = id[v].lower_bound(l);
if (it != id[v].end() && *it <= r)
{
cout << *it + 1 << " " << *it + 1 << '\n';
continue;
}
auto it1 = idx[v].lower_bound(l);
if (it1 != idx[v].end() && *it1 < r)
{
cout << *it1 + 1 << " " << *it1 + 2 << '\n';
continue;
}
cout << "-1 -1" << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
57944 KB |
n=5 |
2 |
Correct |
8 ms |
57948 KB |
n=100 |
3 |
Correct |
9 ms |
57948 KB |
n=100 |
4 |
Correct |
9 ms |
57948 KB |
n=100 |
5 |
Correct |
9 ms |
58032 KB |
n=100 |
6 |
Correct |
8 ms |
57948 KB |
n=100 |
7 |
Correct |
8 ms |
57944 KB |
n=100 |
8 |
Correct |
8 ms |
57948 KB |
n=100 |
9 |
Correct |
8 ms |
57948 KB |
n=100 |
10 |
Correct |
8 ms |
57944 KB |
n=100 |
11 |
Correct |
9 ms |
57944 KB |
n=100 |
12 |
Correct |
9 ms |
57948 KB |
n=100 |
13 |
Correct |
8 ms |
57948 KB |
n=100 |
14 |
Correct |
8 ms |
57944 KB |
n=100 |
15 |
Correct |
8 ms |
57948 KB |
n=100 |
16 |
Correct |
8 ms |
57948 KB |
n=100 |
17 |
Correct |
9 ms |
58104 KB |
n=100 |
18 |
Correct |
8 ms |
57944 KB |
n=100 |
19 |
Correct |
8 ms |
57948 KB |
n=100 |
20 |
Correct |
8 ms |
57944 KB |
n=100 |
21 |
Correct |
8 ms |
57948 KB |
n=100 |
22 |
Correct |
8 ms |
58044 KB |
n=100 |
23 |
Correct |
8 ms |
57948 KB |
n=100 |
24 |
Correct |
8 ms |
57984 KB |
n=100 |
25 |
Correct |
9 ms |
57948 KB |
n=100 |
26 |
Correct |
8 ms |
58104 KB |
n=12 |
27 |
Correct |
8 ms |
57948 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
57944 KB |
n=5 |
2 |
Correct |
8 ms |
57948 KB |
n=100 |
3 |
Correct |
9 ms |
57948 KB |
n=100 |
4 |
Correct |
9 ms |
57948 KB |
n=100 |
5 |
Correct |
9 ms |
58032 KB |
n=100 |
6 |
Correct |
8 ms |
57948 KB |
n=100 |
7 |
Correct |
8 ms |
57944 KB |
n=100 |
8 |
Correct |
8 ms |
57948 KB |
n=100 |
9 |
Correct |
8 ms |
57948 KB |
n=100 |
10 |
Correct |
8 ms |
57944 KB |
n=100 |
11 |
Correct |
9 ms |
57944 KB |
n=100 |
12 |
Correct |
9 ms |
57948 KB |
n=100 |
13 |
Correct |
8 ms |
57948 KB |
n=100 |
14 |
Correct |
8 ms |
57944 KB |
n=100 |
15 |
Correct |
8 ms |
57948 KB |
n=100 |
16 |
Correct |
8 ms |
57948 KB |
n=100 |
17 |
Correct |
9 ms |
58104 KB |
n=100 |
18 |
Correct |
8 ms |
57944 KB |
n=100 |
19 |
Correct |
8 ms |
57948 KB |
n=100 |
20 |
Correct |
8 ms |
57944 KB |
n=100 |
21 |
Correct |
8 ms |
57948 KB |
n=100 |
22 |
Correct |
8 ms |
58044 KB |
n=100 |
23 |
Correct |
8 ms |
57948 KB |
n=100 |
24 |
Correct |
8 ms |
57984 KB |
n=100 |
25 |
Correct |
9 ms |
57948 KB |
n=100 |
26 |
Correct |
8 ms |
58104 KB |
n=12 |
27 |
Correct |
8 ms |
57948 KB |
n=100 |
28 |
Correct |
10 ms |
58200 KB |
n=500 |
29 |
Correct |
9 ms |
57948 KB |
n=500 |
30 |
Correct |
9 ms |
57980 KB |
n=500 |
31 |
Correct |
9 ms |
58136 KB |
n=500 |
32 |
Correct |
9 ms |
57944 KB |
n=500 |
33 |
Correct |
9 ms |
57948 KB |
n=500 |
34 |
Correct |
9 ms |
57948 KB |
n=500 |
35 |
Correct |
9 ms |
57948 KB |
n=500 |
36 |
Correct |
9 ms |
57944 KB |
n=500 |
37 |
Correct |
9 ms |
57948 KB |
n=500 |
38 |
Correct |
9 ms |
57948 KB |
n=500 |
39 |
Correct |
8 ms |
57948 KB |
n=500 |
40 |
Correct |
9 ms |
57948 KB |
n=500 |
41 |
Correct |
9 ms |
57992 KB |
n=500 |
42 |
Correct |
9 ms |
57944 KB |
n=500 |
43 |
Correct |
9 ms |
58172 KB |
n=500 |
44 |
Correct |
9 ms |
58176 KB |
n=500 |
45 |
Correct |
9 ms |
57948 KB |
n=500 |
46 |
Correct |
9 ms |
57948 KB |
n=500 |
47 |
Correct |
9 ms |
57944 KB |
n=500 |
48 |
Correct |
9 ms |
57944 KB |
n=500 |
49 |
Correct |
9 ms |
57944 KB |
n=500 |
50 |
Correct |
9 ms |
58048 KB |
n=500 |
51 |
Correct |
9 ms |
57944 KB |
n=500 |
52 |
Correct |
9 ms |
57948 KB |
n=500 |
53 |
Correct |
9 ms |
57948 KB |
n=500 |
54 |
Correct |
9 ms |
57948 KB |
n=500 |
55 |
Correct |
8 ms |
57948 KB |
n=278 |
56 |
Correct |
9 ms |
57948 KB |
n=500 |
57 |
Correct |
9 ms |
57948 KB |
n=500 |
58 |
Correct |
9 ms |
57944 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
57944 KB |
n=5 |
2 |
Correct |
8 ms |
57948 KB |
n=100 |
3 |
Correct |
9 ms |
57948 KB |
n=100 |
4 |
Correct |
9 ms |
57948 KB |
n=100 |
5 |
Correct |
9 ms |
58032 KB |
n=100 |
6 |
Correct |
8 ms |
57948 KB |
n=100 |
7 |
Correct |
8 ms |
57944 KB |
n=100 |
8 |
Correct |
8 ms |
57948 KB |
n=100 |
9 |
Correct |
8 ms |
57948 KB |
n=100 |
10 |
Correct |
8 ms |
57944 KB |
n=100 |
11 |
Correct |
9 ms |
57944 KB |
n=100 |
12 |
Correct |
9 ms |
57948 KB |
n=100 |
13 |
Correct |
8 ms |
57948 KB |
n=100 |
14 |
Correct |
8 ms |
57944 KB |
n=100 |
15 |
Correct |
8 ms |
57948 KB |
n=100 |
16 |
Correct |
8 ms |
57948 KB |
n=100 |
17 |
Correct |
9 ms |
58104 KB |
n=100 |
18 |
Correct |
8 ms |
57944 KB |
n=100 |
19 |
Correct |
8 ms |
57948 KB |
n=100 |
20 |
Correct |
8 ms |
57944 KB |
n=100 |
21 |
Correct |
8 ms |
57948 KB |
n=100 |
22 |
Correct |
8 ms |
58044 KB |
n=100 |
23 |
Correct |
8 ms |
57948 KB |
n=100 |
24 |
Correct |
8 ms |
57984 KB |
n=100 |
25 |
Correct |
9 ms |
57948 KB |
n=100 |
26 |
Correct |
8 ms |
58104 KB |
n=12 |
27 |
Correct |
8 ms |
57948 KB |
n=100 |
28 |
Correct |
10 ms |
58200 KB |
n=500 |
29 |
Correct |
9 ms |
57948 KB |
n=500 |
30 |
Correct |
9 ms |
57980 KB |
n=500 |
31 |
Correct |
9 ms |
58136 KB |
n=500 |
32 |
Correct |
9 ms |
57944 KB |
n=500 |
33 |
Correct |
9 ms |
57948 KB |
n=500 |
34 |
Correct |
9 ms |
57948 KB |
n=500 |
35 |
Correct |
9 ms |
57948 KB |
n=500 |
36 |
Correct |
9 ms |
57944 KB |
n=500 |
37 |
Correct |
9 ms |
57948 KB |
n=500 |
38 |
Correct |
9 ms |
57948 KB |
n=500 |
39 |
Correct |
8 ms |
57948 KB |
n=500 |
40 |
Correct |
9 ms |
57948 KB |
n=500 |
41 |
Correct |
9 ms |
57992 KB |
n=500 |
42 |
Correct |
9 ms |
57944 KB |
n=500 |
43 |
Correct |
9 ms |
58172 KB |
n=500 |
44 |
Correct |
9 ms |
58176 KB |
n=500 |
45 |
Correct |
9 ms |
57948 KB |
n=500 |
46 |
Correct |
9 ms |
57948 KB |
n=500 |
47 |
Correct |
9 ms |
57944 KB |
n=500 |
48 |
Correct |
9 ms |
57944 KB |
n=500 |
49 |
Correct |
9 ms |
57944 KB |
n=500 |
50 |
Correct |
9 ms |
58048 KB |
n=500 |
51 |
Correct |
9 ms |
57944 KB |
n=500 |
52 |
Correct |
9 ms |
57948 KB |
n=500 |
53 |
Correct |
9 ms |
57948 KB |
n=500 |
54 |
Correct |
9 ms |
57948 KB |
n=500 |
55 |
Correct |
8 ms |
57948 KB |
n=278 |
56 |
Correct |
9 ms |
57948 KB |
n=500 |
57 |
Correct |
9 ms |
57948 KB |
n=500 |
58 |
Correct |
9 ms |
57944 KB |
n=500 |
59 |
Correct |
12 ms |
58204 KB |
n=2000 |
60 |
Correct |
10 ms |
58456 KB |
n=2000 |
61 |
Correct |
10 ms |
58408 KB |
n=2000 |
62 |
Correct |
13 ms |
58968 KB |
n=2000 |
63 |
Correct |
12 ms |
58248 KB |
n=2000 |
64 |
Correct |
11 ms |
58204 KB |
n=2000 |
65 |
Correct |
11 ms |
58204 KB |
n=2000 |
66 |
Correct |
11 ms |
58460 KB |
n=2000 |
67 |
Correct |
11 ms |
58200 KB |
n=2000 |
68 |
Correct |
12 ms |
58456 KB |
n=2000 |
69 |
Correct |
10 ms |
58204 KB |
n=2000 |
70 |
Correct |
12 ms |
58204 KB |
n=2000 |
71 |
Correct |
10 ms |
58204 KB |
n=2000 |
72 |
Correct |
11 ms |
58200 KB |
n=2000 |
73 |
Correct |
10 ms |
58204 KB |
n=2000 |
74 |
Correct |
11 ms |
58200 KB |
n=1844 |
75 |
Correct |
10 ms |
58408 KB |
n=2000 |
76 |
Correct |
11 ms |
58204 KB |
n=2000 |
77 |
Correct |
11 ms |
58208 KB |
n=2000 |
78 |
Correct |
11 ms |
58204 KB |
n=2000 |
79 |
Correct |
11 ms |
58204 KB |
n=2000 |
80 |
Correct |
10 ms |
58460 KB |
n=2000 |
81 |
Correct |
11 ms |
58204 KB |
n=2000 |
82 |
Correct |
11 ms |
58200 KB |
n=2000 |
83 |
Correct |
10 ms |
58456 KB |
n=2000 |
84 |
Correct |
11 ms |
58204 KB |
n=2000 |
85 |
Correct |
11 ms |
58200 KB |
n=2000 |
86 |
Correct |
12 ms |
58204 KB |
n=2000 |
87 |
Correct |
11 ms |
58204 KB |
n=2000 |
88 |
Correct |
10 ms |
58456 KB |
n=2000 |
89 |
Correct |
11 ms |
58456 KB |
n=2000 |
90 |
Correct |
10 ms |
58460 KB |
n=2000 |
91 |
Correct |
10 ms |
58204 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
57944 KB |
n=5 |
2 |
Correct |
8 ms |
57948 KB |
n=100 |
3 |
Correct |
9 ms |
57948 KB |
n=100 |
4 |
Correct |
9 ms |
57948 KB |
n=100 |
5 |
Correct |
9 ms |
58032 KB |
n=100 |
6 |
Correct |
8 ms |
57948 KB |
n=100 |
7 |
Correct |
8 ms |
57944 KB |
n=100 |
8 |
Correct |
8 ms |
57948 KB |
n=100 |
9 |
Correct |
8 ms |
57948 KB |
n=100 |
10 |
Correct |
8 ms |
57944 KB |
n=100 |
11 |
Correct |
9 ms |
57944 KB |
n=100 |
12 |
Correct |
9 ms |
57948 KB |
n=100 |
13 |
Correct |
8 ms |
57948 KB |
n=100 |
14 |
Correct |
8 ms |
57944 KB |
n=100 |
15 |
Correct |
8 ms |
57948 KB |
n=100 |
16 |
Correct |
8 ms |
57948 KB |
n=100 |
17 |
Correct |
9 ms |
58104 KB |
n=100 |
18 |
Correct |
8 ms |
57944 KB |
n=100 |
19 |
Correct |
8 ms |
57948 KB |
n=100 |
20 |
Correct |
8 ms |
57944 KB |
n=100 |
21 |
Correct |
8 ms |
57948 KB |
n=100 |
22 |
Correct |
8 ms |
58044 KB |
n=100 |
23 |
Correct |
8 ms |
57948 KB |
n=100 |
24 |
Correct |
8 ms |
57984 KB |
n=100 |
25 |
Correct |
9 ms |
57948 KB |
n=100 |
26 |
Correct |
8 ms |
58104 KB |
n=12 |
27 |
Correct |
8 ms |
57948 KB |
n=100 |
28 |
Correct |
10 ms |
58200 KB |
n=500 |
29 |
Correct |
9 ms |
57948 KB |
n=500 |
30 |
Correct |
9 ms |
57980 KB |
n=500 |
31 |
Correct |
9 ms |
58136 KB |
n=500 |
32 |
Correct |
9 ms |
57944 KB |
n=500 |
33 |
Correct |
9 ms |
57948 KB |
n=500 |
34 |
Correct |
9 ms |
57948 KB |
n=500 |
35 |
Correct |
9 ms |
57948 KB |
n=500 |
36 |
Correct |
9 ms |
57944 KB |
n=500 |
37 |
Correct |
9 ms |
57948 KB |
n=500 |
38 |
Correct |
9 ms |
57948 KB |
n=500 |
39 |
Correct |
8 ms |
57948 KB |
n=500 |
40 |
Correct |
9 ms |
57948 KB |
n=500 |
41 |
Correct |
9 ms |
57992 KB |
n=500 |
42 |
Correct |
9 ms |
57944 KB |
n=500 |
43 |
Correct |
9 ms |
58172 KB |
n=500 |
44 |
Correct |
9 ms |
58176 KB |
n=500 |
45 |
Correct |
9 ms |
57948 KB |
n=500 |
46 |
Correct |
9 ms |
57948 KB |
n=500 |
47 |
Correct |
9 ms |
57944 KB |
n=500 |
48 |
Correct |
9 ms |
57944 KB |
n=500 |
49 |
Correct |
9 ms |
57944 KB |
n=500 |
50 |
Correct |
9 ms |
58048 KB |
n=500 |
51 |
Correct |
9 ms |
57944 KB |
n=500 |
52 |
Correct |
9 ms |
57948 KB |
n=500 |
53 |
Correct |
9 ms |
57948 KB |
n=500 |
54 |
Correct |
9 ms |
57948 KB |
n=500 |
55 |
Correct |
8 ms |
57948 KB |
n=278 |
56 |
Correct |
9 ms |
57948 KB |
n=500 |
57 |
Correct |
9 ms |
57948 KB |
n=500 |
58 |
Correct |
9 ms |
57944 KB |
n=500 |
59 |
Correct |
12 ms |
58204 KB |
n=2000 |
60 |
Correct |
10 ms |
58456 KB |
n=2000 |
61 |
Correct |
10 ms |
58408 KB |
n=2000 |
62 |
Correct |
13 ms |
58968 KB |
n=2000 |
63 |
Correct |
12 ms |
58248 KB |
n=2000 |
64 |
Correct |
11 ms |
58204 KB |
n=2000 |
65 |
Correct |
11 ms |
58204 KB |
n=2000 |
66 |
Correct |
11 ms |
58460 KB |
n=2000 |
67 |
Correct |
11 ms |
58200 KB |
n=2000 |
68 |
Correct |
12 ms |
58456 KB |
n=2000 |
69 |
Correct |
10 ms |
58204 KB |
n=2000 |
70 |
Correct |
12 ms |
58204 KB |
n=2000 |
71 |
Correct |
10 ms |
58204 KB |
n=2000 |
72 |
Correct |
11 ms |
58200 KB |
n=2000 |
73 |
Correct |
10 ms |
58204 KB |
n=2000 |
74 |
Correct |
11 ms |
58200 KB |
n=1844 |
75 |
Correct |
10 ms |
58408 KB |
n=2000 |
76 |
Correct |
11 ms |
58204 KB |
n=2000 |
77 |
Correct |
11 ms |
58208 KB |
n=2000 |
78 |
Correct |
11 ms |
58204 KB |
n=2000 |
79 |
Correct |
11 ms |
58204 KB |
n=2000 |
80 |
Correct |
10 ms |
58460 KB |
n=2000 |
81 |
Correct |
11 ms |
58204 KB |
n=2000 |
82 |
Correct |
11 ms |
58200 KB |
n=2000 |
83 |
Correct |
10 ms |
58456 KB |
n=2000 |
84 |
Correct |
11 ms |
58204 KB |
n=2000 |
85 |
Correct |
11 ms |
58200 KB |
n=2000 |
86 |
Correct |
12 ms |
58204 KB |
n=2000 |
87 |
Correct |
11 ms |
58204 KB |
n=2000 |
88 |
Correct |
10 ms |
58456 KB |
n=2000 |
89 |
Correct |
11 ms |
58456 KB |
n=2000 |
90 |
Correct |
10 ms |
58460 KB |
n=2000 |
91 |
Correct |
10 ms |
58204 KB |
n=2000 |
92 |
Correct |
1263 ms |
92724 KB |
n=200000 |
93 |
Correct |
851 ms |
97640 KB |
n=200000 |
94 |
Correct |
454 ms |
100484 KB |
n=200000 |
95 |
Correct |
1300 ms |
92436 KB |
n=200000 |
96 |
Correct |
1254 ms |
92472 KB |
n=200000 |
97 |
Correct |
918 ms |
96648 KB |
n=200000 |
98 |
Correct |
1330 ms |
92644 KB |
n=200000 |
99 |
Correct |
1157 ms |
92912 KB |
n=200000 |
100 |
Correct |
1250 ms |
92636 KB |
n=200000 |
101 |
Correct |
329 ms |
101204 KB |
n=200000 |
102 |
Correct |
502 ms |
94092 KB |
n=200000 |
103 |
Correct |
460 ms |
93928 KB |
n=200000 |
104 |
Correct |
446 ms |
93880 KB |
n=200000 |
105 |
Correct |
471 ms |
94352 KB |
n=200000 |
106 |
Correct |
467 ms |
94636 KB |
n=200000 |
107 |
Correct |
480 ms |
94288 KB |
n=200000 |
108 |
Correct |
1164 ms |
92760 KB |
n=200000 |
109 |
Correct |
1171 ms |
92780 KB |
n=200000 |
110 |
Correct |
1071 ms |
92656 KB |
n=200000 |
111 |
Correct |
1055 ms |
91900 KB |
n=200000 |
112 |
Correct |
441 ms |
100552 KB |
n=200000 |
113 |
Correct |
878 ms |
96596 KB |
n=200000 |
114 |
Correct |
1088 ms |
92272 KB |
n=200000 |
115 |
Correct |
1212 ms |
94548 KB |
n=200000 |
116 |
Correct |
1300 ms |
92848 KB |
n=200000 |
117 |
Correct |
362 ms |
100692 KB |
n=200000 |
118 |
Correct |
1106 ms |
95840 KB |
n=200000 |
119 |
Correct |
1207 ms |
92756 KB |
n=200000 |
120 |
Correct |
291 ms |
100180 KB |
n=200000 |
121 |
Correct |
359 ms |
100272 KB |
n=200000 |
122 |
Correct |
367 ms |
100464 KB |
n=200000 |
123 |
Correct |
515 ms |
93948 KB |
n=200000 |
124 |
Correct |
119 ms |
70544 KB |
n=25264 |