// Bolatulu
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define int long long
#define kanagattandirilmagandiktarinizdan ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define F first
#define S second
#define md (tl+tr)/2
#define TL v+v,tl,md
#define TR v+v+1,md+1,tr
#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
using namespace std;
int binpow(int a,int n,int M) {
if (n==0)
return 1;
if (n%2!=0)
return (a * binpow(a,n-1,M))%M;
int z=binpow(a,n/2,M);
return (z*z)%M;
}
const ll INF = 1e18;
const int N = 1e6+7;
const int M = 1e9+7;
const ll HZ = 1e5;
const int MAX = INT_MAX;
const int MIN = INT_MIN;
const db pi = 3.141592653;
const int P=31;
int n,m,q,tin[N],tout[N],t,up[20][N],a[N];
vector <int> g[N];
void dfs(int v,int p) {
tin[v] = ++t;
up[0][v] = p;
for (auto now: g[v]) {
if (now == p)
continue;
dfs(now, v);
}
tout[v] = ++t;
}
bool parent(int a,int b) {
return tin[a] <= tin[b] and tout[b] <= tout[a];
}
void prepare(int pw) {
if (pw == 20)
return;
for (int i = 1; i <= n; i++)
up[pw][i] = up[pw - 1][up[pw - 1][i]];
prepare(pw + 1);
}
int lca(int a,int b) {
if (parent(a, b))
return a;
if (parent(b, a))
return b;
for (int i = 19; i >= 0; i--)
if (up[i][a] and !parent(up[i][a], b))
a = up[i][a];
return up[0][a];
}
void solve() {
cin >> n >> m >> q;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v), g[v].push_back(u);
}
dfs(1, 0), prepare(1);
vector<set<int>> d(n + 1), s(n + 1);
for (int i = 1; i <= m; i++) {
cin >> a[i];
if (i > 1)
d[lca(a[i - 1], a[i])].insert(i - 1);
s[a[i]].insert(i);
}
while (q--) {
int tp, l, r, v;
cin >> tp;
if (tp == 1) {
cin >> l >> v;
if (l > 1)
d[lca(a[l - 1], a[l])].erase(l - 1), d[lca(a[l - 1], v)].insert(l - 1);
if (l < m)
d[lca(a[l], a[l + 1])].erase(l), d[lca(v, a[l + 1])].insert(l);
s[a[l]].erase(l), s[v].insert(l);
a[l] = v;
} else {
cin >> l >> r >> v;
if (!s[v].empty() and s[v].lower_bound(l) != s[v].end() and *s[v].lower_bound(l) <= r)
cout << *s[v].lower_bound(l) << ' ' << *s[v].lower_bound(l) << '\n';
else if (!d[v].empty() and d[v].lower_bound(l) != d[v].end() and *d[v].lower_bound(l) <= r - 1)
cout << *d[v].lower_bound(l) << ' ' << *d[v].lower_bound(l) + 1 << '\n';
else
cout << -1 << ' ' << -1 << '\n';
}
}
}
signed main() {
// freopen("lca.in", "r", stdin);
// freopen("lca.out", "w", stdout);
kanagattandirilmagandiktarinizdan
int test = 1, count = 1;
// cin >> test;
while (test--) {
// cout << "Case " << count << ":\n";
solve();
if (test)
// cout << '\n';
count++;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
68188 KB |
n=5 |
2 |
Correct |
11 ms |
68212 KB |
n=100 |
3 |
Correct |
10 ms |
68184 KB |
n=100 |
4 |
Correct |
10 ms |
68200 KB |
n=100 |
5 |
Correct |
11 ms |
68188 KB |
n=100 |
6 |
Correct |
10 ms |
68188 KB |
n=100 |
7 |
Correct |
10 ms |
68376 KB |
n=100 |
8 |
Correct |
11 ms |
68188 KB |
n=100 |
9 |
Correct |
8 ms |
53852 KB |
n=100 |
10 |
Correct |
8 ms |
53852 KB |
n=100 |
11 |
Correct |
9 ms |
53952 KB |
n=100 |
12 |
Correct |
10 ms |
68188 KB |
n=100 |
13 |
Correct |
11 ms |
68188 KB |
n=100 |
14 |
Correct |
10 ms |
68184 KB |
n=100 |
15 |
Correct |
10 ms |
68188 KB |
n=100 |
16 |
Correct |
11 ms |
68188 KB |
n=100 |
17 |
Correct |
12 ms |
68188 KB |
n=100 |
18 |
Correct |
11 ms |
68188 KB |
n=100 |
19 |
Correct |
9 ms |
59992 KB |
n=100 |
20 |
Correct |
11 ms |
68372 KB |
n=100 |
21 |
Correct |
10 ms |
68184 KB |
n=100 |
22 |
Correct |
10 ms |
68188 KB |
n=100 |
23 |
Correct |
10 ms |
68188 KB |
n=100 |
24 |
Correct |
10 ms |
68188 KB |
n=100 |
25 |
Correct |
10 ms |
64088 KB |
n=100 |
26 |
Correct |
10 ms |
59992 KB |
n=12 |
27 |
Correct |
10 ms |
68188 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
68188 KB |
n=5 |
2 |
Correct |
11 ms |
68212 KB |
n=100 |
3 |
Correct |
10 ms |
68184 KB |
n=100 |
4 |
Correct |
10 ms |
68200 KB |
n=100 |
5 |
Correct |
11 ms |
68188 KB |
n=100 |
6 |
Correct |
10 ms |
68188 KB |
n=100 |
7 |
Correct |
10 ms |
68376 KB |
n=100 |
8 |
Correct |
11 ms |
68188 KB |
n=100 |
9 |
Correct |
8 ms |
53852 KB |
n=100 |
10 |
Correct |
8 ms |
53852 KB |
n=100 |
11 |
Correct |
9 ms |
53952 KB |
n=100 |
12 |
Correct |
10 ms |
68188 KB |
n=100 |
13 |
Correct |
11 ms |
68188 KB |
n=100 |
14 |
Correct |
10 ms |
68184 KB |
n=100 |
15 |
Correct |
10 ms |
68188 KB |
n=100 |
16 |
Correct |
11 ms |
68188 KB |
n=100 |
17 |
Correct |
12 ms |
68188 KB |
n=100 |
18 |
Correct |
11 ms |
68188 KB |
n=100 |
19 |
Correct |
9 ms |
59992 KB |
n=100 |
20 |
Correct |
11 ms |
68372 KB |
n=100 |
21 |
Correct |
10 ms |
68184 KB |
n=100 |
22 |
Correct |
10 ms |
68188 KB |
n=100 |
23 |
Correct |
10 ms |
68188 KB |
n=100 |
24 |
Correct |
10 ms |
68188 KB |
n=100 |
25 |
Correct |
10 ms |
64088 KB |
n=100 |
26 |
Correct |
10 ms |
59992 KB |
n=12 |
27 |
Correct |
10 ms |
68188 KB |
n=100 |
28 |
Correct |
10 ms |
68440 KB |
n=500 |
29 |
Correct |
11 ms |
68444 KB |
n=500 |
30 |
Correct |
11 ms |
68440 KB |
n=500 |
31 |
Correct |
11 ms |
68476 KB |
n=500 |
32 |
Correct |
12 ms |
68444 KB |
n=500 |
33 |
Correct |
10 ms |
54360 KB |
n=500 |
34 |
Correct |
9 ms |
56156 KB |
n=500 |
35 |
Correct |
10 ms |
68444 KB |
n=500 |
36 |
Correct |
11 ms |
68444 KB |
n=500 |
37 |
Correct |
10 ms |
68444 KB |
n=500 |
38 |
Correct |
10 ms |
68444 KB |
n=500 |
39 |
Correct |
11 ms |
68476 KB |
n=500 |
40 |
Correct |
12 ms |
68440 KB |
n=500 |
41 |
Correct |
10 ms |
68444 KB |
n=500 |
42 |
Correct |
9 ms |
56156 KB |
n=500 |
43 |
Correct |
9 ms |
56184 KB |
n=500 |
44 |
Correct |
11 ms |
58204 KB |
n=500 |
45 |
Correct |
11 ms |
68444 KB |
n=500 |
46 |
Correct |
10 ms |
68444 KB |
n=500 |
47 |
Correct |
12 ms |
68440 KB |
n=500 |
48 |
Correct |
11 ms |
68444 KB |
n=500 |
49 |
Correct |
11 ms |
68444 KB |
n=500 |
50 |
Correct |
11 ms |
68444 KB |
n=500 |
51 |
Correct |
9 ms |
58204 KB |
n=500 |
52 |
Correct |
8 ms |
52060 KB |
n=500 |
53 |
Correct |
11 ms |
68456 KB |
n=500 |
54 |
Correct |
11 ms |
68444 KB |
n=500 |
55 |
Correct |
10 ms |
68444 KB |
n=278 |
56 |
Correct |
10 ms |
68476 KB |
n=500 |
57 |
Correct |
10 ms |
68444 KB |
n=500 |
58 |
Correct |
10 ms |
68444 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
68188 KB |
n=5 |
2 |
Correct |
11 ms |
68212 KB |
n=100 |
3 |
Correct |
10 ms |
68184 KB |
n=100 |
4 |
Correct |
10 ms |
68200 KB |
n=100 |
5 |
Correct |
11 ms |
68188 KB |
n=100 |
6 |
Correct |
10 ms |
68188 KB |
n=100 |
7 |
Correct |
10 ms |
68376 KB |
n=100 |
8 |
Correct |
11 ms |
68188 KB |
n=100 |
9 |
Correct |
8 ms |
53852 KB |
n=100 |
10 |
Correct |
8 ms |
53852 KB |
n=100 |
11 |
Correct |
9 ms |
53952 KB |
n=100 |
12 |
Correct |
10 ms |
68188 KB |
n=100 |
13 |
Correct |
11 ms |
68188 KB |
n=100 |
14 |
Correct |
10 ms |
68184 KB |
n=100 |
15 |
Correct |
10 ms |
68188 KB |
n=100 |
16 |
Correct |
11 ms |
68188 KB |
n=100 |
17 |
Correct |
12 ms |
68188 KB |
n=100 |
18 |
Correct |
11 ms |
68188 KB |
n=100 |
19 |
Correct |
9 ms |
59992 KB |
n=100 |
20 |
Correct |
11 ms |
68372 KB |
n=100 |
21 |
Correct |
10 ms |
68184 KB |
n=100 |
22 |
Correct |
10 ms |
68188 KB |
n=100 |
23 |
Correct |
10 ms |
68188 KB |
n=100 |
24 |
Correct |
10 ms |
68188 KB |
n=100 |
25 |
Correct |
10 ms |
64088 KB |
n=100 |
26 |
Correct |
10 ms |
59992 KB |
n=12 |
27 |
Correct |
10 ms |
68188 KB |
n=100 |
28 |
Correct |
10 ms |
68440 KB |
n=500 |
29 |
Correct |
11 ms |
68444 KB |
n=500 |
30 |
Correct |
11 ms |
68440 KB |
n=500 |
31 |
Correct |
11 ms |
68476 KB |
n=500 |
32 |
Correct |
12 ms |
68444 KB |
n=500 |
33 |
Correct |
10 ms |
54360 KB |
n=500 |
34 |
Correct |
9 ms |
56156 KB |
n=500 |
35 |
Correct |
10 ms |
68444 KB |
n=500 |
36 |
Correct |
11 ms |
68444 KB |
n=500 |
37 |
Correct |
10 ms |
68444 KB |
n=500 |
38 |
Correct |
10 ms |
68444 KB |
n=500 |
39 |
Correct |
11 ms |
68476 KB |
n=500 |
40 |
Correct |
12 ms |
68440 KB |
n=500 |
41 |
Correct |
10 ms |
68444 KB |
n=500 |
42 |
Correct |
9 ms |
56156 KB |
n=500 |
43 |
Correct |
9 ms |
56184 KB |
n=500 |
44 |
Correct |
11 ms |
58204 KB |
n=500 |
45 |
Correct |
11 ms |
68444 KB |
n=500 |
46 |
Correct |
10 ms |
68444 KB |
n=500 |
47 |
Correct |
12 ms |
68440 KB |
n=500 |
48 |
Correct |
11 ms |
68444 KB |
n=500 |
49 |
Correct |
11 ms |
68444 KB |
n=500 |
50 |
Correct |
11 ms |
68444 KB |
n=500 |
51 |
Correct |
9 ms |
58204 KB |
n=500 |
52 |
Correct |
8 ms |
52060 KB |
n=500 |
53 |
Correct |
11 ms |
68456 KB |
n=500 |
54 |
Correct |
11 ms |
68444 KB |
n=500 |
55 |
Correct |
10 ms |
68444 KB |
n=278 |
56 |
Correct |
10 ms |
68476 KB |
n=500 |
57 |
Correct |
10 ms |
68444 KB |
n=500 |
58 |
Correct |
10 ms |
68444 KB |
n=500 |
59 |
Correct |
13 ms |
68700 KB |
n=2000 |
60 |
Correct |
12 ms |
56664 KB |
n=2000 |
61 |
Correct |
12 ms |
52824 KB |
n=2000 |
62 |
Correct |
12 ms |
68696 KB |
n=2000 |
63 |
Correct |
12 ms |
68700 KB |
n=2000 |
64 |
Correct |
12 ms |
68696 KB |
n=2000 |
65 |
Correct |
13 ms |
69088 KB |
n=2000 |
66 |
Correct |
12 ms |
54620 KB |
n=2000 |
67 |
Correct |
11 ms |
54616 KB |
n=2000 |
68 |
Correct |
10 ms |
52568 KB |
n=2000 |
69 |
Correct |
12 ms |
68696 KB |
n=2000 |
70 |
Correct |
13 ms |
68700 KB |
n=2000 |
71 |
Correct |
11 ms |
68696 KB |
n=2000 |
72 |
Correct |
11 ms |
68696 KB |
n=2000 |
73 |
Correct |
12 ms |
68832 KB |
n=2000 |
74 |
Correct |
12 ms |
56412 KB |
n=1844 |
75 |
Correct |
10 ms |
56668 KB |
n=2000 |
76 |
Correct |
13 ms |
56664 KB |
n=2000 |
77 |
Correct |
11 ms |
58456 KB |
n=2000 |
78 |
Correct |
12 ms |
68700 KB |
n=2000 |
79 |
Correct |
12 ms |
68700 KB |
n=2000 |
80 |
Correct |
14 ms |
68700 KB |
n=2000 |
81 |
Correct |
12 ms |
68696 KB |
n=2000 |
82 |
Correct |
16 ms |
68700 KB |
n=2000 |
83 |
Correct |
11 ms |
56664 KB |
n=2000 |
84 |
Correct |
11 ms |
58456 KB |
n=2000 |
85 |
Correct |
11 ms |
56664 KB |
n=2000 |
86 |
Correct |
13 ms |
68696 KB |
n=2000 |
87 |
Correct |
12 ms |
68700 KB |
n=2000 |
88 |
Correct |
11 ms |
68696 KB |
n=2000 |
89 |
Correct |
11 ms |
68700 KB |
n=2000 |
90 |
Correct |
12 ms |
68700 KB |
n=2000 |
91 |
Correct |
11 ms |
56664 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
68188 KB |
n=5 |
2 |
Correct |
11 ms |
68212 KB |
n=100 |
3 |
Correct |
10 ms |
68184 KB |
n=100 |
4 |
Correct |
10 ms |
68200 KB |
n=100 |
5 |
Correct |
11 ms |
68188 KB |
n=100 |
6 |
Correct |
10 ms |
68188 KB |
n=100 |
7 |
Correct |
10 ms |
68376 KB |
n=100 |
8 |
Correct |
11 ms |
68188 KB |
n=100 |
9 |
Correct |
8 ms |
53852 KB |
n=100 |
10 |
Correct |
8 ms |
53852 KB |
n=100 |
11 |
Correct |
9 ms |
53952 KB |
n=100 |
12 |
Correct |
10 ms |
68188 KB |
n=100 |
13 |
Correct |
11 ms |
68188 KB |
n=100 |
14 |
Correct |
10 ms |
68184 KB |
n=100 |
15 |
Correct |
10 ms |
68188 KB |
n=100 |
16 |
Correct |
11 ms |
68188 KB |
n=100 |
17 |
Correct |
12 ms |
68188 KB |
n=100 |
18 |
Correct |
11 ms |
68188 KB |
n=100 |
19 |
Correct |
9 ms |
59992 KB |
n=100 |
20 |
Correct |
11 ms |
68372 KB |
n=100 |
21 |
Correct |
10 ms |
68184 KB |
n=100 |
22 |
Correct |
10 ms |
68188 KB |
n=100 |
23 |
Correct |
10 ms |
68188 KB |
n=100 |
24 |
Correct |
10 ms |
68188 KB |
n=100 |
25 |
Correct |
10 ms |
64088 KB |
n=100 |
26 |
Correct |
10 ms |
59992 KB |
n=12 |
27 |
Correct |
10 ms |
68188 KB |
n=100 |
28 |
Correct |
10 ms |
68440 KB |
n=500 |
29 |
Correct |
11 ms |
68444 KB |
n=500 |
30 |
Correct |
11 ms |
68440 KB |
n=500 |
31 |
Correct |
11 ms |
68476 KB |
n=500 |
32 |
Correct |
12 ms |
68444 KB |
n=500 |
33 |
Correct |
10 ms |
54360 KB |
n=500 |
34 |
Correct |
9 ms |
56156 KB |
n=500 |
35 |
Correct |
10 ms |
68444 KB |
n=500 |
36 |
Correct |
11 ms |
68444 KB |
n=500 |
37 |
Correct |
10 ms |
68444 KB |
n=500 |
38 |
Correct |
10 ms |
68444 KB |
n=500 |
39 |
Correct |
11 ms |
68476 KB |
n=500 |
40 |
Correct |
12 ms |
68440 KB |
n=500 |
41 |
Correct |
10 ms |
68444 KB |
n=500 |
42 |
Correct |
9 ms |
56156 KB |
n=500 |
43 |
Correct |
9 ms |
56184 KB |
n=500 |
44 |
Correct |
11 ms |
58204 KB |
n=500 |
45 |
Correct |
11 ms |
68444 KB |
n=500 |
46 |
Correct |
10 ms |
68444 KB |
n=500 |
47 |
Correct |
12 ms |
68440 KB |
n=500 |
48 |
Correct |
11 ms |
68444 KB |
n=500 |
49 |
Correct |
11 ms |
68444 KB |
n=500 |
50 |
Correct |
11 ms |
68444 KB |
n=500 |
51 |
Correct |
9 ms |
58204 KB |
n=500 |
52 |
Correct |
8 ms |
52060 KB |
n=500 |
53 |
Correct |
11 ms |
68456 KB |
n=500 |
54 |
Correct |
11 ms |
68444 KB |
n=500 |
55 |
Correct |
10 ms |
68444 KB |
n=278 |
56 |
Correct |
10 ms |
68476 KB |
n=500 |
57 |
Correct |
10 ms |
68444 KB |
n=500 |
58 |
Correct |
10 ms |
68444 KB |
n=500 |
59 |
Correct |
13 ms |
68700 KB |
n=2000 |
60 |
Correct |
12 ms |
56664 KB |
n=2000 |
61 |
Correct |
12 ms |
52824 KB |
n=2000 |
62 |
Correct |
12 ms |
68696 KB |
n=2000 |
63 |
Correct |
12 ms |
68700 KB |
n=2000 |
64 |
Correct |
12 ms |
68696 KB |
n=2000 |
65 |
Correct |
13 ms |
69088 KB |
n=2000 |
66 |
Correct |
12 ms |
54620 KB |
n=2000 |
67 |
Correct |
11 ms |
54616 KB |
n=2000 |
68 |
Correct |
10 ms |
52568 KB |
n=2000 |
69 |
Correct |
12 ms |
68696 KB |
n=2000 |
70 |
Correct |
13 ms |
68700 KB |
n=2000 |
71 |
Correct |
11 ms |
68696 KB |
n=2000 |
72 |
Correct |
11 ms |
68696 KB |
n=2000 |
73 |
Correct |
12 ms |
68832 KB |
n=2000 |
74 |
Correct |
12 ms |
56412 KB |
n=1844 |
75 |
Correct |
10 ms |
56668 KB |
n=2000 |
76 |
Correct |
13 ms |
56664 KB |
n=2000 |
77 |
Correct |
11 ms |
58456 KB |
n=2000 |
78 |
Correct |
12 ms |
68700 KB |
n=2000 |
79 |
Correct |
12 ms |
68700 KB |
n=2000 |
80 |
Correct |
14 ms |
68700 KB |
n=2000 |
81 |
Correct |
12 ms |
68696 KB |
n=2000 |
82 |
Correct |
16 ms |
68700 KB |
n=2000 |
83 |
Correct |
11 ms |
56664 KB |
n=2000 |
84 |
Correct |
11 ms |
58456 KB |
n=2000 |
85 |
Correct |
11 ms |
56664 KB |
n=2000 |
86 |
Correct |
13 ms |
68696 KB |
n=2000 |
87 |
Correct |
12 ms |
68700 KB |
n=2000 |
88 |
Correct |
11 ms |
68696 KB |
n=2000 |
89 |
Correct |
11 ms |
68700 KB |
n=2000 |
90 |
Correct |
12 ms |
68700 KB |
n=2000 |
91 |
Correct |
11 ms |
56664 KB |
n=2000 |
92 |
Correct |
692 ms |
127952 KB |
n=200000 |
93 |
Correct |
959 ms |
152904 KB |
n=200000 |
94 |
Correct |
557 ms |
158240 KB |
n=200000 |
95 |
Correct |
658 ms |
152508 KB |
n=200000 |
96 |
Correct |
612 ms |
149816 KB |
n=200000 |
97 |
Correct |
1121 ms |
156840 KB |
n=200000 |
98 |
Correct |
617 ms |
154848 KB |
n=200000 |
99 |
Correct |
779 ms |
129960 KB |
n=200000 |
100 |
Correct |
687 ms |
139988 KB |
n=200000 |
101 |
Correct |
432 ms |
161124 KB |
n=200000 |
102 |
Correct |
361 ms |
135420 KB |
n=200000 |
103 |
Correct |
327 ms |
144984 KB |
n=200000 |
104 |
Correct |
306 ms |
154512 KB |
n=200000 |
105 |
Correct |
306 ms |
157852 KB |
n=200000 |
106 |
Correct |
306 ms |
157776 KB |
n=200000 |
107 |
Correct |
312 ms |
157536 KB |
n=200000 |
108 |
Correct |
580 ms |
156676 KB |
n=200000 |
109 |
Correct |
566 ms |
156632 KB |
n=200000 |
110 |
Correct |
564 ms |
156568 KB |
n=200000 |
111 |
Correct |
541 ms |
156328 KB |
n=200000 |
112 |
Correct |
443 ms |
160688 KB |
n=200000 |
113 |
Correct |
909 ms |
154468 KB |
n=200000 |
114 |
Correct |
534 ms |
152764 KB |
n=200000 |
115 |
Correct |
1154 ms |
153304 KB |
n=200000 |
116 |
Correct |
536 ms |
152512 KB |
n=200000 |
117 |
Correct |
407 ms |
156356 KB |
n=200000 |
118 |
Correct |
1050 ms |
153428 KB |
n=200000 |
119 |
Correct |
517 ms |
152576 KB |
n=200000 |
120 |
Correct |
321 ms |
156240 KB |
n=200000 |
121 |
Correct |
332 ms |
156236 KB |
n=200000 |
122 |
Correct |
317 ms |
156752 KB |
n=200000 |
123 |
Correct |
308 ms |
153428 KB |
n=200000 |
124 |
Correct |
102 ms |
85076 KB |
n=25264 |