#include <bits/stdc++.h>
#define DIM 200010
using namespace std;
vector <int> L[DIM];
pair <int,int> rmq[20][DIM*3];
set <int> s[DIM],s2[DIM];
int E[DIM*3],p[DIM*3],first[DIM],level[DIM],v[DIM];
int n,m,i,j,x,y,pos,val,q,k,tip,l,r;
void dfs (int nod, int tata){
level[nod] = 1 + level[tata];
E[++k] = nod;
first[nod] = k;
for (auto vecin : L[nod])
if (vecin != tata){
dfs (vecin,nod);
E[++k] = nod;
}
}
int get_lca (int x, int y){
int posx = first[x], posy = first[y];
if (posx > posy)
swap (posx,posy);
int nr = p[posy-posx+1];
pair <int,int> sol = min (rmq[nr][posx],rmq[nr][posy-(1<<nr)+1]);
return E[sol.second];
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n>>m>>q;
for (i=1;i<n;i++){
cin>>x>>y;
L[x].push_back(y);
L[y].push_back(x);
}
dfs (1,0);
for (i=1;i<=k;i++)
rmq[0][i] = make_pair(level[E[i]],i);
for (i=1;(1<<i)<=k;i++)
for (j=1;j<=k;j++){
rmq[i][j] = rmq[i-1][j];
if (j + (1<<(i-1)) <= k && rmq[i-1][j + (1<<(i-1))].first < rmq[i][j].first)
rmq[i][j] = rmq[i-1][j + (1<<(i-1))];
}
for (i=2;i<=k;i++)
p[i] = p[i/2] + 1;
for (i=1;i<=m;i++){
cin>>v[i];
s2[v[i]].insert(i);
}
for (i=1;i<m;i++){
int lca = get_lca (v[i],v[i+1]);
s[lca].insert(i);
}
for (;q--;){
cin>>tip;
if (tip == 1){
cin>>pos>>val;
if (pos > 1){
int lca = get_lca (v[pos-1],v[pos]);
s[lca].erase(pos-1);
}
if (pos < m){
int lca = get_lca (v[pos],v[pos+1]);
s[lca].erase(pos);
}
s2[v[pos]].erase(pos);
v[pos] = val;
s2[v[pos]].insert(pos);
if (pos > 1){
int lca = get_lca (v[pos-1],v[pos]);
s[lca].insert(pos-1);
}
if (pos < m){
int lca = get_lca (v[pos],v[pos+1]);
s[lca].insert(pos);
}
} else {
cin>>l>>r>>val;
set <int> :: iterator it = s2[val].lower_bound(l);
if (it != s2[val].end() && *it <= r){
cout<<(*it)<<" "<<(*it)<<"\n";
continue;
}
it = s[val].lower_bound(l);
pos = *it;
if (it == s[val].end() || *it >= r)
cout<<"-1 -1\n";
else cout<<(*it)<<" "<<(*it)+1<<"\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
n=5 |
2 |
Correct |
17 ms |
23916 KB |
n=100 |
3 |
Correct |
17 ms |
23916 KB |
n=100 |
4 |
Correct |
19 ms |
23916 KB |
n=100 |
5 |
Correct |
17 ms |
23916 KB |
n=100 |
6 |
Correct |
17 ms |
23916 KB |
n=100 |
7 |
Correct |
19 ms |
23916 KB |
n=100 |
8 |
Correct |
16 ms |
23916 KB |
n=100 |
9 |
Correct |
16 ms |
23916 KB |
n=100 |
10 |
Correct |
18 ms |
23916 KB |
n=100 |
11 |
Correct |
16 ms |
23916 KB |
n=100 |
12 |
Correct |
17 ms |
23916 KB |
n=100 |
13 |
Correct |
16 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
16 ms |
23916 KB |
n=100 |
16 |
Correct |
16 ms |
23916 KB |
n=100 |
17 |
Correct |
16 ms |
23916 KB |
n=100 |
18 |
Correct |
18 ms |
23916 KB |
n=100 |
19 |
Correct |
20 ms |
23916 KB |
n=100 |
20 |
Correct |
17 ms |
23916 KB |
n=100 |
21 |
Correct |
17 ms |
23916 KB |
n=100 |
22 |
Correct |
16 ms |
23916 KB |
n=100 |
23 |
Correct |
19 ms |
23916 KB |
n=100 |
24 |
Correct |
16 ms |
23916 KB |
n=100 |
25 |
Correct |
17 ms |
23916 KB |
n=100 |
26 |
Correct |
19 ms |
23916 KB |
n=12 |
27 |
Correct |
19 ms |
23916 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
n=5 |
2 |
Correct |
17 ms |
23916 KB |
n=100 |
3 |
Correct |
17 ms |
23916 KB |
n=100 |
4 |
Correct |
19 ms |
23916 KB |
n=100 |
5 |
Correct |
17 ms |
23916 KB |
n=100 |
6 |
Correct |
17 ms |
23916 KB |
n=100 |
7 |
Correct |
19 ms |
23916 KB |
n=100 |
8 |
Correct |
16 ms |
23916 KB |
n=100 |
9 |
Correct |
16 ms |
23916 KB |
n=100 |
10 |
Correct |
18 ms |
23916 KB |
n=100 |
11 |
Correct |
16 ms |
23916 KB |
n=100 |
12 |
Correct |
17 ms |
23916 KB |
n=100 |
13 |
Correct |
16 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
16 ms |
23916 KB |
n=100 |
16 |
Correct |
16 ms |
23916 KB |
n=100 |
17 |
Correct |
16 ms |
23916 KB |
n=100 |
18 |
Correct |
18 ms |
23916 KB |
n=100 |
19 |
Correct |
20 ms |
23916 KB |
n=100 |
20 |
Correct |
17 ms |
23916 KB |
n=100 |
21 |
Correct |
17 ms |
23916 KB |
n=100 |
22 |
Correct |
16 ms |
23916 KB |
n=100 |
23 |
Correct |
19 ms |
23916 KB |
n=100 |
24 |
Correct |
16 ms |
23916 KB |
n=100 |
25 |
Correct |
17 ms |
23916 KB |
n=100 |
26 |
Correct |
19 ms |
23916 KB |
n=12 |
27 |
Correct |
19 ms |
23916 KB |
n=100 |
28 |
Correct |
20 ms |
24044 KB |
n=500 |
29 |
Correct |
18 ms |
24044 KB |
n=500 |
30 |
Correct |
18 ms |
24044 KB |
n=500 |
31 |
Correct |
20 ms |
24044 KB |
n=500 |
32 |
Correct |
18 ms |
24044 KB |
n=500 |
33 |
Correct |
18 ms |
24044 KB |
n=500 |
34 |
Correct |
21 ms |
24044 KB |
n=500 |
35 |
Correct |
18 ms |
24044 KB |
n=500 |
36 |
Correct |
18 ms |
24044 KB |
n=500 |
37 |
Correct |
20 ms |
24300 KB |
n=500 |
38 |
Correct |
18 ms |
24044 KB |
n=500 |
39 |
Correct |
18 ms |
24044 KB |
n=500 |
40 |
Correct |
18 ms |
24044 KB |
n=500 |
41 |
Correct |
19 ms |
24064 KB |
n=500 |
42 |
Correct |
19 ms |
24308 KB |
n=500 |
43 |
Correct |
18 ms |
24044 KB |
n=500 |
44 |
Correct |
18 ms |
24044 KB |
n=500 |
45 |
Correct |
18 ms |
24044 KB |
n=500 |
46 |
Correct |
18 ms |
24192 KB |
n=500 |
47 |
Correct |
19 ms |
24044 KB |
n=500 |
48 |
Correct |
19 ms |
24172 KB |
n=500 |
49 |
Correct |
21 ms |
24044 KB |
n=500 |
50 |
Correct |
22 ms |
24044 KB |
n=500 |
51 |
Correct |
18 ms |
24044 KB |
n=500 |
52 |
Correct |
18 ms |
24172 KB |
n=500 |
53 |
Correct |
19 ms |
24044 KB |
n=500 |
54 |
Correct |
18 ms |
24044 KB |
n=500 |
55 |
Correct |
20 ms |
24044 KB |
n=278 |
56 |
Correct |
18 ms |
24044 KB |
n=500 |
57 |
Correct |
18 ms |
24044 KB |
n=500 |
58 |
Correct |
19 ms |
24044 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
n=5 |
2 |
Correct |
17 ms |
23916 KB |
n=100 |
3 |
Correct |
17 ms |
23916 KB |
n=100 |
4 |
Correct |
19 ms |
23916 KB |
n=100 |
5 |
Correct |
17 ms |
23916 KB |
n=100 |
6 |
Correct |
17 ms |
23916 KB |
n=100 |
7 |
Correct |
19 ms |
23916 KB |
n=100 |
8 |
Correct |
16 ms |
23916 KB |
n=100 |
9 |
Correct |
16 ms |
23916 KB |
n=100 |
10 |
Correct |
18 ms |
23916 KB |
n=100 |
11 |
Correct |
16 ms |
23916 KB |
n=100 |
12 |
Correct |
17 ms |
23916 KB |
n=100 |
13 |
Correct |
16 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
16 ms |
23916 KB |
n=100 |
16 |
Correct |
16 ms |
23916 KB |
n=100 |
17 |
Correct |
16 ms |
23916 KB |
n=100 |
18 |
Correct |
18 ms |
23916 KB |
n=100 |
19 |
Correct |
20 ms |
23916 KB |
n=100 |
20 |
Correct |
17 ms |
23916 KB |
n=100 |
21 |
Correct |
17 ms |
23916 KB |
n=100 |
22 |
Correct |
16 ms |
23916 KB |
n=100 |
23 |
Correct |
19 ms |
23916 KB |
n=100 |
24 |
Correct |
16 ms |
23916 KB |
n=100 |
25 |
Correct |
17 ms |
23916 KB |
n=100 |
26 |
Correct |
19 ms |
23916 KB |
n=12 |
27 |
Correct |
19 ms |
23916 KB |
n=100 |
28 |
Correct |
20 ms |
24044 KB |
n=500 |
29 |
Correct |
18 ms |
24044 KB |
n=500 |
30 |
Correct |
18 ms |
24044 KB |
n=500 |
31 |
Correct |
20 ms |
24044 KB |
n=500 |
32 |
Correct |
18 ms |
24044 KB |
n=500 |
33 |
Correct |
18 ms |
24044 KB |
n=500 |
34 |
Correct |
21 ms |
24044 KB |
n=500 |
35 |
Correct |
18 ms |
24044 KB |
n=500 |
36 |
Correct |
18 ms |
24044 KB |
n=500 |
37 |
Correct |
20 ms |
24300 KB |
n=500 |
38 |
Correct |
18 ms |
24044 KB |
n=500 |
39 |
Correct |
18 ms |
24044 KB |
n=500 |
40 |
Correct |
18 ms |
24044 KB |
n=500 |
41 |
Correct |
19 ms |
24064 KB |
n=500 |
42 |
Correct |
19 ms |
24308 KB |
n=500 |
43 |
Correct |
18 ms |
24044 KB |
n=500 |
44 |
Correct |
18 ms |
24044 KB |
n=500 |
45 |
Correct |
18 ms |
24044 KB |
n=500 |
46 |
Correct |
18 ms |
24192 KB |
n=500 |
47 |
Correct |
19 ms |
24044 KB |
n=500 |
48 |
Correct |
19 ms |
24172 KB |
n=500 |
49 |
Correct |
21 ms |
24044 KB |
n=500 |
50 |
Correct |
22 ms |
24044 KB |
n=500 |
51 |
Correct |
18 ms |
24044 KB |
n=500 |
52 |
Correct |
18 ms |
24172 KB |
n=500 |
53 |
Correct |
19 ms |
24044 KB |
n=500 |
54 |
Correct |
18 ms |
24044 KB |
n=500 |
55 |
Correct |
20 ms |
24044 KB |
n=278 |
56 |
Correct |
18 ms |
24044 KB |
n=500 |
57 |
Correct |
18 ms |
24044 KB |
n=500 |
58 |
Correct |
19 ms |
24044 KB |
n=500 |
59 |
Correct |
24 ms |
24684 KB |
n=2000 |
60 |
Correct |
25 ms |
24812 KB |
n=2000 |
61 |
Correct |
28 ms |
24684 KB |
n=2000 |
62 |
Correct |
24 ms |
24684 KB |
n=2000 |
63 |
Correct |
25 ms |
24684 KB |
n=2000 |
64 |
Correct |
24 ms |
24684 KB |
n=2000 |
65 |
Correct |
29 ms |
24684 KB |
n=2000 |
66 |
Correct |
29 ms |
24812 KB |
n=2000 |
67 |
Correct |
24 ms |
24684 KB |
n=2000 |
68 |
Correct |
24 ms |
24684 KB |
n=2000 |
69 |
Correct |
26 ms |
24684 KB |
n=2000 |
70 |
Correct |
29 ms |
24684 KB |
n=2000 |
71 |
Correct |
26 ms |
24684 KB |
n=2000 |
72 |
Correct |
26 ms |
24684 KB |
n=2000 |
73 |
Correct |
28 ms |
24684 KB |
n=2000 |
74 |
Correct |
23 ms |
24684 KB |
n=1844 |
75 |
Correct |
25 ms |
24684 KB |
n=2000 |
76 |
Correct |
24 ms |
24812 KB |
n=2000 |
77 |
Correct |
24 ms |
24684 KB |
n=2000 |
78 |
Correct |
24 ms |
24684 KB |
n=2000 |
79 |
Correct |
24 ms |
24684 KB |
n=2000 |
80 |
Correct |
24 ms |
24812 KB |
n=2000 |
81 |
Correct |
25 ms |
24684 KB |
n=2000 |
82 |
Correct |
24 ms |
24684 KB |
n=2000 |
83 |
Correct |
24 ms |
24812 KB |
n=2000 |
84 |
Correct |
31 ms |
24684 KB |
n=2000 |
85 |
Correct |
28 ms |
24684 KB |
n=2000 |
86 |
Correct |
24 ms |
24684 KB |
n=2000 |
87 |
Correct |
24 ms |
24684 KB |
n=2000 |
88 |
Correct |
26 ms |
24812 KB |
n=2000 |
89 |
Correct |
27 ms |
24812 KB |
n=2000 |
90 |
Correct |
27 ms |
24812 KB |
n=2000 |
91 |
Correct |
26 ms |
24684 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
n=5 |
2 |
Correct |
17 ms |
23916 KB |
n=100 |
3 |
Correct |
17 ms |
23916 KB |
n=100 |
4 |
Correct |
19 ms |
23916 KB |
n=100 |
5 |
Correct |
17 ms |
23916 KB |
n=100 |
6 |
Correct |
17 ms |
23916 KB |
n=100 |
7 |
Correct |
19 ms |
23916 KB |
n=100 |
8 |
Correct |
16 ms |
23916 KB |
n=100 |
9 |
Correct |
16 ms |
23916 KB |
n=100 |
10 |
Correct |
18 ms |
23916 KB |
n=100 |
11 |
Correct |
16 ms |
23916 KB |
n=100 |
12 |
Correct |
17 ms |
23916 KB |
n=100 |
13 |
Correct |
16 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
16 ms |
23916 KB |
n=100 |
16 |
Correct |
16 ms |
23916 KB |
n=100 |
17 |
Correct |
16 ms |
23916 KB |
n=100 |
18 |
Correct |
18 ms |
23916 KB |
n=100 |
19 |
Correct |
20 ms |
23916 KB |
n=100 |
20 |
Correct |
17 ms |
23916 KB |
n=100 |
21 |
Correct |
17 ms |
23916 KB |
n=100 |
22 |
Correct |
16 ms |
23916 KB |
n=100 |
23 |
Correct |
19 ms |
23916 KB |
n=100 |
24 |
Correct |
16 ms |
23916 KB |
n=100 |
25 |
Correct |
17 ms |
23916 KB |
n=100 |
26 |
Correct |
19 ms |
23916 KB |
n=12 |
27 |
Correct |
19 ms |
23916 KB |
n=100 |
28 |
Correct |
20 ms |
24044 KB |
n=500 |
29 |
Correct |
18 ms |
24044 KB |
n=500 |
30 |
Correct |
18 ms |
24044 KB |
n=500 |
31 |
Correct |
20 ms |
24044 KB |
n=500 |
32 |
Correct |
18 ms |
24044 KB |
n=500 |
33 |
Correct |
18 ms |
24044 KB |
n=500 |
34 |
Correct |
21 ms |
24044 KB |
n=500 |
35 |
Correct |
18 ms |
24044 KB |
n=500 |
36 |
Correct |
18 ms |
24044 KB |
n=500 |
37 |
Correct |
20 ms |
24300 KB |
n=500 |
38 |
Correct |
18 ms |
24044 KB |
n=500 |
39 |
Correct |
18 ms |
24044 KB |
n=500 |
40 |
Correct |
18 ms |
24044 KB |
n=500 |
41 |
Correct |
19 ms |
24064 KB |
n=500 |
42 |
Correct |
19 ms |
24308 KB |
n=500 |
43 |
Correct |
18 ms |
24044 KB |
n=500 |
44 |
Correct |
18 ms |
24044 KB |
n=500 |
45 |
Correct |
18 ms |
24044 KB |
n=500 |
46 |
Correct |
18 ms |
24192 KB |
n=500 |
47 |
Correct |
19 ms |
24044 KB |
n=500 |
48 |
Correct |
19 ms |
24172 KB |
n=500 |
49 |
Correct |
21 ms |
24044 KB |
n=500 |
50 |
Correct |
22 ms |
24044 KB |
n=500 |
51 |
Correct |
18 ms |
24044 KB |
n=500 |
52 |
Correct |
18 ms |
24172 KB |
n=500 |
53 |
Correct |
19 ms |
24044 KB |
n=500 |
54 |
Correct |
18 ms |
24044 KB |
n=500 |
55 |
Correct |
20 ms |
24044 KB |
n=278 |
56 |
Correct |
18 ms |
24044 KB |
n=500 |
57 |
Correct |
18 ms |
24044 KB |
n=500 |
58 |
Correct |
19 ms |
24044 KB |
n=500 |
59 |
Correct |
24 ms |
24684 KB |
n=2000 |
60 |
Correct |
25 ms |
24812 KB |
n=2000 |
61 |
Correct |
28 ms |
24684 KB |
n=2000 |
62 |
Correct |
24 ms |
24684 KB |
n=2000 |
63 |
Correct |
25 ms |
24684 KB |
n=2000 |
64 |
Correct |
24 ms |
24684 KB |
n=2000 |
65 |
Correct |
29 ms |
24684 KB |
n=2000 |
66 |
Correct |
29 ms |
24812 KB |
n=2000 |
67 |
Correct |
24 ms |
24684 KB |
n=2000 |
68 |
Correct |
24 ms |
24684 KB |
n=2000 |
69 |
Correct |
26 ms |
24684 KB |
n=2000 |
70 |
Correct |
29 ms |
24684 KB |
n=2000 |
71 |
Correct |
26 ms |
24684 KB |
n=2000 |
72 |
Correct |
26 ms |
24684 KB |
n=2000 |
73 |
Correct |
28 ms |
24684 KB |
n=2000 |
74 |
Correct |
23 ms |
24684 KB |
n=1844 |
75 |
Correct |
25 ms |
24684 KB |
n=2000 |
76 |
Correct |
24 ms |
24812 KB |
n=2000 |
77 |
Correct |
24 ms |
24684 KB |
n=2000 |
78 |
Correct |
24 ms |
24684 KB |
n=2000 |
79 |
Correct |
24 ms |
24684 KB |
n=2000 |
80 |
Correct |
24 ms |
24812 KB |
n=2000 |
81 |
Correct |
25 ms |
24684 KB |
n=2000 |
82 |
Correct |
24 ms |
24684 KB |
n=2000 |
83 |
Correct |
24 ms |
24812 KB |
n=2000 |
84 |
Correct |
31 ms |
24684 KB |
n=2000 |
85 |
Correct |
28 ms |
24684 KB |
n=2000 |
86 |
Correct |
24 ms |
24684 KB |
n=2000 |
87 |
Correct |
24 ms |
24684 KB |
n=2000 |
88 |
Correct |
26 ms |
24812 KB |
n=2000 |
89 |
Correct |
27 ms |
24812 KB |
n=2000 |
90 |
Correct |
27 ms |
24812 KB |
n=2000 |
91 |
Correct |
26 ms |
24684 KB |
n=2000 |
92 |
Correct |
1399 ms |
122628 KB |
n=200000 |
93 |
Correct |
1410 ms |
127552 KB |
n=200000 |
94 |
Correct |
1349 ms |
130668 KB |
n=200000 |
95 |
Correct |
1365 ms |
122336 KB |
n=200000 |
96 |
Correct |
1405 ms |
122460 KB |
n=200000 |
97 |
Correct |
1420 ms |
126444 KB |
n=200000 |
98 |
Correct |
1367 ms |
122336 KB |
n=200000 |
99 |
Correct |
1465 ms |
122840 KB |
n=200000 |
100 |
Correct |
1406 ms |
122508 KB |
n=200000 |
101 |
Correct |
1334 ms |
132016 KB |
n=200000 |
102 |
Correct |
1238 ms |
123628 KB |
n=200000 |
103 |
Correct |
1160 ms |
123640 KB |
n=200000 |
104 |
Correct |
1233 ms |
123676 KB |
n=200000 |
105 |
Correct |
1248 ms |
123952 KB |
n=200000 |
106 |
Correct |
1221 ms |
124012 KB |
n=200000 |
107 |
Correct |
1222 ms |
124028 KB |
n=200000 |
108 |
Correct |
1379 ms |
122476 KB |
n=200000 |
109 |
Correct |
1307 ms |
122328 KB |
n=200000 |
110 |
Correct |
1356 ms |
122348 KB |
n=200000 |
111 |
Correct |
1410 ms |
121880 KB |
n=200000 |
112 |
Correct |
1317 ms |
131052 KB |
n=200000 |
113 |
Correct |
1391 ms |
126692 KB |
n=200000 |
114 |
Correct |
1338 ms |
121952 KB |
n=200000 |
115 |
Correct |
1442 ms |
124428 KB |
n=200000 |
116 |
Correct |
1325 ms |
122592 KB |
n=200000 |
117 |
Correct |
1277 ms |
131308 KB |
n=200000 |
118 |
Correct |
1415 ms |
125376 KB |
n=200000 |
119 |
Correct |
1295 ms |
122592 KB |
n=200000 |
120 |
Correct |
1235 ms |
130924 KB |
n=200000 |
121 |
Correct |
1223 ms |
131380 KB |
n=200000 |
122 |
Correct |
1211 ms |
131436 KB |
n=200000 |
123 |
Correct |
1165 ms |
123804 KB |
n=200000 |
124 |
Correct |
427 ms |
44012 KB |
n=25264 |