#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK ""
#define ALL(x) (x).begin(), (x).end()
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
const int N = 2e5 + 5;
const int oo = 1e9;
const long long ooo = 1e18;
const int mod = 1e9 + 7; // 998244353;
const long double pi = acos(-1);
vector <int> adj[N];
set <int> pos[N];
set <int> ind[N];
int T[2 * N][20];
int tin[N];
int h[N];
int a[N];
int n,m,q,timer;
int gethigh(int u, int v) {
return (h[u] < h[v]) ? u : v;
}
int getlca(int u, int v) {
int l = tin[u];
int r = tin[v];
if (l > r)
swap(l, r);
int d = __lg(r - l + 1);
return gethigh(T[l][d], T[r - (1 << d) + 1][d]);
}
void dfs(int u, int p = -1) {
tin[u] = ++timer;
T[timer][0] = u;
for (int v : adj[u]) if (v != p) {
h[v] = h[u] + 1;
dfs(v, u);
T[++timer][0] = u;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef ONLINE_JUDGE
// freopen(TASK".inp","r",stdin);
// freopen(TASK".out","w",stdout);
#endif
cin >> n >> m >> q;
for (int i = 1; i < n; i++) {
int u,v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1);
for (int j = 1; j < 20; j++)
for (int i = 1; i + (1 << j) - 1 <= timer; i++)
T[i][j] = gethigh(T[i][j - 1], T[i + (1 << (j - 1))][j - 1]);
for (int i = 1; i <= m; i++) {
cin >> a[i];
if (i > 1)
pos[getlca(a[i - 1], a[i])].insert(i - 1);
ind[a[i]].insert(i);
}
while (q--) {
int op; cin >> op;
if (op == 1) {
int i,v;
cin >> i >> v;
if (i > 1) {
pos[getlca(a[i - 1], a[i])].erase(i - 1);
pos[getlca(a[i - 1], v)].insert(i - 1);
}
if (i < m) {
pos[getlca(a[i], a[i + 1])].erase(i);
pos[getlca(v, a[i + 1])].insert(i);
}
ind[a[i]].erase(i);
a[i] = v;
ind[a[i]].insert(i);
} else {
int l, r, v;
cin >> l >> r >> v;
auto it = pos[v].lower_bound(l);
if (it == pos[v].end() || (*it) + 1 > r) {
it = ind[v].lower_bound(l);
if (it == ind[v].end() || (*it) > r)
cout << "-1 -1\n";
else
cout << (*it) << " " << (*it) << "\n";
} else
cout << (*it) << " " << (*it) + 1 << "\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
n=5 |
2 |
Correct |
11 ms |
23808 KB |
n=100 |
3 |
Correct |
11 ms |
23832 KB |
n=100 |
4 |
Correct |
11 ms |
23808 KB |
n=100 |
5 |
Correct |
12 ms |
23764 KB |
n=100 |
6 |
Correct |
12 ms |
23764 KB |
n=100 |
7 |
Correct |
12 ms |
23764 KB |
n=100 |
8 |
Correct |
12 ms |
23764 KB |
n=100 |
9 |
Correct |
12 ms |
23764 KB |
n=100 |
10 |
Correct |
13 ms |
23764 KB |
n=100 |
11 |
Correct |
12 ms |
23872 KB |
n=100 |
12 |
Correct |
12 ms |
23764 KB |
n=100 |
13 |
Correct |
12 ms |
23852 KB |
n=100 |
14 |
Correct |
12 ms |
23844 KB |
n=100 |
15 |
Correct |
12 ms |
23852 KB |
n=100 |
16 |
Correct |
12 ms |
23804 KB |
n=100 |
17 |
Correct |
12 ms |
23808 KB |
n=100 |
18 |
Correct |
13 ms |
23824 KB |
n=100 |
19 |
Correct |
11 ms |
23796 KB |
n=100 |
20 |
Correct |
12 ms |
23792 KB |
n=100 |
21 |
Correct |
12 ms |
23764 KB |
n=100 |
22 |
Correct |
11 ms |
23764 KB |
n=100 |
23 |
Correct |
12 ms |
23764 KB |
n=100 |
24 |
Correct |
14 ms |
23800 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
12 ms |
23912 KB |
n=12 |
27 |
Correct |
12 ms |
23776 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
n=5 |
2 |
Correct |
11 ms |
23808 KB |
n=100 |
3 |
Correct |
11 ms |
23832 KB |
n=100 |
4 |
Correct |
11 ms |
23808 KB |
n=100 |
5 |
Correct |
12 ms |
23764 KB |
n=100 |
6 |
Correct |
12 ms |
23764 KB |
n=100 |
7 |
Correct |
12 ms |
23764 KB |
n=100 |
8 |
Correct |
12 ms |
23764 KB |
n=100 |
9 |
Correct |
12 ms |
23764 KB |
n=100 |
10 |
Correct |
13 ms |
23764 KB |
n=100 |
11 |
Correct |
12 ms |
23872 KB |
n=100 |
12 |
Correct |
12 ms |
23764 KB |
n=100 |
13 |
Correct |
12 ms |
23852 KB |
n=100 |
14 |
Correct |
12 ms |
23844 KB |
n=100 |
15 |
Correct |
12 ms |
23852 KB |
n=100 |
16 |
Correct |
12 ms |
23804 KB |
n=100 |
17 |
Correct |
12 ms |
23808 KB |
n=100 |
18 |
Correct |
13 ms |
23824 KB |
n=100 |
19 |
Correct |
11 ms |
23796 KB |
n=100 |
20 |
Correct |
12 ms |
23792 KB |
n=100 |
21 |
Correct |
12 ms |
23764 KB |
n=100 |
22 |
Correct |
11 ms |
23764 KB |
n=100 |
23 |
Correct |
12 ms |
23764 KB |
n=100 |
24 |
Correct |
14 ms |
23800 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
12 ms |
23912 KB |
n=12 |
27 |
Correct |
12 ms |
23776 KB |
n=100 |
28 |
Correct |
13 ms |
23944 KB |
n=500 |
29 |
Correct |
12 ms |
23888 KB |
n=500 |
30 |
Correct |
12 ms |
23892 KB |
n=500 |
31 |
Correct |
12 ms |
23892 KB |
n=500 |
32 |
Correct |
13 ms |
23892 KB |
n=500 |
33 |
Correct |
12 ms |
23892 KB |
n=500 |
34 |
Correct |
12 ms |
23948 KB |
n=500 |
35 |
Correct |
13 ms |
23996 KB |
n=500 |
36 |
Correct |
12 ms |
23892 KB |
n=500 |
37 |
Correct |
12 ms |
23948 KB |
n=500 |
38 |
Correct |
12 ms |
23892 KB |
n=500 |
39 |
Correct |
12 ms |
23892 KB |
n=500 |
40 |
Correct |
12 ms |
23940 KB |
n=500 |
41 |
Correct |
12 ms |
23876 KB |
n=500 |
42 |
Correct |
13 ms |
24020 KB |
n=500 |
43 |
Correct |
13 ms |
23900 KB |
n=500 |
44 |
Correct |
12 ms |
23892 KB |
n=500 |
45 |
Correct |
13 ms |
23904 KB |
n=500 |
46 |
Correct |
12 ms |
23932 KB |
n=500 |
47 |
Correct |
12 ms |
23976 KB |
n=500 |
48 |
Correct |
12 ms |
23892 KB |
n=500 |
49 |
Correct |
14 ms |
23944 KB |
n=500 |
50 |
Correct |
12 ms |
23924 KB |
n=500 |
51 |
Correct |
13 ms |
23952 KB |
n=500 |
52 |
Correct |
13 ms |
23972 KB |
n=500 |
53 |
Correct |
12 ms |
23892 KB |
n=500 |
54 |
Correct |
13 ms |
23892 KB |
n=500 |
55 |
Correct |
12 ms |
23892 KB |
n=278 |
56 |
Correct |
13 ms |
23892 KB |
n=500 |
57 |
Correct |
12 ms |
23972 KB |
n=500 |
58 |
Correct |
12 ms |
23892 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
n=5 |
2 |
Correct |
11 ms |
23808 KB |
n=100 |
3 |
Correct |
11 ms |
23832 KB |
n=100 |
4 |
Correct |
11 ms |
23808 KB |
n=100 |
5 |
Correct |
12 ms |
23764 KB |
n=100 |
6 |
Correct |
12 ms |
23764 KB |
n=100 |
7 |
Correct |
12 ms |
23764 KB |
n=100 |
8 |
Correct |
12 ms |
23764 KB |
n=100 |
9 |
Correct |
12 ms |
23764 KB |
n=100 |
10 |
Correct |
13 ms |
23764 KB |
n=100 |
11 |
Correct |
12 ms |
23872 KB |
n=100 |
12 |
Correct |
12 ms |
23764 KB |
n=100 |
13 |
Correct |
12 ms |
23852 KB |
n=100 |
14 |
Correct |
12 ms |
23844 KB |
n=100 |
15 |
Correct |
12 ms |
23852 KB |
n=100 |
16 |
Correct |
12 ms |
23804 KB |
n=100 |
17 |
Correct |
12 ms |
23808 KB |
n=100 |
18 |
Correct |
13 ms |
23824 KB |
n=100 |
19 |
Correct |
11 ms |
23796 KB |
n=100 |
20 |
Correct |
12 ms |
23792 KB |
n=100 |
21 |
Correct |
12 ms |
23764 KB |
n=100 |
22 |
Correct |
11 ms |
23764 KB |
n=100 |
23 |
Correct |
12 ms |
23764 KB |
n=100 |
24 |
Correct |
14 ms |
23800 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
12 ms |
23912 KB |
n=12 |
27 |
Correct |
12 ms |
23776 KB |
n=100 |
28 |
Correct |
13 ms |
23944 KB |
n=500 |
29 |
Correct |
12 ms |
23888 KB |
n=500 |
30 |
Correct |
12 ms |
23892 KB |
n=500 |
31 |
Correct |
12 ms |
23892 KB |
n=500 |
32 |
Correct |
13 ms |
23892 KB |
n=500 |
33 |
Correct |
12 ms |
23892 KB |
n=500 |
34 |
Correct |
12 ms |
23948 KB |
n=500 |
35 |
Correct |
13 ms |
23996 KB |
n=500 |
36 |
Correct |
12 ms |
23892 KB |
n=500 |
37 |
Correct |
12 ms |
23948 KB |
n=500 |
38 |
Correct |
12 ms |
23892 KB |
n=500 |
39 |
Correct |
12 ms |
23892 KB |
n=500 |
40 |
Correct |
12 ms |
23940 KB |
n=500 |
41 |
Correct |
12 ms |
23876 KB |
n=500 |
42 |
Correct |
13 ms |
24020 KB |
n=500 |
43 |
Correct |
13 ms |
23900 KB |
n=500 |
44 |
Correct |
12 ms |
23892 KB |
n=500 |
45 |
Correct |
13 ms |
23904 KB |
n=500 |
46 |
Correct |
12 ms |
23932 KB |
n=500 |
47 |
Correct |
12 ms |
23976 KB |
n=500 |
48 |
Correct |
12 ms |
23892 KB |
n=500 |
49 |
Correct |
14 ms |
23944 KB |
n=500 |
50 |
Correct |
12 ms |
23924 KB |
n=500 |
51 |
Correct |
13 ms |
23952 KB |
n=500 |
52 |
Correct |
13 ms |
23972 KB |
n=500 |
53 |
Correct |
12 ms |
23892 KB |
n=500 |
54 |
Correct |
13 ms |
23892 KB |
n=500 |
55 |
Correct |
12 ms |
23892 KB |
n=278 |
56 |
Correct |
13 ms |
23892 KB |
n=500 |
57 |
Correct |
12 ms |
23972 KB |
n=500 |
58 |
Correct |
12 ms |
23892 KB |
n=500 |
59 |
Correct |
14 ms |
24460 KB |
n=2000 |
60 |
Correct |
15 ms |
24532 KB |
n=2000 |
61 |
Correct |
16 ms |
24592 KB |
n=2000 |
62 |
Correct |
15 ms |
24404 KB |
n=2000 |
63 |
Correct |
15 ms |
24532 KB |
n=2000 |
64 |
Correct |
14 ms |
24460 KB |
n=2000 |
65 |
Correct |
15 ms |
24412 KB |
n=2000 |
66 |
Correct |
15 ms |
24460 KB |
n=2000 |
67 |
Correct |
15 ms |
24360 KB |
n=2000 |
68 |
Correct |
14 ms |
24452 KB |
n=2000 |
69 |
Correct |
14 ms |
24432 KB |
n=2000 |
70 |
Correct |
14 ms |
24480 KB |
n=2000 |
71 |
Correct |
15 ms |
24428 KB |
n=2000 |
72 |
Correct |
14 ms |
24460 KB |
n=2000 |
73 |
Correct |
14 ms |
24404 KB |
n=2000 |
74 |
Correct |
14 ms |
24404 KB |
n=1844 |
75 |
Correct |
14 ms |
24464 KB |
n=2000 |
76 |
Correct |
14 ms |
24412 KB |
n=2000 |
77 |
Correct |
16 ms |
24404 KB |
n=2000 |
78 |
Correct |
15 ms |
24460 KB |
n=2000 |
79 |
Correct |
15 ms |
24404 KB |
n=2000 |
80 |
Correct |
15 ms |
24540 KB |
n=2000 |
81 |
Correct |
14 ms |
24404 KB |
n=2000 |
82 |
Correct |
15 ms |
24404 KB |
n=2000 |
83 |
Correct |
14 ms |
24532 KB |
n=2000 |
84 |
Correct |
15 ms |
24404 KB |
n=2000 |
85 |
Correct |
15 ms |
24456 KB |
n=2000 |
86 |
Correct |
14 ms |
24404 KB |
n=2000 |
87 |
Correct |
15 ms |
24408 KB |
n=2000 |
88 |
Correct |
18 ms |
24532 KB |
n=2000 |
89 |
Correct |
15 ms |
24532 KB |
n=2000 |
90 |
Correct |
14 ms |
24588 KB |
n=2000 |
91 |
Correct |
15 ms |
24464 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
n=5 |
2 |
Correct |
11 ms |
23808 KB |
n=100 |
3 |
Correct |
11 ms |
23832 KB |
n=100 |
4 |
Correct |
11 ms |
23808 KB |
n=100 |
5 |
Correct |
12 ms |
23764 KB |
n=100 |
6 |
Correct |
12 ms |
23764 KB |
n=100 |
7 |
Correct |
12 ms |
23764 KB |
n=100 |
8 |
Correct |
12 ms |
23764 KB |
n=100 |
9 |
Correct |
12 ms |
23764 KB |
n=100 |
10 |
Correct |
13 ms |
23764 KB |
n=100 |
11 |
Correct |
12 ms |
23872 KB |
n=100 |
12 |
Correct |
12 ms |
23764 KB |
n=100 |
13 |
Correct |
12 ms |
23852 KB |
n=100 |
14 |
Correct |
12 ms |
23844 KB |
n=100 |
15 |
Correct |
12 ms |
23852 KB |
n=100 |
16 |
Correct |
12 ms |
23804 KB |
n=100 |
17 |
Correct |
12 ms |
23808 KB |
n=100 |
18 |
Correct |
13 ms |
23824 KB |
n=100 |
19 |
Correct |
11 ms |
23796 KB |
n=100 |
20 |
Correct |
12 ms |
23792 KB |
n=100 |
21 |
Correct |
12 ms |
23764 KB |
n=100 |
22 |
Correct |
11 ms |
23764 KB |
n=100 |
23 |
Correct |
12 ms |
23764 KB |
n=100 |
24 |
Correct |
14 ms |
23800 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
12 ms |
23912 KB |
n=12 |
27 |
Correct |
12 ms |
23776 KB |
n=100 |
28 |
Correct |
13 ms |
23944 KB |
n=500 |
29 |
Correct |
12 ms |
23888 KB |
n=500 |
30 |
Correct |
12 ms |
23892 KB |
n=500 |
31 |
Correct |
12 ms |
23892 KB |
n=500 |
32 |
Correct |
13 ms |
23892 KB |
n=500 |
33 |
Correct |
12 ms |
23892 KB |
n=500 |
34 |
Correct |
12 ms |
23948 KB |
n=500 |
35 |
Correct |
13 ms |
23996 KB |
n=500 |
36 |
Correct |
12 ms |
23892 KB |
n=500 |
37 |
Correct |
12 ms |
23948 KB |
n=500 |
38 |
Correct |
12 ms |
23892 KB |
n=500 |
39 |
Correct |
12 ms |
23892 KB |
n=500 |
40 |
Correct |
12 ms |
23940 KB |
n=500 |
41 |
Correct |
12 ms |
23876 KB |
n=500 |
42 |
Correct |
13 ms |
24020 KB |
n=500 |
43 |
Correct |
13 ms |
23900 KB |
n=500 |
44 |
Correct |
12 ms |
23892 KB |
n=500 |
45 |
Correct |
13 ms |
23904 KB |
n=500 |
46 |
Correct |
12 ms |
23932 KB |
n=500 |
47 |
Correct |
12 ms |
23976 KB |
n=500 |
48 |
Correct |
12 ms |
23892 KB |
n=500 |
49 |
Correct |
14 ms |
23944 KB |
n=500 |
50 |
Correct |
12 ms |
23924 KB |
n=500 |
51 |
Correct |
13 ms |
23952 KB |
n=500 |
52 |
Correct |
13 ms |
23972 KB |
n=500 |
53 |
Correct |
12 ms |
23892 KB |
n=500 |
54 |
Correct |
13 ms |
23892 KB |
n=500 |
55 |
Correct |
12 ms |
23892 KB |
n=278 |
56 |
Correct |
13 ms |
23892 KB |
n=500 |
57 |
Correct |
12 ms |
23972 KB |
n=500 |
58 |
Correct |
12 ms |
23892 KB |
n=500 |
59 |
Correct |
14 ms |
24460 KB |
n=2000 |
60 |
Correct |
15 ms |
24532 KB |
n=2000 |
61 |
Correct |
16 ms |
24592 KB |
n=2000 |
62 |
Correct |
15 ms |
24404 KB |
n=2000 |
63 |
Correct |
15 ms |
24532 KB |
n=2000 |
64 |
Correct |
14 ms |
24460 KB |
n=2000 |
65 |
Correct |
15 ms |
24412 KB |
n=2000 |
66 |
Correct |
15 ms |
24460 KB |
n=2000 |
67 |
Correct |
15 ms |
24360 KB |
n=2000 |
68 |
Correct |
14 ms |
24452 KB |
n=2000 |
69 |
Correct |
14 ms |
24432 KB |
n=2000 |
70 |
Correct |
14 ms |
24480 KB |
n=2000 |
71 |
Correct |
15 ms |
24428 KB |
n=2000 |
72 |
Correct |
14 ms |
24460 KB |
n=2000 |
73 |
Correct |
14 ms |
24404 KB |
n=2000 |
74 |
Correct |
14 ms |
24404 KB |
n=1844 |
75 |
Correct |
14 ms |
24464 KB |
n=2000 |
76 |
Correct |
14 ms |
24412 KB |
n=2000 |
77 |
Correct |
16 ms |
24404 KB |
n=2000 |
78 |
Correct |
15 ms |
24460 KB |
n=2000 |
79 |
Correct |
15 ms |
24404 KB |
n=2000 |
80 |
Correct |
15 ms |
24540 KB |
n=2000 |
81 |
Correct |
14 ms |
24404 KB |
n=2000 |
82 |
Correct |
15 ms |
24404 KB |
n=2000 |
83 |
Correct |
14 ms |
24532 KB |
n=2000 |
84 |
Correct |
15 ms |
24404 KB |
n=2000 |
85 |
Correct |
15 ms |
24456 KB |
n=2000 |
86 |
Correct |
14 ms |
24404 KB |
n=2000 |
87 |
Correct |
15 ms |
24408 KB |
n=2000 |
88 |
Correct |
18 ms |
24532 KB |
n=2000 |
89 |
Correct |
15 ms |
24532 KB |
n=2000 |
90 |
Correct |
14 ms |
24588 KB |
n=2000 |
91 |
Correct |
15 ms |
24464 KB |
n=2000 |
92 |
Correct |
688 ms |
90940 KB |
n=200000 |
93 |
Correct |
714 ms |
97380 KB |
n=200000 |
94 |
Correct |
631 ms |
101940 KB |
n=200000 |
95 |
Correct |
686 ms |
90688 KB |
n=200000 |
96 |
Correct |
667 ms |
90748 KB |
n=200000 |
97 |
Correct |
699 ms |
96308 KB |
n=200000 |
98 |
Correct |
700 ms |
90764 KB |
n=200000 |
99 |
Correct |
834 ms |
90864 KB |
n=200000 |
100 |
Correct |
813 ms |
90820 KB |
n=200000 |
101 |
Correct |
716 ms |
103476 KB |
n=200000 |
102 |
Correct |
486 ms |
91976 KB |
n=200000 |
103 |
Correct |
444 ms |
91968 KB |
n=200000 |
104 |
Correct |
458 ms |
91928 KB |
n=200000 |
105 |
Correct |
501 ms |
92476 KB |
n=200000 |
106 |
Correct |
454 ms |
92396 KB |
n=200000 |
107 |
Correct |
483 ms |
92412 KB |
n=200000 |
108 |
Correct |
788 ms |
90848 KB |
n=200000 |
109 |
Correct |
793 ms |
90800 KB |
n=200000 |
110 |
Correct |
777 ms |
90888 KB |
n=200000 |
111 |
Correct |
802 ms |
90372 KB |
n=200000 |
112 |
Correct |
730 ms |
102224 KB |
n=200000 |
113 |
Correct |
794 ms |
96180 KB |
n=200000 |
114 |
Correct |
794 ms |
90304 KB |
n=200000 |
115 |
Correct |
873 ms |
93344 KB |
n=200000 |
116 |
Correct |
730 ms |
90960 KB |
n=200000 |
117 |
Correct |
691 ms |
102696 KB |
n=200000 |
118 |
Correct |
797 ms |
94684 KB |
n=200000 |
119 |
Correct |
702 ms |
90824 KB |
n=200000 |
120 |
Correct |
697 ms |
102584 KB |
n=200000 |
121 |
Correct |
656 ms |
102576 KB |
n=200000 |
122 |
Correct |
642 ms |
102952 KB |
n=200000 |
123 |
Correct |
491 ms |
92164 KB |
n=200000 |
124 |
Correct |
202 ms |
41168 KB |
n=25264 |