#include<bits/stdc++.h>
#define el '\n'
#define fi first
#define sc second
#define int ll
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
const int mod=1e9+7;
const int N=1e5+11;
int n, m, q, up[23][N], h[N], nod[4*N], lc[2003][2003], a[N];
vector<int> adj[N];
void dfs(int u, int pa)
{
up[0][u]=pa;
for(int i=1; i<=20; i++) up[i][u]=up[i-1][up[i-1][u]];
for(int v:adj[u])
{
if(v!=pa)
{
h[v]=h[u]+1;
dfs(v, u);
}
}
}
int jump(int k, int u)
{
for(int i=0; i<=20; i++)
{
if(k>>i&1) u=up[i][u];
}
return u;
}
int lca(int u, int v)
{
if(h[u]<h[v]) swap(u, v);
u=jump(h[u]-h[v], u);
if(u==v) return u;
for(int i=20; i>=0; i--)
{
if(up[i][u]!=up[i][v])
{
u=up[i][u];
v=up[i][v];
}
}
return up[0][u];
}
void glow(int id, int l, int r)
{
if(l==r)
{
nod[id]=a[l];
return;
}
int mid=(l+r)/2;
glow(id*2, l, mid);
glow(id*2+1, mid+1, r);
nod[id]=lc[nod[id*2]][nod[id*2+1]];
}
void update(int id, int l, int r, int pos, int val)
{
if(r<pos||pos<l) return;
if(l==r && l==pos)
{
nod[id]=val;
return;
}
int mid=(l+r)/2;
if(pos<=mid) update(id*2, l, mid, pos, val);
else update(id*2+1, mid+1, r, pos, val);
nod[id]=lc[nod[id*2]][nod[id*2+1]];
}
int get(int id, int l, int r, int u, int v)
{
if(r<u || v<l) return n+1;
if(u<=l && r<=v) return nod[id];
int mid=(l+r)/2;
int s1=get(id*2, l, mid, u, v);
int s2=get(id*2+1, mid+1, r, u, v);
return lc[s1][s2];
}
void sub1()
{
while(q--)
{
int tt;
cin >> tt;
if(tt==1)
{
int pos, v;
cin >> pos >> v;
update(1, 1, m, pos, v);
a[pos]=v;
}
else
{
int l, r, v;
cin >> l >> r >> v;
int ch=0, s1, s2;
for(int i=l; i<=r; i++)
{
if(ch) continue;
int low=i, high=r;
while(low<=high)
{
int mid=(low+high)/2;
int cc=get(1, 1, m, i, mid);
if(h[cc]>h[v]) low=mid+1;
else if(h[cc]<h[v]) high=mid-1;
else if(cc==v)
{
ch=1;
s1=i;
s2=mid;
break;
}
else break;
}
}
if(ch) cout << s1 << ' ' << s2 << el;
else cout << -1 << ' ' << -1 << el;
}
}
}
void sol()
{
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);
}
h[1]=1;
dfs(1, 0);
for(int i=1; i<=m; i++) cin >> a[i];
for(int i=1; i<=n; i++) for(int j=i; j<=n; j++) lc[i][j]=lc[j][i]=lca(i, j);
for(int i=1; i<=n; i++) lc[n+1][i]=lc[i][n+1]=i;
glow(1, 1, m);
// cout << get(1, 1, m, 1, 1) << el;
sub1();
// cout << lca(5, 3);
}
signed main()
{
// freopen("divisor.INP", "r", stdin);
// freopen("divisor.OUT", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--)
{
sol();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2908 KB |
n=5 |
2 |
Correct |
2 ms |
3416 KB |
n=100 |
3 |
Correct |
2 ms |
3420 KB |
n=100 |
4 |
Correct |
2 ms |
3420 KB |
n=100 |
5 |
Correct |
2 ms |
3420 KB |
n=100 |
6 |
Correct |
3 ms |
3420 KB |
n=100 |
7 |
Correct |
4 ms |
3672 KB |
n=100 |
8 |
Correct |
2 ms |
3420 KB |
n=100 |
9 |
Correct |
2 ms |
3416 KB |
n=100 |
10 |
Correct |
2 ms |
3420 KB |
n=100 |
11 |
Correct |
2 ms |
3416 KB |
n=100 |
12 |
Correct |
2 ms |
3416 KB |
n=100 |
13 |
Correct |
2 ms |
3420 KB |
n=100 |
14 |
Correct |
2 ms |
3420 KB |
n=100 |
15 |
Correct |
2 ms |
3420 KB |
n=100 |
16 |
Correct |
2 ms |
3420 KB |
n=100 |
17 |
Correct |
2 ms |
3420 KB |
n=100 |
18 |
Correct |
2 ms |
3448 KB |
n=100 |
19 |
Correct |
2 ms |
3416 KB |
n=100 |
20 |
Correct |
2 ms |
3420 KB |
n=100 |
21 |
Correct |
2 ms |
3420 KB |
n=100 |
22 |
Correct |
2 ms |
3420 KB |
n=100 |
23 |
Correct |
3 ms |
3420 KB |
n=100 |
24 |
Correct |
2 ms |
3420 KB |
n=100 |
25 |
Correct |
2 ms |
3416 KB |
n=100 |
26 |
Correct |
1 ms |
2908 KB |
n=12 |
27 |
Correct |
2 ms |
3328 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2908 KB |
n=5 |
2 |
Correct |
2 ms |
3416 KB |
n=100 |
3 |
Correct |
2 ms |
3420 KB |
n=100 |
4 |
Correct |
2 ms |
3420 KB |
n=100 |
5 |
Correct |
2 ms |
3420 KB |
n=100 |
6 |
Correct |
3 ms |
3420 KB |
n=100 |
7 |
Correct |
4 ms |
3672 KB |
n=100 |
8 |
Correct |
2 ms |
3420 KB |
n=100 |
9 |
Correct |
2 ms |
3416 KB |
n=100 |
10 |
Correct |
2 ms |
3420 KB |
n=100 |
11 |
Correct |
2 ms |
3416 KB |
n=100 |
12 |
Correct |
2 ms |
3416 KB |
n=100 |
13 |
Correct |
2 ms |
3420 KB |
n=100 |
14 |
Correct |
2 ms |
3420 KB |
n=100 |
15 |
Correct |
2 ms |
3420 KB |
n=100 |
16 |
Correct |
2 ms |
3420 KB |
n=100 |
17 |
Correct |
2 ms |
3420 KB |
n=100 |
18 |
Correct |
2 ms |
3448 KB |
n=100 |
19 |
Correct |
2 ms |
3416 KB |
n=100 |
20 |
Correct |
2 ms |
3420 KB |
n=100 |
21 |
Correct |
2 ms |
3420 KB |
n=100 |
22 |
Correct |
2 ms |
3420 KB |
n=100 |
23 |
Correct |
3 ms |
3420 KB |
n=100 |
24 |
Correct |
2 ms |
3420 KB |
n=100 |
25 |
Correct |
2 ms |
3416 KB |
n=100 |
26 |
Correct |
1 ms |
2908 KB |
n=12 |
27 |
Correct |
2 ms |
3328 KB |
n=100 |
28 |
Correct |
11 ms |
7004 KB |
n=500 |
29 |
Correct |
20 ms |
7048 KB |
n=500 |
30 |
Correct |
22 ms |
7260 KB |
n=500 |
31 |
Correct |
19 ms |
7004 KB |
n=500 |
32 |
Correct |
11 ms |
7000 KB |
n=500 |
33 |
Correct |
23 ms |
6996 KB |
n=500 |
34 |
Correct |
11 ms |
7004 KB |
n=500 |
35 |
Correct |
18 ms |
7004 KB |
n=500 |
36 |
Correct |
94 ms |
7004 KB |
n=500 |
37 |
Correct |
105 ms |
7004 KB |
n=500 |
38 |
Correct |
94 ms |
7004 KB |
n=500 |
39 |
Correct |
40 ms |
7004 KB |
n=500 |
40 |
Correct |
46 ms |
7004 KB |
n=500 |
41 |
Correct |
40 ms |
7004 KB |
n=500 |
42 |
Correct |
59 ms |
7000 KB |
n=500 |
43 |
Correct |
51 ms |
7004 KB |
n=500 |
44 |
Correct |
50 ms |
7000 KB |
n=500 |
45 |
Correct |
11 ms |
7000 KB |
n=500 |
46 |
Correct |
18 ms |
7004 KB |
n=500 |
47 |
Correct |
17 ms |
6900 KB |
n=500 |
48 |
Correct |
12 ms |
7004 KB |
n=500 |
49 |
Correct |
16 ms |
7004 KB |
n=500 |
50 |
Correct |
26 ms |
7004 KB |
n=500 |
51 |
Correct |
25 ms |
7004 KB |
n=500 |
52 |
Correct |
35 ms |
7004 KB |
n=500 |
53 |
Correct |
29 ms |
7000 KB |
n=500 |
54 |
Correct |
18 ms |
7000 KB |
n=500 |
55 |
Correct |
6 ms |
4700 KB |
n=278 |
56 |
Correct |
86 ms |
7004 KB |
n=500 |
57 |
Correct |
85 ms |
7004 KB |
n=500 |
58 |
Correct |
76 ms |
7012 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2908 KB |
n=5 |
2 |
Correct |
2 ms |
3416 KB |
n=100 |
3 |
Correct |
2 ms |
3420 KB |
n=100 |
4 |
Correct |
2 ms |
3420 KB |
n=100 |
5 |
Correct |
2 ms |
3420 KB |
n=100 |
6 |
Correct |
3 ms |
3420 KB |
n=100 |
7 |
Correct |
4 ms |
3672 KB |
n=100 |
8 |
Correct |
2 ms |
3420 KB |
n=100 |
9 |
Correct |
2 ms |
3416 KB |
n=100 |
10 |
Correct |
2 ms |
3420 KB |
n=100 |
11 |
Correct |
2 ms |
3416 KB |
n=100 |
12 |
Correct |
2 ms |
3416 KB |
n=100 |
13 |
Correct |
2 ms |
3420 KB |
n=100 |
14 |
Correct |
2 ms |
3420 KB |
n=100 |
15 |
Correct |
2 ms |
3420 KB |
n=100 |
16 |
Correct |
2 ms |
3420 KB |
n=100 |
17 |
Correct |
2 ms |
3420 KB |
n=100 |
18 |
Correct |
2 ms |
3448 KB |
n=100 |
19 |
Correct |
2 ms |
3416 KB |
n=100 |
20 |
Correct |
2 ms |
3420 KB |
n=100 |
21 |
Correct |
2 ms |
3420 KB |
n=100 |
22 |
Correct |
2 ms |
3420 KB |
n=100 |
23 |
Correct |
3 ms |
3420 KB |
n=100 |
24 |
Correct |
2 ms |
3420 KB |
n=100 |
25 |
Correct |
2 ms |
3416 KB |
n=100 |
26 |
Correct |
1 ms |
2908 KB |
n=12 |
27 |
Correct |
2 ms |
3328 KB |
n=100 |
28 |
Correct |
11 ms |
7004 KB |
n=500 |
29 |
Correct |
20 ms |
7048 KB |
n=500 |
30 |
Correct |
22 ms |
7260 KB |
n=500 |
31 |
Correct |
19 ms |
7004 KB |
n=500 |
32 |
Correct |
11 ms |
7000 KB |
n=500 |
33 |
Correct |
23 ms |
6996 KB |
n=500 |
34 |
Correct |
11 ms |
7004 KB |
n=500 |
35 |
Correct |
18 ms |
7004 KB |
n=500 |
36 |
Correct |
94 ms |
7004 KB |
n=500 |
37 |
Correct |
105 ms |
7004 KB |
n=500 |
38 |
Correct |
94 ms |
7004 KB |
n=500 |
39 |
Correct |
40 ms |
7004 KB |
n=500 |
40 |
Correct |
46 ms |
7004 KB |
n=500 |
41 |
Correct |
40 ms |
7004 KB |
n=500 |
42 |
Correct |
59 ms |
7000 KB |
n=500 |
43 |
Correct |
51 ms |
7004 KB |
n=500 |
44 |
Correct |
50 ms |
7000 KB |
n=500 |
45 |
Correct |
11 ms |
7000 KB |
n=500 |
46 |
Correct |
18 ms |
7004 KB |
n=500 |
47 |
Correct |
17 ms |
6900 KB |
n=500 |
48 |
Correct |
12 ms |
7004 KB |
n=500 |
49 |
Correct |
16 ms |
7004 KB |
n=500 |
50 |
Correct |
26 ms |
7004 KB |
n=500 |
51 |
Correct |
25 ms |
7004 KB |
n=500 |
52 |
Correct |
35 ms |
7004 KB |
n=500 |
53 |
Correct |
29 ms |
7000 KB |
n=500 |
54 |
Correct |
18 ms |
7000 KB |
n=500 |
55 |
Correct |
6 ms |
4700 KB |
n=278 |
56 |
Correct |
86 ms |
7004 KB |
n=500 |
57 |
Correct |
85 ms |
7004 KB |
n=500 |
58 |
Correct |
76 ms |
7012 KB |
n=500 |
59 |
Correct |
166 ms |
35032 KB |
n=2000 |
60 |
Correct |
417 ms |
34924 KB |
n=2000 |
61 |
Correct |
421 ms |
34644 KB |
n=2000 |
62 |
Correct |
358 ms |
34900 KB |
n=2000 |
63 |
Correct |
164 ms |
34644 KB |
n=2000 |
64 |
Correct |
381 ms |
34644 KB |
n=2000 |
65 |
Correct |
152 ms |
34644 KB |
n=2000 |
66 |
Correct |
451 ms |
34636 KB |
n=2000 |
67 |
Correct |
197 ms |
34712 KB |
n=2000 |
68 |
Correct |
401 ms |
34804 KB |
n=2000 |
69 |
Correct |
2215 ms |
34900 KB |
n=2000 |
70 |
Correct |
2197 ms |
34896 KB |
n=2000 |
71 |
Correct |
2213 ms |
34900 KB |
n=2000 |
72 |
Correct |
886 ms |
34796 KB |
n=2000 |
73 |
Correct |
902 ms |
35064 KB |
n=2000 |
74 |
Correct |
135 ms |
32312 KB |
n=1844 |
75 |
Correct |
897 ms |
34644 KB |
n=2000 |
76 |
Correct |
1227 ms |
34896 KB |
n=2000 |
77 |
Correct |
1241 ms |
34804 KB |
n=2000 |
78 |
Correct |
1259 ms |
34792 KB |
n=2000 |
79 |
Correct |
165 ms |
34644 KB |
n=2000 |
80 |
Correct |
402 ms |
34620 KB |
n=2000 |
81 |
Correct |
380 ms |
34788 KB |
n=2000 |
82 |
Correct |
160 ms |
34644 KB |
n=2000 |
83 |
Correct |
398 ms |
34640 KB |
n=2000 |
84 |
Correct |
624 ms |
34720 KB |
n=2000 |
85 |
Correct |
611 ms |
34828 KB |
n=2000 |
86 |
Correct |
663 ms |
34900 KB |
n=2000 |
87 |
Correct |
706 ms |
34812 KB |
n=2000 |
88 |
Correct |
2447 ms |
34880 KB |
n=2000 |
89 |
Correct |
2352 ms |
34880 KB |
n=2000 |
90 |
Correct |
471 ms |
34876 KB |
n=2000 |
91 |
Correct |
1570 ms |
34808 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2908 KB |
n=5 |
2 |
Correct |
2 ms |
3416 KB |
n=100 |
3 |
Correct |
2 ms |
3420 KB |
n=100 |
4 |
Correct |
2 ms |
3420 KB |
n=100 |
5 |
Correct |
2 ms |
3420 KB |
n=100 |
6 |
Correct |
3 ms |
3420 KB |
n=100 |
7 |
Correct |
4 ms |
3672 KB |
n=100 |
8 |
Correct |
2 ms |
3420 KB |
n=100 |
9 |
Correct |
2 ms |
3416 KB |
n=100 |
10 |
Correct |
2 ms |
3420 KB |
n=100 |
11 |
Correct |
2 ms |
3416 KB |
n=100 |
12 |
Correct |
2 ms |
3416 KB |
n=100 |
13 |
Correct |
2 ms |
3420 KB |
n=100 |
14 |
Correct |
2 ms |
3420 KB |
n=100 |
15 |
Correct |
2 ms |
3420 KB |
n=100 |
16 |
Correct |
2 ms |
3420 KB |
n=100 |
17 |
Correct |
2 ms |
3420 KB |
n=100 |
18 |
Correct |
2 ms |
3448 KB |
n=100 |
19 |
Correct |
2 ms |
3416 KB |
n=100 |
20 |
Correct |
2 ms |
3420 KB |
n=100 |
21 |
Correct |
2 ms |
3420 KB |
n=100 |
22 |
Correct |
2 ms |
3420 KB |
n=100 |
23 |
Correct |
3 ms |
3420 KB |
n=100 |
24 |
Correct |
2 ms |
3420 KB |
n=100 |
25 |
Correct |
2 ms |
3416 KB |
n=100 |
26 |
Correct |
1 ms |
2908 KB |
n=12 |
27 |
Correct |
2 ms |
3328 KB |
n=100 |
28 |
Correct |
11 ms |
7004 KB |
n=500 |
29 |
Correct |
20 ms |
7048 KB |
n=500 |
30 |
Correct |
22 ms |
7260 KB |
n=500 |
31 |
Correct |
19 ms |
7004 KB |
n=500 |
32 |
Correct |
11 ms |
7000 KB |
n=500 |
33 |
Correct |
23 ms |
6996 KB |
n=500 |
34 |
Correct |
11 ms |
7004 KB |
n=500 |
35 |
Correct |
18 ms |
7004 KB |
n=500 |
36 |
Correct |
94 ms |
7004 KB |
n=500 |
37 |
Correct |
105 ms |
7004 KB |
n=500 |
38 |
Correct |
94 ms |
7004 KB |
n=500 |
39 |
Correct |
40 ms |
7004 KB |
n=500 |
40 |
Correct |
46 ms |
7004 KB |
n=500 |
41 |
Correct |
40 ms |
7004 KB |
n=500 |
42 |
Correct |
59 ms |
7000 KB |
n=500 |
43 |
Correct |
51 ms |
7004 KB |
n=500 |
44 |
Correct |
50 ms |
7000 KB |
n=500 |
45 |
Correct |
11 ms |
7000 KB |
n=500 |
46 |
Correct |
18 ms |
7004 KB |
n=500 |
47 |
Correct |
17 ms |
6900 KB |
n=500 |
48 |
Correct |
12 ms |
7004 KB |
n=500 |
49 |
Correct |
16 ms |
7004 KB |
n=500 |
50 |
Correct |
26 ms |
7004 KB |
n=500 |
51 |
Correct |
25 ms |
7004 KB |
n=500 |
52 |
Correct |
35 ms |
7004 KB |
n=500 |
53 |
Correct |
29 ms |
7000 KB |
n=500 |
54 |
Correct |
18 ms |
7000 KB |
n=500 |
55 |
Correct |
6 ms |
4700 KB |
n=278 |
56 |
Correct |
86 ms |
7004 KB |
n=500 |
57 |
Correct |
85 ms |
7004 KB |
n=500 |
58 |
Correct |
76 ms |
7012 KB |
n=500 |
59 |
Correct |
166 ms |
35032 KB |
n=2000 |
60 |
Correct |
417 ms |
34924 KB |
n=2000 |
61 |
Correct |
421 ms |
34644 KB |
n=2000 |
62 |
Correct |
358 ms |
34900 KB |
n=2000 |
63 |
Correct |
164 ms |
34644 KB |
n=2000 |
64 |
Correct |
381 ms |
34644 KB |
n=2000 |
65 |
Correct |
152 ms |
34644 KB |
n=2000 |
66 |
Correct |
451 ms |
34636 KB |
n=2000 |
67 |
Correct |
197 ms |
34712 KB |
n=2000 |
68 |
Correct |
401 ms |
34804 KB |
n=2000 |
69 |
Correct |
2215 ms |
34900 KB |
n=2000 |
70 |
Correct |
2197 ms |
34896 KB |
n=2000 |
71 |
Correct |
2213 ms |
34900 KB |
n=2000 |
72 |
Correct |
886 ms |
34796 KB |
n=2000 |
73 |
Correct |
902 ms |
35064 KB |
n=2000 |
74 |
Correct |
135 ms |
32312 KB |
n=1844 |
75 |
Correct |
897 ms |
34644 KB |
n=2000 |
76 |
Correct |
1227 ms |
34896 KB |
n=2000 |
77 |
Correct |
1241 ms |
34804 KB |
n=2000 |
78 |
Correct |
1259 ms |
34792 KB |
n=2000 |
79 |
Correct |
165 ms |
34644 KB |
n=2000 |
80 |
Correct |
402 ms |
34620 KB |
n=2000 |
81 |
Correct |
380 ms |
34788 KB |
n=2000 |
82 |
Correct |
160 ms |
34644 KB |
n=2000 |
83 |
Correct |
398 ms |
34640 KB |
n=2000 |
84 |
Correct |
624 ms |
34720 KB |
n=2000 |
85 |
Correct |
611 ms |
34828 KB |
n=2000 |
86 |
Correct |
663 ms |
34900 KB |
n=2000 |
87 |
Correct |
706 ms |
34812 KB |
n=2000 |
88 |
Correct |
2447 ms |
34880 KB |
n=2000 |
89 |
Correct |
2352 ms |
34880 KB |
n=2000 |
90 |
Correct |
471 ms |
34876 KB |
n=2000 |
91 |
Correct |
1570 ms |
34808 KB |
n=2000 |
92 |
Runtime error |
125 ms |
83660 KB |
Execution killed with signal 11 |
93 |
Halted |
0 ms |
0 KB |
- |