#include <bits/stdc++.h>
#define pb push_back
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define x first
#define y second
#define int long long
#define nl "\n"
using namespace std;
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair <ll, ll> pii;
const int N = (int)2e5 + 7;
const int M = (int)7e6 + 7;
const ll MOD = (ll)1e9 + 7;
const int inf = (int)1e9 + 7;
const ll INF = (ll)3e18 + 7;
pii dir[] = {{-1, -1}, {1, 1}, {-1, 1}, {1, -1}};
int n, m, q, a[N], t[4*N];
int timer, tin[N], tout[N], up[N][19];
vector<int> g[N];
set<pii> s[N];
void calc(int v, int pr) {
up[v][0] = pr;
tin[v] = ++timer;
for(int i = 1; i <= 18; ++i) {
up[v][i] = up[up[v][i-1]][i-1];
}
for(auto to : g[v]) {
if(to != pr) {
calc(to, v);
}
}
tout[v] = ++timer;
}
bool is_parent(int u, int v) {
return tin[u] <= tin[v] && tout[u] >= tout[v];
}
int lca(int u, int v) {
if(is_parent(u, v)) return u;
if(is_parent(v, u)) return v;
for(int i = 18; i >= 0; --i) {
if(!is_parent(up[u][i], v)) {
u = up[u][i];
}
}
return up[u][0];
}
void solve() {
cin >> n >> m >> q;
for(int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
for(int i = 1; i <= m; ++i) cin >> a[i];
calc(1, 1);
for(int i = 1; i < m; ++i) {
s[lca(a[i], a[i + 1])].insert({i, i + 1});
s[a[i]].insert({i, i});
}
while(q--) {
char tp;
cin >> tp;
int l, r, v;
if(tp == '1') {
cin >> l >> r;
if(l > 1) s[lca(a[l], a[l - 1])].erase({l - 1, l});
if(l < m) s[lca(a[l], a[l + 1])].erase({l, l + 1});
s[a[l]].erase({l, l});
a[l] = r;
if(l > 1) s[lca(a[l], a[l - 1])].insert({l - 1, l});
if(l < m) s[lca(a[l], a[l + 1])].insert({l, l + 1});
s[a[l]].insert({l, l});
} else {
cin >> l >> r >> v;
if(sz(s[v]) == 0) {
cout << "-1 -1\n";
continue;
}
auto e = *s[v].lower_bound({l, -inf});
if(e.y > r || e.x < l) {
cout << "-1 -1\n";
continue;
}
cout << e.x << ' ' << e.y << nl;
}
}
}
signed main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int test = 1;
//cin >> test;
for(int i = 1; i <= test; ++i) {
//cout << "Case " << i << ": ";
solve();
}
return 0;
}
/*
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14412 KB |
n=5 |
2 |
Correct |
8 ms |
14412 KB |
n=100 |
3 |
Correct |
8 ms |
14412 KB |
n=100 |
4 |
Correct |
8 ms |
14412 KB |
n=100 |
5 |
Correct |
10 ms |
14412 KB |
n=100 |
6 |
Correct |
7 ms |
14412 KB |
n=100 |
7 |
Correct |
7 ms |
14412 KB |
n=100 |
8 |
Correct |
8 ms |
14412 KB |
n=100 |
9 |
Correct |
7 ms |
14380 KB |
n=100 |
10 |
Correct |
7 ms |
14412 KB |
n=100 |
11 |
Correct |
8 ms |
14412 KB |
n=100 |
12 |
Correct |
10 ms |
14468 KB |
n=100 |
13 |
Correct |
8 ms |
14412 KB |
n=100 |
14 |
Correct |
8 ms |
14412 KB |
n=100 |
15 |
Correct |
8 ms |
14412 KB |
n=100 |
16 |
Correct |
8 ms |
14412 KB |
n=100 |
17 |
Incorrect |
8 ms |
14412 KB |
Jury has the answer but participant has not |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14412 KB |
n=5 |
2 |
Correct |
8 ms |
14412 KB |
n=100 |
3 |
Correct |
8 ms |
14412 KB |
n=100 |
4 |
Correct |
8 ms |
14412 KB |
n=100 |
5 |
Correct |
10 ms |
14412 KB |
n=100 |
6 |
Correct |
7 ms |
14412 KB |
n=100 |
7 |
Correct |
7 ms |
14412 KB |
n=100 |
8 |
Correct |
8 ms |
14412 KB |
n=100 |
9 |
Correct |
7 ms |
14380 KB |
n=100 |
10 |
Correct |
7 ms |
14412 KB |
n=100 |
11 |
Correct |
8 ms |
14412 KB |
n=100 |
12 |
Correct |
10 ms |
14468 KB |
n=100 |
13 |
Correct |
8 ms |
14412 KB |
n=100 |
14 |
Correct |
8 ms |
14412 KB |
n=100 |
15 |
Correct |
8 ms |
14412 KB |
n=100 |
16 |
Correct |
8 ms |
14412 KB |
n=100 |
17 |
Incorrect |
8 ms |
14412 KB |
Jury has the answer but participant has not |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14412 KB |
n=5 |
2 |
Correct |
8 ms |
14412 KB |
n=100 |
3 |
Correct |
8 ms |
14412 KB |
n=100 |
4 |
Correct |
8 ms |
14412 KB |
n=100 |
5 |
Correct |
10 ms |
14412 KB |
n=100 |
6 |
Correct |
7 ms |
14412 KB |
n=100 |
7 |
Correct |
7 ms |
14412 KB |
n=100 |
8 |
Correct |
8 ms |
14412 KB |
n=100 |
9 |
Correct |
7 ms |
14380 KB |
n=100 |
10 |
Correct |
7 ms |
14412 KB |
n=100 |
11 |
Correct |
8 ms |
14412 KB |
n=100 |
12 |
Correct |
10 ms |
14468 KB |
n=100 |
13 |
Correct |
8 ms |
14412 KB |
n=100 |
14 |
Correct |
8 ms |
14412 KB |
n=100 |
15 |
Correct |
8 ms |
14412 KB |
n=100 |
16 |
Correct |
8 ms |
14412 KB |
n=100 |
17 |
Incorrect |
8 ms |
14412 KB |
Jury has the answer but participant has not |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14412 KB |
n=5 |
2 |
Correct |
8 ms |
14412 KB |
n=100 |
3 |
Correct |
8 ms |
14412 KB |
n=100 |
4 |
Correct |
8 ms |
14412 KB |
n=100 |
5 |
Correct |
10 ms |
14412 KB |
n=100 |
6 |
Correct |
7 ms |
14412 KB |
n=100 |
7 |
Correct |
7 ms |
14412 KB |
n=100 |
8 |
Correct |
8 ms |
14412 KB |
n=100 |
9 |
Correct |
7 ms |
14380 KB |
n=100 |
10 |
Correct |
7 ms |
14412 KB |
n=100 |
11 |
Correct |
8 ms |
14412 KB |
n=100 |
12 |
Correct |
10 ms |
14468 KB |
n=100 |
13 |
Correct |
8 ms |
14412 KB |
n=100 |
14 |
Correct |
8 ms |
14412 KB |
n=100 |
15 |
Correct |
8 ms |
14412 KB |
n=100 |
16 |
Correct |
8 ms |
14412 KB |
n=100 |
17 |
Incorrect |
8 ms |
14412 KB |
Jury has the answer but participant has not |
18 |
Halted |
0 ms |
0 KB |
- |