# include <bits/stdc++.h>
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define deb(x) cerr << #x << " = " << x << endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll maxn = 2e5 + 25;
const ll inf = 1e18 + 0;
const ll mod = 1e9 + 123;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
using namespace std;
ll n, m, q, timer;
vector <ll> g[maxn];
ll up[maxn][21];
ll tin[maxn];
ll tout[maxn];
ll a[maxn];
set <ll> st[maxn];
set <ll> qq[maxn];
void dfs (ll v = 1, ll pa = 1)
{
tin[v] = ++timer;
up[v][0] = pa;
for (ll j = 1; j <= 19; ++j)
{
up[v][j] = up[up[v][j - 1]][j - 1];
}
for (ll to : g[v])
{
if (to == pa) continue;
dfs(to, v);
}
tout[v] = timer;
}
bool anc (ll u, ll v)
{
return (tin[u] <= tin[v] && tout[v] <= tout[u]);
}
ll lca (ll u, ll v)
{
if (anc(u, v)) return u;
if (anc(v, u)) return v;
for (ll j = 19; j >= 0; --j)
{
if (!anc(up[u][j], v))
{
u = up[u][j];
}
}
return up[u][0];
}
void ma1n (/* SABR */)
{
cin >> n >> m >> q;
for (ll i = 2, u, v; i <= n; ++i)
{
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
dfs ();
for (ll i = 1; i <= m; ++i)
{
cin >> a[i];
if (i > 1)
{
st[lca(a[i], a[i - 1])].insert(i);
}
qq[a[i]].insert(i);
}
while (q--)
{
ll type;
cin >> type;
if (type == 1)
{
ll pos, val;
cin >> pos >> val;
qq[a[pos]].erase(pos);
qq[val].insert(pos);
if (pos > 1)
{
st[lca(a[pos], a[pos - 1])].erase(pos);
st[lca(val, a[pos - 1])].insert(pos);
}
if (pos < m)
{
st[lca(a[pos], a[pos + 1])].erase(pos);
st[lca(val, a[pos + 1])].insert(pos);
}
a[pos] = val;
}
if (type == 2)
{
ll l, r, v;
cin >> l >> r >> v;
auto it = qq[v].lower_bound(l);
if (it != qq[v].end() && *it <= r)
{
cout << *it << ' ' << *it << nl;
}
else
{
auto it = st[v].lower_bound(l);
if (it != st[v].end() && *it <= r)
{
cout << *it << ' ' << *it + 1 << nl;
}
else
{
cout << -1 << ' ' << -1 << nl;
}
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
int ttt = 1;
// cin >> ttt;
for (int test = 1; test <= ttt; ++test)
{
// cout << "Case " << test << ":" << ' ';
ma1n();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
23764 KB |
Wrong output format. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
23764 KB |
Wrong output format. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
23764 KB |
Wrong output format. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
23764 KB |
Wrong output format. |
2 |
Halted |
0 ms |
0 KB |
- |