//bit chass 1
#include <bits/stdc++.h>
#define x first
#define y second
#define el "\n"
#define ll long long
#define pb push_back
#define pll pair <ll, ll>
#define pii pair <int, int>
#define all(x) x.begin(), x.end()
#define lcm(x,y) x * y / __gcd(x, y)
#define ibase ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
const int N = 1e3 + 5, inf = 1e9 + 7, M = 2e6, MM = 2e6 + 5, K = 300;
const ll MI = 2e18, mm = 1e15;
const double P = 3.14;
vector <int> g[N];
int tim, tin[N], tout[N], u[N][22], a[N];
set <pii> s[N];
void dfs(int v, int pr) {
tin[v] = ++tim;
u[v][0] = pr;
for (int i = 1; i < 22; i++)
u[v][i] = u[u[v][i - 1]][i - 1];
for (int to : g[v]) {
if (to != pr)
dfs(to, v);
}
tout[v] = ++tim;
}
bool upper(int x, int y) {
return (tin[x] <= tin[y] && tin[y] <= tout[x]);
}
int lca(int x, int y) {
if (upper(x, y))
return x;
if (upper(y, x))
return y;
for (int i = 21; i >= 0; i--)
if (u[x][i] != 0 && !upper(u[x][i], y))
x = u[x][i];
return u[x][0];
}
void solve() {
int n, m, q;
cin >> n >> m >> q;
for (int i = 1, x, y; i < n; i++) {
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
dfs(1, 0);
for (int i = 1; i <= m; i++) {
cin >> a[i];
s[a[i]].insert({i, i});
if (i > 1)
s[lca(a[i], a[i - 1])].insert({i - 1, i});//, cout << lca(a[i], a[i - 1]) << ' ' << i - 1 << ' ' << i << el;
}
// exit(0);
// for (int i = 1; i <= m; i++) {
// cout << i << ':' << el;
// for (auto j : s[i])
// cout << j.x << ' ' << j.y << ' ';
// cout << el;
// }
// exit(0);
for (int i = 1; i <= q; i++) {
int tp;
cin >> tp;
if (tp == 1) {
int pos, v;
cin >> pos >> v;
s[lca(a[pos], a[pos - 1])].erase(s[lca(a[pos], a[pos - 1])].lower_bound({pos - 1, pos}));
s[lca(a[pos], a[pos + 1])].erase(s[lca(a[pos], a[pos + 1])].lower_bound({pos, pos + 1}));
s[a[pos]].erase(s[a[pos]].lower_bound({pos, 0}));
s[lca(a[pos - 1], v)].insert({pos - 1, pos});
s[lca(a[pos + 1], v)].insert({pos, pos + 1});
s[v].insert({pos, pos});
a[pos] = v;
}
else {
int l, r, v;
cin >> l >> r >> v;
auto tl = s[v].lower_bound({l, 0});
if (tl != s[v].end() && (*tl).y <= r)
cout << (*tl).x << ' ' << (*tl).y << el;
else
cout << "-1 -1" << el;
}
}
}
int main() {
// ibase;
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++) {
// cout << "Case " << i << ": ";
solve();
cout << el;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
n=5 |
2 |
Execution timed out |
4024 ms |
360 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
n=5 |
2 |
Execution timed out |
4024 ms |
360 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
n=5 |
2 |
Execution timed out |
4024 ms |
360 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
n=5 |
2 |
Execution timed out |
4024 ms |
360 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |