# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
// # define int long long
# define fi first
# define se second
using namespace std;
const int N = 2e5 + 1;
const int mod = 1e9 + 7;
// const int INF = 1e18;
vector < int > adj[N];
set < int > pos[N], pos2[N];
int a[N], tin[N], tout[N], timer = 1, up[N][20], lg;
void dfs( int v, int pr ) {
tin[v] = timer++;
up[v][0] = pr;
for ( int i = 1; i <= lg; i++ ) {
up[v][i] = up[ up[v][i - 1] ][i - 1];
}
for ( auto u: adj[v] ) {
if ( u != pr ) {
dfs(u, v);
}
}
tout[v] = timer;
}
bool is_ancestor( int v, int u ) {
return tin[v] <= tin[u] && tout[v] >= tout[u];
}
int lca( int v, int u ) {
if ( is_ancestor(v, u) ) {
return v;
}
if ( is_ancestor(u, v) ) {
return u;
}
for ( int i = lg; i >= 0; i-- ) {
if ( !is_ancestor(up[v][i], u) ) {
v = up[v][i];
}
}
return up[v][0];
}
int32_t main() {
speed;
int n, m, q;
cin >> n >> m >> q;
lg = log2(n) + 1;
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, 1);
for ( int i = 1; i <= m; i++ ) {
cin >> a[i];
}
for ( int i = 1; i < m; i++ ) {
pos[ a[i] ].insert(i);
pos2[ lca( a[i], a[i + 1] ) ].insert(i);
}
pos[ a[m] ].insert(m);
for ( int i = 1; i <= q; i++ ) {
int t;
cin >> t;
if ( t == 1 ) {
int p, v;
cin >> p >> v;
pos[ a[p] ].erase(p);
if ( p > 1 ) {
pos2[ lca( a[p - 1], a[p] ) ].erase( p - 1 );
}
if ( p != m ) {
pos2[ lca( a[p], a[p + 1] ) ].erase( p );
}
a[p] = v;
pos[ a[p] ].insert(p);
if ( p > 1 ) {
pos2[ lca( a[p - 1], a[p] ) ].insert(p - 1);
}
if ( p != m ) {
pos2[ lca( a[p], a[p + 1] ) ].insert(p);
}
}
else {
int l, r, v;
cin >> l >> r >> v;
if ( !pos[v].empty() ) {
auto it = pos[v].lower_bound(l);
if ( it != pos[v].end() ) {
int j = *it;
if ( j <= r ) {
cout << j << ' ' << j << "\n";
continue;
}
}
}
if ( !pos2[v].empty() ) {
auto it = pos2[v].lower_bound(l);
if ( it != pos2[v].end() ) {
int j = *it;
if ( j < r ) {
cout << j << ' ' << j + 1 << "\n";
continue;
}
}
}
cout << "-1 -1\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
n=5 |
2 |
Correct |
12 ms |
23760 KB |
n=100 |
3 |
Correct |
13 ms |
23840 KB |
n=100 |
4 |
Correct |
12 ms |
23844 KB |
n=100 |
5 |
Correct |
12 ms |
23756 KB |
n=100 |
6 |
Correct |
13 ms |
23756 KB |
n=100 |
7 |
Correct |
12 ms |
23756 KB |
n=100 |
8 |
Correct |
12 ms |
23756 KB |
n=100 |
9 |
Correct |
12 ms |
23760 KB |
n=100 |
10 |
Correct |
13 ms |
23756 KB |
n=100 |
11 |
Correct |
15 ms |
23884 KB |
n=100 |
12 |
Correct |
12 ms |
23844 KB |
n=100 |
13 |
Correct |
12 ms |
23756 KB |
n=100 |
14 |
Correct |
12 ms |
23788 KB |
n=100 |
15 |
Correct |
12 ms |
23756 KB |
n=100 |
16 |
Correct |
12 ms |
23756 KB |
n=100 |
17 |
Correct |
12 ms |
23756 KB |
n=100 |
18 |
Correct |
13 ms |
23828 KB |
n=100 |
19 |
Correct |
12 ms |
23756 KB |
n=100 |
20 |
Correct |
12 ms |
23756 KB |
n=100 |
21 |
Correct |
12 ms |
23756 KB |
n=100 |
22 |
Correct |
12 ms |
23828 KB |
n=100 |
23 |
Correct |
13 ms |
23800 KB |
n=100 |
24 |
Correct |
12 ms |
23756 KB |
n=100 |
25 |
Correct |
12 ms |
23756 KB |
n=100 |
26 |
Correct |
13 ms |
23756 KB |
n=12 |
27 |
Correct |
12 ms |
23732 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
n=5 |
2 |
Correct |
12 ms |
23760 KB |
n=100 |
3 |
Correct |
13 ms |
23840 KB |
n=100 |
4 |
Correct |
12 ms |
23844 KB |
n=100 |
5 |
Correct |
12 ms |
23756 KB |
n=100 |
6 |
Correct |
13 ms |
23756 KB |
n=100 |
7 |
Correct |
12 ms |
23756 KB |
n=100 |
8 |
Correct |
12 ms |
23756 KB |
n=100 |
9 |
Correct |
12 ms |
23760 KB |
n=100 |
10 |
Correct |
13 ms |
23756 KB |
n=100 |
11 |
Correct |
15 ms |
23884 KB |
n=100 |
12 |
Correct |
12 ms |
23844 KB |
n=100 |
13 |
Correct |
12 ms |
23756 KB |
n=100 |
14 |
Correct |
12 ms |
23788 KB |
n=100 |
15 |
Correct |
12 ms |
23756 KB |
n=100 |
16 |
Correct |
12 ms |
23756 KB |
n=100 |
17 |
Correct |
12 ms |
23756 KB |
n=100 |
18 |
Correct |
13 ms |
23828 KB |
n=100 |
19 |
Correct |
12 ms |
23756 KB |
n=100 |
20 |
Correct |
12 ms |
23756 KB |
n=100 |
21 |
Correct |
12 ms |
23756 KB |
n=100 |
22 |
Correct |
12 ms |
23828 KB |
n=100 |
23 |
Correct |
13 ms |
23800 KB |
n=100 |
24 |
Correct |
12 ms |
23756 KB |
n=100 |
25 |
Correct |
12 ms |
23756 KB |
n=100 |
26 |
Correct |
13 ms |
23756 KB |
n=12 |
27 |
Correct |
12 ms |
23732 KB |
n=100 |
28 |
Correct |
13 ms |
23892 KB |
n=500 |
29 |
Correct |
14 ms |
23884 KB |
n=500 |
30 |
Correct |
15 ms |
23888 KB |
n=500 |
31 |
Correct |
13 ms |
23884 KB |
n=500 |
32 |
Correct |
12 ms |
23936 KB |
n=500 |
33 |
Correct |
12 ms |
23900 KB |
n=500 |
34 |
Correct |
12 ms |
23884 KB |
n=500 |
35 |
Correct |
12 ms |
23884 KB |
n=500 |
36 |
Correct |
12 ms |
23884 KB |
n=500 |
37 |
Correct |
12 ms |
23884 KB |
n=500 |
38 |
Correct |
14 ms |
23856 KB |
n=500 |
39 |
Correct |
12 ms |
23884 KB |
n=500 |
40 |
Correct |
12 ms |
23884 KB |
n=500 |
41 |
Correct |
12 ms |
23836 KB |
n=500 |
42 |
Correct |
14 ms |
23876 KB |
n=500 |
43 |
Correct |
13 ms |
23936 KB |
n=500 |
44 |
Correct |
13 ms |
23940 KB |
n=500 |
45 |
Correct |
13 ms |
23884 KB |
n=500 |
46 |
Correct |
14 ms |
23948 KB |
n=500 |
47 |
Correct |
13 ms |
23952 KB |
n=500 |
48 |
Correct |
12 ms |
23884 KB |
n=500 |
49 |
Correct |
13 ms |
23936 KB |
n=500 |
50 |
Correct |
13 ms |
23884 KB |
n=500 |
51 |
Correct |
12 ms |
23884 KB |
n=500 |
52 |
Correct |
13 ms |
23884 KB |
n=500 |
53 |
Correct |
12 ms |
23912 KB |
n=500 |
54 |
Correct |
13 ms |
23880 KB |
n=500 |
55 |
Correct |
13 ms |
23992 KB |
n=278 |
56 |
Correct |
12 ms |
23960 KB |
n=500 |
57 |
Correct |
12 ms |
23924 KB |
n=500 |
58 |
Correct |
13 ms |
23884 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
n=5 |
2 |
Correct |
12 ms |
23760 KB |
n=100 |
3 |
Correct |
13 ms |
23840 KB |
n=100 |
4 |
Correct |
12 ms |
23844 KB |
n=100 |
5 |
Correct |
12 ms |
23756 KB |
n=100 |
6 |
Correct |
13 ms |
23756 KB |
n=100 |
7 |
Correct |
12 ms |
23756 KB |
n=100 |
8 |
Correct |
12 ms |
23756 KB |
n=100 |
9 |
Correct |
12 ms |
23760 KB |
n=100 |
10 |
Correct |
13 ms |
23756 KB |
n=100 |
11 |
Correct |
15 ms |
23884 KB |
n=100 |
12 |
Correct |
12 ms |
23844 KB |
n=100 |
13 |
Correct |
12 ms |
23756 KB |
n=100 |
14 |
Correct |
12 ms |
23788 KB |
n=100 |
15 |
Correct |
12 ms |
23756 KB |
n=100 |
16 |
Correct |
12 ms |
23756 KB |
n=100 |
17 |
Correct |
12 ms |
23756 KB |
n=100 |
18 |
Correct |
13 ms |
23828 KB |
n=100 |
19 |
Correct |
12 ms |
23756 KB |
n=100 |
20 |
Correct |
12 ms |
23756 KB |
n=100 |
21 |
Correct |
12 ms |
23756 KB |
n=100 |
22 |
Correct |
12 ms |
23828 KB |
n=100 |
23 |
Correct |
13 ms |
23800 KB |
n=100 |
24 |
Correct |
12 ms |
23756 KB |
n=100 |
25 |
Correct |
12 ms |
23756 KB |
n=100 |
26 |
Correct |
13 ms |
23756 KB |
n=12 |
27 |
Correct |
12 ms |
23732 KB |
n=100 |
28 |
Correct |
13 ms |
23892 KB |
n=500 |
29 |
Correct |
14 ms |
23884 KB |
n=500 |
30 |
Correct |
15 ms |
23888 KB |
n=500 |
31 |
Correct |
13 ms |
23884 KB |
n=500 |
32 |
Correct |
12 ms |
23936 KB |
n=500 |
33 |
Correct |
12 ms |
23900 KB |
n=500 |
34 |
Correct |
12 ms |
23884 KB |
n=500 |
35 |
Correct |
12 ms |
23884 KB |
n=500 |
36 |
Correct |
12 ms |
23884 KB |
n=500 |
37 |
Correct |
12 ms |
23884 KB |
n=500 |
38 |
Correct |
14 ms |
23856 KB |
n=500 |
39 |
Correct |
12 ms |
23884 KB |
n=500 |
40 |
Correct |
12 ms |
23884 KB |
n=500 |
41 |
Correct |
12 ms |
23836 KB |
n=500 |
42 |
Correct |
14 ms |
23876 KB |
n=500 |
43 |
Correct |
13 ms |
23936 KB |
n=500 |
44 |
Correct |
13 ms |
23940 KB |
n=500 |
45 |
Correct |
13 ms |
23884 KB |
n=500 |
46 |
Correct |
14 ms |
23948 KB |
n=500 |
47 |
Correct |
13 ms |
23952 KB |
n=500 |
48 |
Correct |
12 ms |
23884 KB |
n=500 |
49 |
Correct |
13 ms |
23936 KB |
n=500 |
50 |
Correct |
13 ms |
23884 KB |
n=500 |
51 |
Correct |
12 ms |
23884 KB |
n=500 |
52 |
Correct |
13 ms |
23884 KB |
n=500 |
53 |
Correct |
12 ms |
23912 KB |
n=500 |
54 |
Correct |
13 ms |
23880 KB |
n=500 |
55 |
Correct |
13 ms |
23992 KB |
n=278 |
56 |
Correct |
12 ms |
23960 KB |
n=500 |
57 |
Correct |
12 ms |
23924 KB |
n=500 |
58 |
Correct |
13 ms |
23884 KB |
n=500 |
59 |
Correct |
14 ms |
24156 KB |
n=2000 |
60 |
Correct |
14 ms |
24328 KB |
n=2000 |
61 |
Correct |
15 ms |
24268 KB |
n=2000 |
62 |
Correct |
14 ms |
24276 KB |
n=2000 |
63 |
Correct |
15 ms |
24200 KB |
n=2000 |
64 |
Correct |
15 ms |
24268 KB |
n=2000 |
65 |
Correct |
14 ms |
24156 KB |
n=2000 |
66 |
Correct |
14 ms |
24208 KB |
n=2000 |
67 |
Correct |
15 ms |
24268 KB |
n=2000 |
68 |
Correct |
15 ms |
24268 KB |
n=2000 |
69 |
Correct |
14 ms |
24240 KB |
n=2000 |
70 |
Correct |
14 ms |
24280 KB |
n=2000 |
71 |
Correct |
14 ms |
24268 KB |
n=2000 |
72 |
Correct |
14 ms |
24268 KB |
n=2000 |
73 |
Correct |
14 ms |
24268 KB |
n=2000 |
74 |
Correct |
17 ms |
24248 KB |
n=1844 |
75 |
Correct |
14 ms |
24268 KB |
n=2000 |
76 |
Correct |
16 ms |
24268 KB |
n=2000 |
77 |
Correct |
15 ms |
24228 KB |
n=2000 |
78 |
Correct |
15 ms |
24268 KB |
n=2000 |
79 |
Correct |
16 ms |
24236 KB |
n=2000 |
80 |
Correct |
14 ms |
24268 KB |
n=2000 |
81 |
Correct |
14 ms |
24268 KB |
n=2000 |
82 |
Correct |
15 ms |
24208 KB |
n=2000 |
83 |
Correct |
17 ms |
24268 KB |
n=2000 |
84 |
Correct |
16 ms |
24184 KB |
n=2000 |
85 |
Correct |
15 ms |
24268 KB |
n=2000 |
86 |
Correct |
15 ms |
24268 KB |
n=2000 |
87 |
Correct |
15 ms |
24200 KB |
n=2000 |
88 |
Correct |
14 ms |
24360 KB |
n=2000 |
89 |
Correct |
17 ms |
24288 KB |
n=2000 |
90 |
Correct |
14 ms |
24268 KB |
n=2000 |
91 |
Correct |
14 ms |
24268 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
n=5 |
2 |
Correct |
12 ms |
23760 KB |
n=100 |
3 |
Correct |
13 ms |
23840 KB |
n=100 |
4 |
Correct |
12 ms |
23844 KB |
n=100 |
5 |
Correct |
12 ms |
23756 KB |
n=100 |
6 |
Correct |
13 ms |
23756 KB |
n=100 |
7 |
Correct |
12 ms |
23756 KB |
n=100 |
8 |
Correct |
12 ms |
23756 KB |
n=100 |
9 |
Correct |
12 ms |
23760 KB |
n=100 |
10 |
Correct |
13 ms |
23756 KB |
n=100 |
11 |
Correct |
15 ms |
23884 KB |
n=100 |
12 |
Correct |
12 ms |
23844 KB |
n=100 |
13 |
Correct |
12 ms |
23756 KB |
n=100 |
14 |
Correct |
12 ms |
23788 KB |
n=100 |
15 |
Correct |
12 ms |
23756 KB |
n=100 |
16 |
Correct |
12 ms |
23756 KB |
n=100 |
17 |
Correct |
12 ms |
23756 KB |
n=100 |
18 |
Correct |
13 ms |
23828 KB |
n=100 |
19 |
Correct |
12 ms |
23756 KB |
n=100 |
20 |
Correct |
12 ms |
23756 KB |
n=100 |
21 |
Correct |
12 ms |
23756 KB |
n=100 |
22 |
Correct |
12 ms |
23828 KB |
n=100 |
23 |
Correct |
13 ms |
23800 KB |
n=100 |
24 |
Correct |
12 ms |
23756 KB |
n=100 |
25 |
Correct |
12 ms |
23756 KB |
n=100 |
26 |
Correct |
13 ms |
23756 KB |
n=12 |
27 |
Correct |
12 ms |
23732 KB |
n=100 |
28 |
Correct |
13 ms |
23892 KB |
n=500 |
29 |
Correct |
14 ms |
23884 KB |
n=500 |
30 |
Correct |
15 ms |
23888 KB |
n=500 |
31 |
Correct |
13 ms |
23884 KB |
n=500 |
32 |
Correct |
12 ms |
23936 KB |
n=500 |
33 |
Correct |
12 ms |
23900 KB |
n=500 |
34 |
Correct |
12 ms |
23884 KB |
n=500 |
35 |
Correct |
12 ms |
23884 KB |
n=500 |
36 |
Correct |
12 ms |
23884 KB |
n=500 |
37 |
Correct |
12 ms |
23884 KB |
n=500 |
38 |
Correct |
14 ms |
23856 KB |
n=500 |
39 |
Correct |
12 ms |
23884 KB |
n=500 |
40 |
Correct |
12 ms |
23884 KB |
n=500 |
41 |
Correct |
12 ms |
23836 KB |
n=500 |
42 |
Correct |
14 ms |
23876 KB |
n=500 |
43 |
Correct |
13 ms |
23936 KB |
n=500 |
44 |
Correct |
13 ms |
23940 KB |
n=500 |
45 |
Correct |
13 ms |
23884 KB |
n=500 |
46 |
Correct |
14 ms |
23948 KB |
n=500 |
47 |
Correct |
13 ms |
23952 KB |
n=500 |
48 |
Correct |
12 ms |
23884 KB |
n=500 |
49 |
Correct |
13 ms |
23936 KB |
n=500 |
50 |
Correct |
13 ms |
23884 KB |
n=500 |
51 |
Correct |
12 ms |
23884 KB |
n=500 |
52 |
Correct |
13 ms |
23884 KB |
n=500 |
53 |
Correct |
12 ms |
23912 KB |
n=500 |
54 |
Correct |
13 ms |
23880 KB |
n=500 |
55 |
Correct |
13 ms |
23992 KB |
n=278 |
56 |
Correct |
12 ms |
23960 KB |
n=500 |
57 |
Correct |
12 ms |
23924 KB |
n=500 |
58 |
Correct |
13 ms |
23884 KB |
n=500 |
59 |
Correct |
14 ms |
24156 KB |
n=2000 |
60 |
Correct |
14 ms |
24328 KB |
n=2000 |
61 |
Correct |
15 ms |
24268 KB |
n=2000 |
62 |
Correct |
14 ms |
24276 KB |
n=2000 |
63 |
Correct |
15 ms |
24200 KB |
n=2000 |
64 |
Correct |
15 ms |
24268 KB |
n=2000 |
65 |
Correct |
14 ms |
24156 KB |
n=2000 |
66 |
Correct |
14 ms |
24208 KB |
n=2000 |
67 |
Correct |
15 ms |
24268 KB |
n=2000 |
68 |
Correct |
15 ms |
24268 KB |
n=2000 |
69 |
Correct |
14 ms |
24240 KB |
n=2000 |
70 |
Correct |
14 ms |
24280 KB |
n=2000 |
71 |
Correct |
14 ms |
24268 KB |
n=2000 |
72 |
Correct |
14 ms |
24268 KB |
n=2000 |
73 |
Correct |
14 ms |
24268 KB |
n=2000 |
74 |
Correct |
17 ms |
24248 KB |
n=1844 |
75 |
Correct |
14 ms |
24268 KB |
n=2000 |
76 |
Correct |
16 ms |
24268 KB |
n=2000 |
77 |
Correct |
15 ms |
24228 KB |
n=2000 |
78 |
Correct |
15 ms |
24268 KB |
n=2000 |
79 |
Correct |
16 ms |
24236 KB |
n=2000 |
80 |
Correct |
14 ms |
24268 KB |
n=2000 |
81 |
Correct |
14 ms |
24268 KB |
n=2000 |
82 |
Correct |
15 ms |
24208 KB |
n=2000 |
83 |
Correct |
17 ms |
24268 KB |
n=2000 |
84 |
Correct |
16 ms |
24184 KB |
n=2000 |
85 |
Correct |
15 ms |
24268 KB |
n=2000 |
86 |
Correct |
15 ms |
24268 KB |
n=2000 |
87 |
Correct |
15 ms |
24200 KB |
n=2000 |
88 |
Correct |
14 ms |
24360 KB |
n=2000 |
89 |
Correct |
17 ms |
24288 KB |
n=2000 |
90 |
Correct |
14 ms |
24268 KB |
n=2000 |
91 |
Correct |
14 ms |
24268 KB |
n=2000 |
92 |
Correct |
692 ms |
68936 KB |
n=200000 |
93 |
Correct |
692 ms |
72440 KB |
n=200000 |
94 |
Correct |
512 ms |
75868 KB |
n=200000 |
95 |
Correct |
648 ms |
68904 KB |
n=200000 |
96 |
Correct |
631 ms |
68796 KB |
n=200000 |
97 |
Correct |
761 ms |
71584 KB |
n=200000 |
98 |
Correct |
647 ms |
68872 KB |
n=200000 |
99 |
Correct |
799 ms |
68160 KB |
n=200000 |
100 |
Correct |
637 ms |
68764 KB |
n=200000 |
101 |
Correct |
474 ms |
77208 KB |
n=200000 |
102 |
Correct |
383 ms |
69696 KB |
n=200000 |
103 |
Correct |
391 ms |
69656 KB |
n=200000 |
104 |
Correct |
387 ms |
69780 KB |
n=200000 |
105 |
Correct |
399 ms |
69524 KB |
n=200000 |
106 |
Correct |
400 ms |
69400 KB |
n=200000 |
107 |
Correct |
405 ms |
69428 KB |
n=200000 |
108 |
Correct |
696 ms |
68348 KB |
n=200000 |
109 |
Correct |
683 ms |
68292 KB |
n=200000 |
110 |
Correct |
706 ms |
68384 KB |
n=200000 |
111 |
Correct |
655 ms |
68604 KB |
n=200000 |
112 |
Correct |
488 ms |
76228 KB |
n=200000 |
113 |
Correct |
735 ms |
71572 KB |
n=200000 |
114 |
Correct |
637 ms |
68536 KB |
n=200000 |
115 |
Correct |
918 ms |
69444 KB |
n=200000 |
116 |
Correct |
615 ms |
68472 KB |
n=200000 |
117 |
Correct |
461 ms |
76444 KB |
n=200000 |
118 |
Correct |
811 ms |
70416 KB |
n=200000 |
119 |
Correct |
610 ms |
68700 KB |
n=200000 |
120 |
Correct |
430 ms |
76988 KB |
n=200000 |
121 |
Correct |
418 ms |
76844 KB |
n=200000 |
122 |
Correct |
416 ms |
77276 KB |
n=200000 |
123 |
Correct |
401 ms |
69068 KB |
n=200000 |
124 |
Correct |
138 ms |
36804 KB |
n=25264 |