#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll maxN=3e5+1;
vector<ll> g[maxN];
ll par[maxN][20],h[maxN],p[maxN];
void dfs(ll u, ll pp)
{
for(auto v:g[u])
{
if(v!=pp)
{
p[v]=u;
par[v][0]=u;
h[v]=h[u]+1;
for(int i=1;i<=18;i++) par[v][i]=par[par[v][i-1]][i-1];
dfs(v,u);
}
}
}
ll LCA(ll u, ll v)
{
if(h[u]<h[v]) swap(u,v);
ll log=log2(h[u])+1;
for(int i=log;i>=0;i--)
{
if(h[par[u][i]]>=h[v]) u=par[u][i];
}
if(u==v) return u;
for(int i=log;i>=0;i--)
{
if(par[u][i]!=par[v][i]) u=par[u][i],v=par[v][i];
}
return p[u];
}
ll n,m,q;
set<int> s[maxN],t[maxN];
ll a[maxN];
#define pb push_back
ll lca[maxN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >>n>>m>>q;
for(int i=1;i<n;i++)
{
ll u,v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
p[1]=1;
for(int i=0;i<=18;i++) par[1][i]=1;
dfs(1,0);
for(int i=1;i<=m;i++) cin >> a[i],s[a[i]].insert(i);
for(int i=1;i<m;i++)
{
lca[i]=LCA(a[i],a[i+1]);
t[lca[i]].insert(i);
}
//for(auto z:t[1]) cout << z<<' ';
//cout << '\n';
for(int i=1;i<=q;i++)
{
ll type,l,r,k;
cin >> type;
if(type==1)
{
cin >> l >> r;
s[a[l]].erase(l);
t[lca[l]].erase(l);
t[lca[l-1]].erase(l-1);
a[l]=r;
s[a[l]].insert(l);
if(l<n)
{
lca[l]=LCA(a[l],a[l+1]);
t[lca[l]].insert(l);
}
if(l>1)
{
lca[l-1]=LCA(a[l-1],a[l]);
t[lca[l-1]].insert(l-1);
}
}
else
{
cin >> l >> r >> k;
auto x=s[k].lower_bound(l);
if(*x<=r&&x!=s[k].end())
{
cout << *x <<' '<<*x<<'\n';
continue;
}
else
{
x=t[k].lower_bound(l);
if(*x<=r-1&&x!=t[k].end())
{
cout << *x<<' '<<*x+1<<'\n';
}
else
{
cout <<-1<< ' '<<-1<<'\n';
}
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
35540 KB |
n=5 |
2 |
Correct |
17 ms |
35524 KB |
n=100 |
3 |
Correct |
16 ms |
35552 KB |
n=100 |
4 |
Correct |
16 ms |
35540 KB |
n=100 |
5 |
Correct |
16 ms |
35540 KB |
n=100 |
6 |
Correct |
16 ms |
35540 KB |
n=100 |
7 |
Correct |
20 ms |
35648 KB |
n=100 |
8 |
Correct |
19 ms |
35556 KB |
n=100 |
9 |
Correct |
21 ms |
35556 KB |
n=100 |
10 |
Correct |
16 ms |
35572 KB |
n=100 |
11 |
Correct |
18 ms |
35572 KB |
n=100 |
12 |
Correct |
16 ms |
35536 KB |
n=100 |
13 |
Correct |
17 ms |
35540 KB |
n=100 |
14 |
Correct |
17 ms |
35548 KB |
n=100 |
15 |
Correct |
17 ms |
35548 KB |
n=100 |
16 |
Correct |
17 ms |
35568 KB |
n=100 |
17 |
Correct |
17 ms |
35580 KB |
n=100 |
18 |
Correct |
16 ms |
35552 KB |
n=100 |
19 |
Correct |
16 ms |
35540 KB |
n=100 |
20 |
Correct |
17 ms |
35560 KB |
n=100 |
21 |
Correct |
16 ms |
35560 KB |
n=100 |
22 |
Correct |
16 ms |
35540 KB |
n=100 |
23 |
Correct |
16 ms |
35540 KB |
n=100 |
24 |
Correct |
17 ms |
35528 KB |
n=100 |
25 |
Correct |
20 ms |
35556 KB |
n=100 |
26 |
Correct |
17 ms |
35556 KB |
n=12 |
27 |
Correct |
16 ms |
35556 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
35540 KB |
n=5 |
2 |
Correct |
17 ms |
35524 KB |
n=100 |
3 |
Correct |
16 ms |
35552 KB |
n=100 |
4 |
Correct |
16 ms |
35540 KB |
n=100 |
5 |
Correct |
16 ms |
35540 KB |
n=100 |
6 |
Correct |
16 ms |
35540 KB |
n=100 |
7 |
Correct |
20 ms |
35648 KB |
n=100 |
8 |
Correct |
19 ms |
35556 KB |
n=100 |
9 |
Correct |
21 ms |
35556 KB |
n=100 |
10 |
Correct |
16 ms |
35572 KB |
n=100 |
11 |
Correct |
18 ms |
35572 KB |
n=100 |
12 |
Correct |
16 ms |
35536 KB |
n=100 |
13 |
Correct |
17 ms |
35540 KB |
n=100 |
14 |
Correct |
17 ms |
35548 KB |
n=100 |
15 |
Correct |
17 ms |
35548 KB |
n=100 |
16 |
Correct |
17 ms |
35568 KB |
n=100 |
17 |
Correct |
17 ms |
35580 KB |
n=100 |
18 |
Correct |
16 ms |
35552 KB |
n=100 |
19 |
Correct |
16 ms |
35540 KB |
n=100 |
20 |
Correct |
17 ms |
35560 KB |
n=100 |
21 |
Correct |
16 ms |
35560 KB |
n=100 |
22 |
Correct |
16 ms |
35540 KB |
n=100 |
23 |
Correct |
16 ms |
35540 KB |
n=100 |
24 |
Correct |
17 ms |
35528 KB |
n=100 |
25 |
Correct |
20 ms |
35556 KB |
n=100 |
26 |
Correct |
17 ms |
35556 KB |
n=12 |
27 |
Correct |
16 ms |
35556 KB |
n=100 |
28 |
Correct |
17 ms |
35700 KB |
n=500 |
29 |
Correct |
21 ms |
35640 KB |
n=500 |
30 |
Correct |
19 ms |
35668 KB |
n=500 |
31 |
Correct |
20 ms |
35696 KB |
n=500 |
32 |
Correct |
18 ms |
35668 KB |
n=500 |
33 |
Correct |
19 ms |
35668 KB |
n=500 |
34 |
Correct |
18 ms |
35692 KB |
n=500 |
35 |
Correct |
17 ms |
35668 KB |
n=500 |
36 |
Correct |
16 ms |
35788 KB |
n=500 |
37 |
Correct |
16 ms |
35668 KB |
n=500 |
38 |
Correct |
18 ms |
35732 KB |
n=500 |
39 |
Correct |
16 ms |
35668 KB |
n=500 |
40 |
Correct |
19 ms |
35692 KB |
n=500 |
41 |
Correct |
18 ms |
35636 KB |
n=500 |
42 |
Correct |
23 ms |
35672 KB |
n=500 |
43 |
Correct |
17 ms |
35668 KB |
n=500 |
44 |
Correct |
17 ms |
35700 KB |
n=500 |
45 |
Correct |
20 ms |
35696 KB |
n=500 |
46 |
Correct |
17 ms |
35708 KB |
n=500 |
47 |
Correct |
18 ms |
35696 KB |
n=500 |
48 |
Correct |
31 ms |
35696 KB |
n=500 |
49 |
Correct |
20 ms |
35668 KB |
n=500 |
50 |
Correct |
18 ms |
35656 KB |
n=500 |
51 |
Correct |
17 ms |
35624 KB |
n=500 |
52 |
Correct |
18 ms |
35684 KB |
n=500 |
53 |
Correct |
18 ms |
35668 KB |
n=500 |
54 |
Correct |
17 ms |
35660 KB |
n=500 |
55 |
Correct |
19 ms |
35668 KB |
n=278 |
56 |
Correct |
17 ms |
35744 KB |
n=500 |
57 |
Correct |
18 ms |
35668 KB |
n=500 |
58 |
Correct |
17 ms |
35728 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
35540 KB |
n=5 |
2 |
Correct |
17 ms |
35524 KB |
n=100 |
3 |
Correct |
16 ms |
35552 KB |
n=100 |
4 |
Correct |
16 ms |
35540 KB |
n=100 |
5 |
Correct |
16 ms |
35540 KB |
n=100 |
6 |
Correct |
16 ms |
35540 KB |
n=100 |
7 |
Correct |
20 ms |
35648 KB |
n=100 |
8 |
Correct |
19 ms |
35556 KB |
n=100 |
9 |
Correct |
21 ms |
35556 KB |
n=100 |
10 |
Correct |
16 ms |
35572 KB |
n=100 |
11 |
Correct |
18 ms |
35572 KB |
n=100 |
12 |
Correct |
16 ms |
35536 KB |
n=100 |
13 |
Correct |
17 ms |
35540 KB |
n=100 |
14 |
Correct |
17 ms |
35548 KB |
n=100 |
15 |
Correct |
17 ms |
35548 KB |
n=100 |
16 |
Correct |
17 ms |
35568 KB |
n=100 |
17 |
Correct |
17 ms |
35580 KB |
n=100 |
18 |
Correct |
16 ms |
35552 KB |
n=100 |
19 |
Correct |
16 ms |
35540 KB |
n=100 |
20 |
Correct |
17 ms |
35560 KB |
n=100 |
21 |
Correct |
16 ms |
35560 KB |
n=100 |
22 |
Correct |
16 ms |
35540 KB |
n=100 |
23 |
Correct |
16 ms |
35540 KB |
n=100 |
24 |
Correct |
17 ms |
35528 KB |
n=100 |
25 |
Correct |
20 ms |
35556 KB |
n=100 |
26 |
Correct |
17 ms |
35556 KB |
n=12 |
27 |
Correct |
16 ms |
35556 KB |
n=100 |
28 |
Correct |
17 ms |
35700 KB |
n=500 |
29 |
Correct |
21 ms |
35640 KB |
n=500 |
30 |
Correct |
19 ms |
35668 KB |
n=500 |
31 |
Correct |
20 ms |
35696 KB |
n=500 |
32 |
Correct |
18 ms |
35668 KB |
n=500 |
33 |
Correct |
19 ms |
35668 KB |
n=500 |
34 |
Correct |
18 ms |
35692 KB |
n=500 |
35 |
Correct |
17 ms |
35668 KB |
n=500 |
36 |
Correct |
16 ms |
35788 KB |
n=500 |
37 |
Correct |
16 ms |
35668 KB |
n=500 |
38 |
Correct |
18 ms |
35732 KB |
n=500 |
39 |
Correct |
16 ms |
35668 KB |
n=500 |
40 |
Correct |
19 ms |
35692 KB |
n=500 |
41 |
Correct |
18 ms |
35636 KB |
n=500 |
42 |
Correct |
23 ms |
35672 KB |
n=500 |
43 |
Correct |
17 ms |
35668 KB |
n=500 |
44 |
Correct |
17 ms |
35700 KB |
n=500 |
45 |
Correct |
20 ms |
35696 KB |
n=500 |
46 |
Correct |
17 ms |
35708 KB |
n=500 |
47 |
Correct |
18 ms |
35696 KB |
n=500 |
48 |
Correct |
31 ms |
35696 KB |
n=500 |
49 |
Correct |
20 ms |
35668 KB |
n=500 |
50 |
Correct |
18 ms |
35656 KB |
n=500 |
51 |
Correct |
17 ms |
35624 KB |
n=500 |
52 |
Correct |
18 ms |
35684 KB |
n=500 |
53 |
Correct |
18 ms |
35668 KB |
n=500 |
54 |
Correct |
17 ms |
35660 KB |
n=500 |
55 |
Correct |
19 ms |
35668 KB |
n=278 |
56 |
Correct |
17 ms |
35744 KB |
n=500 |
57 |
Correct |
18 ms |
35668 KB |
n=500 |
58 |
Correct |
17 ms |
35728 KB |
n=500 |
59 |
Correct |
23 ms |
36152 KB |
n=2000 |
60 |
Correct |
21 ms |
36300 KB |
n=2000 |
61 |
Correct |
19 ms |
36348 KB |
n=2000 |
62 |
Correct |
19 ms |
36208 KB |
n=2000 |
63 |
Correct |
19 ms |
36180 KB |
n=2000 |
64 |
Correct |
19 ms |
36308 KB |
n=2000 |
65 |
Correct |
24 ms |
36172 KB |
n=2000 |
66 |
Correct |
23 ms |
36296 KB |
n=2000 |
67 |
Correct |
20 ms |
36208 KB |
n=2000 |
68 |
Correct |
20 ms |
36340 KB |
n=2000 |
69 |
Correct |
18 ms |
36180 KB |
n=2000 |
70 |
Correct |
18 ms |
36180 KB |
n=2000 |
71 |
Correct |
19 ms |
36172 KB |
n=2000 |
72 |
Correct |
24 ms |
36252 KB |
n=2000 |
73 |
Correct |
19 ms |
36180 KB |
n=2000 |
74 |
Correct |
18 ms |
36204 KB |
n=1844 |
75 |
Correct |
20 ms |
36224 KB |
n=2000 |
76 |
Correct |
21 ms |
36164 KB |
n=2000 |
77 |
Correct |
22 ms |
36188 KB |
n=2000 |
78 |
Correct |
18 ms |
36288 KB |
n=2000 |
79 |
Correct |
19 ms |
36180 KB |
n=2000 |
80 |
Correct |
21 ms |
36356 KB |
n=2000 |
81 |
Correct |
21 ms |
36212 KB |
n=2000 |
82 |
Correct |
19 ms |
36212 KB |
n=2000 |
83 |
Correct |
19 ms |
36336 KB |
n=2000 |
84 |
Correct |
19 ms |
36240 KB |
n=2000 |
85 |
Correct |
20 ms |
36220 KB |
n=2000 |
86 |
Correct |
20 ms |
36308 KB |
n=2000 |
87 |
Correct |
22 ms |
36308 KB |
n=2000 |
88 |
Correct |
20 ms |
36308 KB |
n=2000 |
89 |
Correct |
21 ms |
36340 KB |
n=2000 |
90 |
Correct |
19 ms |
36332 KB |
n=2000 |
91 |
Correct |
19 ms |
36192 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
35540 KB |
n=5 |
2 |
Correct |
17 ms |
35524 KB |
n=100 |
3 |
Correct |
16 ms |
35552 KB |
n=100 |
4 |
Correct |
16 ms |
35540 KB |
n=100 |
5 |
Correct |
16 ms |
35540 KB |
n=100 |
6 |
Correct |
16 ms |
35540 KB |
n=100 |
7 |
Correct |
20 ms |
35648 KB |
n=100 |
8 |
Correct |
19 ms |
35556 KB |
n=100 |
9 |
Correct |
21 ms |
35556 KB |
n=100 |
10 |
Correct |
16 ms |
35572 KB |
n=100 |
11 |
Correct |
18 ms |
35572 KB |
n=100 |
12 |
Correct |
16 ms |
35536 KB |
n=100 |
13 |
Correct |
17 ms |
35540 KB |
n=100 |
14 |
Correct |
17 ms |
35548 KB |
n=100 |
15 |
Correct |
17 ms |
35548 KB |
n=100 |
16 |
Correct |
17 ms |
35568 KB |
n=100 |
17 |
Correct |
17 ms |
35580 KB |
n=100 |
18 |
Correct |
16 ms |
35552 KB |
n=100 |
19 |
Correct |
16 ms |
35540 KB |
n=100 |
20 |
Correct |
17 ms |
35560 KB |
n=100 |
21 |
Correct |
16 ms |
35560 KB |
n=100 |
22 |
Correct |
16 ms |
35540 KB |
n=100 |
23 |
Correct |
16 ms |
35540 KB |
n=100 |
24 |
Correct |
17 ms |
35528 KB |
n=100 |
25 |
Correct |
20 ms |
35556 KB |
n=100 |
26 |
Correct |
17 ms |
35556 KB |
n=12 |
27 |
Correct |
16 ms |
35556 KB |
n=100 |
28 |
Correct |
17 ms |
35700 KB |
n=500 |
29 |
Correct |
21 ms |
35640 KB |
n=500 |
30 |
Correct |
19 ms |
35668 KB |
n=500 |
31 |
Correct |
20 ms |
35696 KB |
n=500 |
32 |
Correct |
18 ms |
35668 KB |
n=500 |
33 |
Correct |
19 ms |
35668 KB |
n=500 |
34 |
Correct |
18 ms |
35692 KB |
n=500 |
35 |
Correct |
17 ms |
35668 KB |
n=500 |
36 |
Correct |
16 ms |
35788 KB |
n=500 |
37 |
Correct |
16 ms |
35668 KB |
n=500 |
38 |
Correct |
18 ms |
35732 KB |
n=500 |
39 |
Correct |
16 ms |
35668 KB |
n=500 |
40 |
Correct |
19 ms |
35692 KB |
n=500 |
41 |
Correct |
18 ms |
35636 KB |
n=500 |
42 |
Correct |
23 ms |
35672 KB |
n=500 |
43 |
Correct |
17 ms |
35668 KB |
n=500 |
44 |
Correct |
17 ms |
35700 KB |
n=500 |
45 |
Correct |
20 ms |
35696 KB |
n=500 |
46 |
Correct |
17 ms |
35708 KB |
n=500 |
47 |
Correct |
18 ms |
35696 KB |
n=500 |
48 |
Correct |
31 ms |
35696 KB |
n=500 |
49 |
Correct |
20 ms |
35668 KB |
n=500 |
50 |
Correct |
18 ms |
35656 KB |
n=500 |
51 |
Correct |
17 ms |
35624 KB |
n=500 |
52 |
Correct |
18 ms |
35684 KB |
n=500 |
53 |
Correct |
18 ms |
35668 KB |
n=500 |
54 |
Correct |
17 ms |
35660 KB |
n=500 |
55 |
Correct |
19 ms |
35668 KB |
n=278 |
56 |
Correct |
17 ms |
35744 KB |
n=500 |
57 |
Correct |
18 ms |
35668 KB |
n=500 |
58 |
Correct |
17 ms |
35728 KB |
n=500 |
59 |
Correct |
23 ms |
36152 KB |
n=2000 |
60 |
Correct |
21 ms |
36300 KB |
n=2000 |
61 |
Correct |
19 ms |
36348 KB |
n=2000 |
62 |
Correct |
19 ms |
36208 KB |
n=2000 |
63 |
Correct |
19 ms |
36180 KB |
n=2000 |
64 |
Correct |
19 ms |
36308 KB |
n=2000 |
65 |
Correct |
24 ms |
36172 KB |
n=2000 |
66 |
Correct |
23 ms |
36296 KB |
n=2000 |
67 |
Correct |
20 ms |
36208 KB |
n=2000 |
68 |
Correct |
20 ms |
36340 KB |
n=2000 |
69 |
Correct |
18 ms |
36180 KB |
n=2000 |
70 |
Correct |
18 ms |
36180 KB |
n=2000 |
71 |
Correct |
19 ms |
36172 KB |
n=2000 |
72 |
Correct |
24 ms |
36252 KB |
n=2000 |
73 |
Correct |
19 ms |
36180 KB |
n=2000 |
74 |
Correct |
18 ms |
36204 KB |
n=1844 |
75 |
Correct |
20 ms |
36224 KB |
n=2000 |
76 |
Correct |
21 ms |
36164 KB |
n=2000 |
77 |
Correct |
22 ms |
36188 KB |
n=2000 |
78 |
Correct |
18 ms |
36288 KB |
n=2000 |
79 |
Correct |
19 ms |
36180 KB |
n=2000 |
80 |
Correct |
21 ms |
36356 KB |
n=2000 |
81 |
Correct |
21 ms |
36212 KB |
n=2000 |
82 |
Correct |
19 ms |
36212 KB |
n=2000 |
83 |
Correct |
19 ms |
36336 KB |
n=2000 |
84 |
Correct |
19 ms |
36240 KB |
n=2000 |
85 |
Correct |
20 ms |
36220 KB |
n=2000 |
86 |
Correct |
20 ms |
36308 KB |
n=2000 |
87 |
Correct |
22 ms |
36308 KB |
n=2000 |
88 |
Correct |
20 ms |
36308 KB |
n=2000 |
89 |
Correct |
21 ms |
36340 KB |
n=2000 |
90 |
Correct |
19 ms |
36332 KB |
n=2000 |
91 |
Correct |
19 ms |
36192 KB |
n=2000 |
92 |
Correct |
655 ms |
107396 KB |
n=200000 |
93 |
Correct |
1152 ms |
113832 KB |
n=200000 |
94 |
Correct |
1081 ms |
118020 KB |
n=200000 |
95 |
Correct |
711 ms |
107188 KB |
n=200000 |
96 |
Correct |
610 ms |
107284 KB |
n=200000 |
97 |
Correct |
1138 ms |
112708 KB |
n=200000 |
98 |
Correct |
728 ms |
107232 KB |
n=200000 |
99 |
Correct |
802 ms |
107700 KB |
n=200000 |
100 |
Correct |
696 ms |
107392 KB |
n=200000 |
101 |
Correct |
1082 ms |
119280 KB |
n=200000 |
102 |
Correct |
398 ms |
108688 KB |
n=200000 |
103 |
Correct |
473 ms |
108604 KB |
n=200000 |
104 |
Correct |
442 ms |
108648 KB |
n=200000 |
105 |
Correct |
426 ms |
109116 KB |
n=200000 |
106 |
Correct |
445 ms |
109108 KB |
n=200000 |
107 |
Correct |
432 ms |
109088 KB |
n=200000 |
108 |
Correct |
761 ms |
107580 KB |
n=200000 |
109 |
Correct |
785 ms |
107640 KB |
n=200000 |
110 |
Correct |
776 ms |
107468 KB |
n=200000 |
111 |
Correct |
637 ms |
106768 KB |
n=200000 |
112 |
Correct |
1046 ms |
118316 KB |
n=200000 |
113 |
Correct |
1133 ms |
112808 KB |
n=200000 |
114 |
Correct |
602 ms |
106800 KB |
n=200000 |
115 |
Correct |
1171 ms |
110148 KB |
n=200000 |
116 |
Correct |
589 ms |
107380 KB |
n=200000 |
117 |
Correct |
1046 ms |
118628 KB |
n=200000 |
118 |
Correct |
1189 ms |
111336 KB |
n=200000 |
119 |
Correct |
626 ms |
107336 KB |
n=200000 |
120 |
Correct |
1070 ms |
118372 KB |
n=200000 |
121 |
Correct |
1010 ms |
118364 KB |
n=200000 |
122 |
Correct |
1037 ms |
118668 KB |
n=200000 |
123 |
Correct |
443 ms |
108796 KB |
n=200000 |
124 |
Incorrect |
236 ms |
54132 KB |
Jury has the answer but participant has not |
125 |
Halted |
0 ms |
0 KB |
- |