이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define task "T"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 2e5 + 2;
int n, m, q, pa[18][N], dep[N], a[N];
vi g[N];
set<int> pos[N], pos1[N];
void dfs(int u, int p)
{
dep[u] = dep[p] + 1;
pa[u][0] = p;
rep(k, 1, 17) pa[u][k] = pa[pa[u][k - 1]][k - 1];
for (int v : g[u]) if (v != p) dfs(v, u);
}
int lca(int x, int y)
{
if (dep[x] < dep[y]) swap(x, y);
Rep(k, 17, 0) if (dep[pa[x][k]] >= dep[y]) x = pa[x][k];
if (x == y) return x;
Rep(k, 17, 0) if (pa[x][k] != pa[y][k]) x = pa[x][k], y = pa[y][k];
return pa[x][0];
}
int main()
{
#ifdef HynDuf
freopen(task".in", "r", stdin);
//freopen(task".out", "w", stdout);
#else
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
cin >> n >> m >> q;
rep(i, 2, n)
{
int u, v;
cin >> u >> v;
g[u].eb(v);
g[v].eb(u);
}
dfs(1, 0);
rep(i, 1, m) cin >> a[i];
rep(i, 1, m) pos[a[i]].insert(i);
rep(i, 2, m)
{
int z = lca(a[i], a[i - 1]);
pos1[z].insert(i - 1);
}
while (q--)
{
int t, l, r, v;
cin >> t >> l >> r;
if (t == 1)
{
pos[a[l]].erase(l);
if (l > 1) pos1[lca(a[l], a[l - 1])].erase(l - 1);
if (l < m) pos1[lca(a[l], a[l + 1])].erase(l);
a[l] = r;
pos[r].insert(l);
if (l > 1) pos1[lca(r, a[l - 1])].insert(l - 1);
if (l < m) pos1[lca(r, a[l + 1])].insert(l);
} else
{
cin >> v;
if (!pos[v].empty())
{
auto it = pos[v].lower_bound(l);
if (it != pos[v].end() && *it <= r)
{
cout << (*it) << ' ' << (*it) << '\n';
continue;
}
}
if (!pos1[v].empty())
{
auto it = pos1[v].lower_bound(l);
if (it != pos1[v].end() && *it < r)
{
cout << (*it) << ' ' << (*it + 1) << '\n';
continue;
}
}
cout << "-1 -1\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |