#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define fi first
#define se second
#define ll long long
using namespace std;
const int N = 1e6 + 7;
const int mod = 1e9 + 7;
int n,m,q;
int l=1;
int cnt;
int a[N];
int tin[N];
int tout[N];
set < pair < int , int > > s[N];
vector < int > v[N];
vector < int > up[N];
void dfs( int x , int p )
{
tin[x] = ++cnt;
up[x][0] = p;
for( int i = 1; i <= l; i++ ){
up[x][i] = up[up[x][i - 1]][i - 1];
}
for( auto y : v[x] ){
if( y != p ){
dfs(y , x);
}
}
tout[x] = cnt;
}
bool upper( int x , int y )
{
return (tin[x] <= tin[y] && tout[x] >= tout[y]);
}
int lca( int x , int y )
{
if( upper(x , y) )return x;
if( upper(y , x) )return y;
for( int i = l; i >= 0; i-- ){
if( !upper(up[x][i] , y) ){
x = up[x][i];
}
}
return up[x][0];
}
void solve()
{
cin >> n >> m >> q;
while( (1 << l) <= n )l++;
for( int i = 0; i <= n; i++ ){
up[i].resize(l + 10);
}
for( int i = 1; i < n; i++ ){
int x,y;
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
dfs(1 , 1);
for( int i = 1; i <= m; i++ ){
cin >> a[i];
s[a[i]].insert({i , i});
if( i > 1 )s[lca(a[i - 1] , a[i])].insert({i - 1, i});
}
for( int i = 1; i <= q; i++ ){
int gh;
cin >> gh;
if( gh == 1 ){
int p , vv;
cin >> p >> vv;
s[a[p]].erase({p , p});
if( p > 1 )s[lca(a[p - 1] , a[p])].erase({p - 1 , p});
if( p < m )s[lca(a[p] , a[p + 1])].erase({p , p + 1});
a[p] = vv;
s[a[p]].insert({p , p});
if( p > 1 )s[lca(a[p - 1] , a[p])].insert({p - 1 , p});
if( p < m )s[lca(a[p] , a[p + 1])].insert({p , p + 1});
}
else{
int l , r , vv;
int lg = -1 , rg = -1;
cin >> l >> r >> vv;
auto it = s[vv].lower_bound({l , 0});
if( it != s[vv].end() ){
if( it->se <= r ){
lg = it->fi;
rg = it->se;
}
}
cout << lg << " " << rg << "\n";
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen( "input.txt" , "r" , stdin );
//freopen( "output.txt" , "w" , stdout );
int t = 1;//cin >> t;
while( t-- ){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
94328 KB |
n=5 |
2 |
Correct |
87 ms |
94300 KB |
n=100 |
3 |
Correct |
86 ms |
94328 KB |
n=100 |
4 |
Correct |
87 ms |
94328 KB |
n=100 |
5 |
Correct |
87 ms |
94456 KB |
n=100 |
6 |
Correct |
87 ms |
94436 KB |
n=100 |
7 |
Correct |
87 ms |
94328 KB |
n=100 |
8 |
Correct |
88 ms |
94328 KB |
n=100 |
9 |
Correct |
87 ms |
94328 KB |
n=100 |
10 |
Correct |
88 ms |
94328 KB |
n=100 |
11 |
Correct |
87 ms |
94328 KB |
n=100 |
12 |
Correct |
87 ms |
94328 KB |
n=100 |
13 |
Correct |
87 ms |
94456 KB |
n=100 |
14 |
Correct |
86 ms |
94328 KB |
n=100 |
15 |
Correct |
86 ms |
94288 KB |
n=100 |
16 |
Correct |
87 ms |
94328 KB |
n=100 |
17 |
Correct |
86 ms |
94320 KB |
n=100 |
18 |
Correct |
87 ms |
94328 KB |
n=100 |
19 |
Correct |
86 ms |
94328 KB |
n=100 |
20 |
Correct |
87 ms |
94328 KB |
n=100 |
21 |
Correct |
87 ms |
94328 KB |
n=100 |
22 |
Correct |
87 ms |
94392 KB |
n=100 |
23 |
Correct |
87 ms |
94328 KB |
n=100 |
24 |
Correct |
87 ms |
94328 KB |
n=100 |
25 |
Correct |
87 ms |
94328 KB |
n=100 |
26 |
Correct |
87 ms |
94236 KB |
n=12 |
27 |
Correct |
86 ms |
94328 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
94328 KB |
n=5 |
2 |
Correct |
87 ms |
94300 KB |
n=100 |
3 |
Correct |
86 ms |
94328 KB |
n=100 |
4 |
Correct |
87 ms |
94328 KB |
n=100 |
5 |
Correct |
87 ms |
94456 KB |
n=100 |
6 |
Correct |
87 ms |
94436 KB |
n=100 |
7 |
Correct |
87 ms |
94328 KB |
n=100 |
8 |
Correct |
88 ms |
94328 KB |
n=100 |
9 |
Correct |
87 ms |
94328 KB |
n=100 |
10 |
Correct |
88 ms |
94328 KB |
n=100 |
11 |
Correct |
87 ms |
94328 KB |
n=100 |
12 |
Correct |
87 ms |
94328 KB |
n=100 |
13 |
Correct |
87 ms |
94456 KB |
n=100 |
14 |
Correct |
86 ms |
94328 KB |
n=100 |
15 |
Correct |
86 ms |
94288 KB |
n=100 |
16 |
Correct |
87 ms |
94328 KB |
n=100 |
17 |
Correct |
86 ms |
94320 KB |
n=100 |
18 |
Correct |
87 ms |
94328 KB |
n=100 |
19 |
Correct |
86 ms |
94328 KB |
n=100 |
20 |
Correct |
87 ms |
94328 KB |
n=100 |
21 |
Correct |
87 ms |
94328 KB |
n=100 |
22 |
Correct |
87 ms |
94392 KB |
n=100 |
23 |
Correct |
87 ms |
94328 KB |
n=100 |
24 |
Correct |
87 ms |
94328 KB |
n=100 |
25 |
Correct |
87 ms |
94328 KB |
n=100 |
26 |
Correct |
87 ms |
94236 KB |
n=12 |
27 |
Correct |
86 ms |
94328 KB |
n=100 |
28 |
Correct |
87 ms |
94456 KB |
n=500 |
29 |
Correct |
87 ms |
94388 KB |
n=500 |
30 |
Correct |
88 ms |
94456 KB |
n=500 |
31 |
Correct |
89 ms |
94476 KB |
n=500 |
32 |
Correct |
88 ms |
94444 KB |
n=500 |
33 |
Correct |
87 ms |
94456 KB |
n=500 |
34 |
Correct |
88 ms |
94456 KB |
n=500 |
35 |
Correct |
88 ms |
94456 KB |
n=500 |
36 |
Correct |
89 ms |
94456 KB |
n=500 |
37 |
Correct |
87 ms |
94456 KB |
n=500 |
38 |
Correct |
88 ms |
94456 KB |
n=500 |
39 |
Correct |
87 ms |
94456 KB |
n=500 |
40 |
Correct |
88 ms |
94456 KB |
n=500 |
41 |
Correct |
86 ms |
94456 KB |
n=500 |
42 |
Correct |
87 ms |
94456 KB |
n=500 |
43 |
Correct |
88 ms |
94516 KB |
n=500 |
44 |
Correct |
88 ms |
94456 KB |
n=500 |
45 |
Correct |
88 ms |
94456 KB |
n=500 |
46 |
Correct |
89 ms |
94456 KB |
n=500 |
47 |
Correct |
87 ms |
94456 KB |
n=500 |
48 |
Correct |
88 ms |
94456 KB |
n=500 |
49 |
Correct |
86 ms |
94584 KB |
n=500 |
50 |
Correct |
90 ms |
94456 KB |
n=500 |
51 |
Correct |
87 ms |
94456 KB |
n=500 |
52 |
Correct |
88 ms |
94456 KB |
n=500 |
53 |
Correct |
87 ms |
94456 KB |
n=500 |
54 |
Correct |
89 ms |
94456 KB |
n=500 |
55 |
Correct |
87 ms |
94456 KB |
n=278 |
56 |
Correct |
89 ms |
94456 KB |
n=500 |
57 |
Correct |
87 ms |
94456 KB |
n=500 |
58 |
Correct |
88 ms |
94456 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
94328 KB |
n=5 |
2 |
Correct |
87 ms |
94300 KB |
n=100 |
3 |
Correct |
86 ms |
94328 KB |
n=100 |
4 |
Correct |
87 ms |
94328 KB |
n=100 |
5 |
Correct |
87 ms |
94456 KB |
n=100 |
6 |
Correct |
87 ms |
94436 KB |
n=100 |
7 |
Correct |
87 ms |
94328 KB |
n=100 |
8 |
Correct |
88 ms |
94328 KB |
n=100 |
9 |
Correct |
87 ms |
94328 KB |
n=100 |
10 |
Correct |
88 ms |
94328 KB |
n=100 |
11 |
Correct |
87 ms |
94328 KB |
n=100 |
12 |
Correct |
87 ms |
94328 KB |
n=100 |
13 |
Correct |
87 ms |
94456 KB |
n=100 |
14 |
Correct |
86 ms |
94328 KB |
n=100 |
15 |
Correct |
86 ms |
94288 KB |
n=100 |
16 |
Correct |
87 ms |
94328 KB |
n=100 |
17 |
Correct |
86 ms |
94320 KB |
n=100 |
18 |
Correct |
87 ms |
94328 KB |
n=100 |
19 |
Correct |
86 ms |
94328 KB |
n=100 |
20 |
Correct |
87 ms |
94328 KB |
n=100 |
21 |
Correct |
87 ms |
94328 KB |
n=100 |
22 |
Correct |
87 ms |
94392 KB |
n=100 |
23 |
Correct |
87 ms |
94328 KB |
n=100 |
24 |
Correct |
87 ms |
94328 KB |
n=100 |
25 |
Correct |
87 ms |
94328 KB |
n=100 |
26 |
Correct |
87 ms |
94236 KB |
n=12 |
27 |
Correct |
86 ms |
94328 KB |
n=100 |
28 |
Correct |
87 ms |
94456 KB |
n=500 |
29 |
Correct |
87 ms |
94388 KB |
n=500 |
30 |
Correct |
88 ms |
94456 KB |
n=500 |
31 |
Correct |
89 ms |
94476 KB |
n=500 |
32 |
Correct |
88 ms |
94444 KB |
n=500 |
33 |
Correct |
87 ms |
94456 KB |
n=500 |
34 |
Correct |
88 ms |
94456 KB |
n=500 |
35 |
Correct |
88 ms |
94456 KB |
n=500 |
36 |
Correct |
89 ms |
94456 KB |
n=500 |
37 |
Correct |
87 ms |
94456 KB |
n=500 |
38 |
Correct |
88 ms |
94456 KB |
n=500 |
39 |
Correct |
87 ms |
94456 KB |
n=500 |
40 |
Correct |
88 ms |
94456 KB |
n=500 |
41 |
Correct |
86 ms |
94456 KB |
n=500 |
42 |
Correct |
87 ms |
94456 KB |
n=500 |
43 |
Correct |
88 ms |
94516 KB |
n=500 |
44 |
Correct |
88 ms |
94456 KB |
n=500 |
45 |
Correct |
88 ms |
94456 KB |
n=500 |
46 |
Correct |
89 ms |
94456 KB |
n=500 |
47 |
Correct |
87 ms |
94456 KB |
n=500 |
48 |
Correct |
88 ms |
94456 KB |
n=500 |
49 |
Correct |
86 ms |
94584 KB |
n=500 |
50 |
Correct |
90 ms |
94456 KB |
n=500 |
51 |
Correct |
87 ms |
94456 KB |
n=500 |
52 |
Correct |
88 ms |
94456 KB |
n=500 |
53 |
Correct |
87 ms |
94456 KB |
n=500 |
54 |
Correct |
89 ms |
94456 KB |
n=500 |
55 |
Correct |
87 ms |
94456 KB |
n=278 |
56 |
Correct |
89 ms |
94456 KB |
n=500 |
57 |
Correct |
87 ms |
94456 KB |
n=500 |
58 |
Correct |
88 ms |
94456 KB |
n=500 |
59 |
Correct |
90 ms |
94852 KB |
n=2000 |
60 |
Correct |
91 ms |
94912 KB |
n=2000 |
61 |
Correct |
91 ms |
94892 KB |
n=2000 |
62 |
Correct |
91 ms |
94876 KB |
n=2000 |
63 |
Correct |
90 ms |
94840 KB |
n=2000 |
64 |
Correct |
91 ms |
94968 KB |
n=2000 |
65 |
Correct |
91 ms |
94840 KB |
n=2000 |
66 |
Correct |
90 ms |
94844 KB |
n=2000 |
67 |
Correct |
92 ms |
94840 KB |
n=2000 |
68 |
Correct |
92 ms |
94840 KB |
n=2000 |
69 |
Correct |
90 ms |
94940 KB |
n=2000 |
70 |
Correct |
91 ms |
94832 KB |
n=2000 |
71 |
Correct |
90 ms |
94852 KB |
n=2000 |
72 |
Correct |
89 ms |
94840 KB |
n=2000 |
73 |
Correct |
90 ms |
94840 KB |
n=2000 |
74 |
Correct |
90 ms |
94712 KB |
n=1844 |
75 |
Correct |
91 ms |
94840 KB |
n=2000 |
76 |
Correct |
91 ms |
94840 KB |
n=2000 |
77 |
Correct |
92 ms |
94776 KB |
n=2000 |
78 |
Correct |
91 ms |
94804 KB |
n=2000 |
79 |
Correct |
90 ms |
94840 KB |
n=2000 |
80 |
Correct |
92 ms |
94812 KB |
n=2000 |
81 |
Correct |
92 ms |
94912 KB |
n=2000 |
82 |
Correct |
91 ms |
94840 KB |
n=2000 |
83 |
Correct |
91 ms |
94840 KB |
n=2000 |
84 |
Correct |
91 ms |
94840 KB |
n=2000 |
85 |
Correct |
90 ms |
94840 KB |
n=2000 |
86 |
Correct |
90 ms |
94844 KB |
n=2000 |
87 |
Correct |
91 ms |
94840 KB |
n=2000 |
88 |
Correct |
89 ms |
94840 KB |
n=2000 |
89 |
Correct |
90 ms |
94840 KB |
n=2000 |
90 |
Correct |
89 ms |
94968 KB |
n=2000 |
91 |
Correct |
92 ms |
94972 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
94328 KB |
n=5 |
2 |
Correct |
87 ms |
94300 KB |
n=100 |
3 |
Correct |
86 ms |
94328 KB |
n=100 |
4 |
Correct |
87 ms |
94328 KB |
n=100 |
5 |
Correct |
87 ms |
94456 KB |
n=100 |
6 |
Correct |
87 ms |
94436 KB |
n=100 |
7 |
Correct |
87 ms |
94328 KB |
n=100 |
8 |
Correct |
88 ms |
94328 KB |
n=100 |
9 |
Correct |
87 ms |
94328 KB |
n=100 |
10 |
Correct |
88 ms |
94328 KB |
n=100 |
11 |
Correct |
87 ms |
94328 KB |
n=100 |
12 |
Correct |
87 ms |
94328 KB |
n=100 |
13 |
Correct |
87 ms |
94456 KB |
n=100 |
14 |
Correct |
86 ms |
94328 KB |
n=100 |
15 |
Correct |
86 ms |
94288 KB |
n=100 |
16 |
Correct |
87 ms |
94328 KB |
n=100 |
17 |
Correct |
86 ms |
94320 KB |
n=100 |
18 |
Correct |
87 ms |
94328 KB |
n=100 |
19 |
Correct |
86 ms |
94328 KB |
n=100 |
20 |
Correct |
87 ms |
94328 KB |
n=100 |
21 |
Correct |
87 ms |
94328 KB |
n=100 |
22 |
Correct |
87 ms |
94392 KB |
n=100 |
23 |
Correct |
87 ms |
94328 KB |
n=100 |
24 |
Correct |
87 ms |
94328 KB |
n=100 |
25 |
Correct |
87 ms |
94328 KB |
n=100 |
26 |
Correct |
87 ms |
94236 KB |
n=12 |
27 |
Correct |
86 ms |
94328 KB |
n=100 |
28 |
Correct |
87 ms |
94456 KB |
n=500 |
29 |
Correct |
87 ms |
94388 KB |
n=500 |
30 |
Correct |
88 ms |
94456 KB |
n=500 |
31 |
Correct |
89 ms |
94476 KB |
n=500 |
32 |
Correct |
88 ms |
94444 KB |
n=500 |
33 |
Correct |
87 ms |
94456 KB |
n=500 |
34 |
Correct |
88 ms |
94456 KB |
n=500 |
35 |
Correct |
88 ms |
94456 KB |
n=500 |
36 |
Correct |
89 ms |
94456 KB |
n=500 |
37 |
Correct |
87 ms |
94456 KB |
n=500 |
38 |
Correct |
88 ms |
94456 KB |
n=500 |
39 |
Correct |
87 ms |
94456 KB |
n=500 |
40 |
Correct |
88 ms |
94456 KB |
n=500 |
41 |
Correct |
86 ms |
94456 KB |
n=500 |
42 |
Correct |
87 ms |
94456 KB |
n=500 |
43 |
Correct |
88 ms |
94516 KB |
n=500 |
44 |
Correct |
88 ms |
94456 KB |
n=500 |
45 |
Correct |
88 ms |
94456 KB |
n=500 |
46 |
Correct |
89 ms |
94456 KB |
n=500 |
47 |
Correct |
87 ms |
94456 KB |
n=500 |
48 |
Correct |
88 ms |
94456 KB |
n=500 |
49 |
Correct |
86 ms |
94584 KB |
n=500 |
50 |
Correct |
90 ms |
94456 KB |
n=500 |
51 |
Correct |
87 ms |
94456 KB |
n=500 |
52 |
Correct |
88 ms |
94456 KB |
n=500 |
53 |
Correct |
87 ms |
94456 KB |
n=500 |
54 |
Correct |
89 ms |
94456 KB |
n=500 |
55 |
Correct |
87 ms |
94456 KB |
n=278 |
56 |
Correct |
89 ms |
94456 KB |
n=500 |
57 |
Correct |
87 ms |
94456 KB |
n=500 |
58 |
Correct |
88 ms |
94456 KB |
n=500 |
59 |
Correct |
90 ms |
94852 KB |
n=2000 |
60 |
Correct |
91 ms |
94912 KB |
n=2000 |
61 |
Correct |
91 ms |
94892 KB |
n=2000 |
62 |
Correct |
91 ms |
94876 KB |
n=2000 |
63 |
Correct |
90 ms |
94840 KB |
n=2000 |
64 |
Correct |
91 ms |
94968 KB |
n=2000 |
65 |
Correct |
91 ms |
94840 KB |
n=2000 |
66 |
Correct |
90 ms |
94844 KB |
n=2000 |
67 |
Correct |
92 ms |
94840 KB |
n=2000 |
68 |
Correct |
92 ms |
94840 KB |
n=2000 |
69 |
Correct |
90 ms |
94940 KB |
n=2000 |
70 |
Correct |
91 ms |
94832 KB |
n=2000 |
71 |
Correct |
90 ms |
94852 KB |
n=2000 |
72 |
Correct |
89 ms |
94840 KB |
n=2000 |
73 |
Correct |
90 ms |
94840 KB |
n=2000 |
74 |
Correct |
90 ms |
94712 KB |
n=1844 |
75 |
Correct |
91 ms |
94840 KB |
n=2000 |
76 |
Correct |
91 ms |
94840 KB |
n=2000 |
77 |
Correct |
92 ms |
94776 KB |
n=2000 |
78 |
Correct |
91 ms |
94804 KB |
n=2000 |
79 |
Correct |
90 ms |
94840 KB |
n=2000 |
80 |
Correct |
92 ms |
94812 KB |
n=2000 |
81 |
Correct |
92 ms |
94912 KB |
n=2000 |
82 |
Correct |
91 ms |
94840 KB |
n=2000 |
83 |
Correct |
91 ms |
94840 KB |
n=2000 |
84 |
Correct |
91 ms |
94840 KB |
n=2000 |
85 |
Correct |
90 ms |
94840 KB |
n=2000 |
86 |
Correct |
90 ms |
94844 KB |
n=2000 |
87 |
Correct |
91 ms |
94840 KB |
n=2000 |
88 |
Correct |
89 ms |
94840 KB |
n=2000 |
89 |
Correct |
90 ms |
94840 KB |
n=2000 |
90 |
Correct |
89 ms |
94968 KB |
n=2000 |
91 |
Correct |
92 ms |
94972 KB |
n=2000 |
92 |
Correct |
988 ms |
151456 KB |
n=200000 |
93 |
Correct |
1131 ms |
158256 KB |
n=200000 |
94 |
Correct |
855 ms |
160556 KB |
n=200000 |
95 |
Correct |
947 ms |
149776 KB |
n=200000 |
96 |
Correct |
947 ms |
149672 KB |
n=200000 |
97 |
Correct |
1181 ms |
157560 KB |
n=200000 |
98 |
Correct |
985 ms |
151988 KB |
n=200000 |
99 |
Correct |
1141 ms |
155224 KB |
n=200000 |
100 |
Correct |
978 ms |
153740 KB |
n=200000 |
101 |
Correct |
738 ms |
161988 KB |
n=200000 |
102 |
Correct |
648 ms |
156044 KB |
n=200000 |
103 |
Correct |
643 ms |
156084 KB |
n=200000 |
104 |
Correct |
640 ms |
156024 KB |
n=200000 |
105 |
Correct |
695 ms |
156632 KB |
n=200000 |
106 |
Correct |
657 ms |
155936 KB |
n=200000 |
107 |
Correct |
660 ms |
156288 KB |
n=200000 |
108 |
Correct |
1070 ms |
155000 KB |
n=200000 |
109 |
Correct |
1038 ms |
154872 KB |
n=200000 |
110 |
Correct |
1048 ms |
154848 KB |
n=200000 |
111 |
Correct |
970 ms |
154120 KB |
n=200000 |
112 |
Correct |
812 ms |
161132 KB |
n=200000 |
113 |
Correct |
1141 ms |
156048 KB |
n=200000 |
114 |
Correct |
972 ms |
151808 KB |
n=200000 |
115 |
Correct |
1442 ms |
156396 KB |
n=200000 |
116 |
Correct |
918 ms |
151420 KB |
n=200000 |
117 |
Correct |
787 ms |
161168 KB |
n=200000 |
118 |
Correct |
1216 ms |
157236 KB |
n=200000 |
119 |
Correct |
918 ms |
154836 KB |
n=200000 |
120 |
Correct |
727 ms |
160768 KB |
n=200000 |
121 |
Correct |
705 ms |
160636 KB |
n=200000 |
122 |
Correct |
688 ms |
161404 KB |
n=200000 |
123 |
Correct |
659 ms |
156080 KB |
n=200000 |
124 |
Correct |
300 ms |
109660 KB |
n=25264 |