#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i<= b; ++i)
#define FORD(i, a, b) for (int i = a; i>=b; --i)
#define REP(i, a) for (int i = 0; i<a; ++i)
#define DEBUG(x) { cerr << #x << " = " << x << endl; }
#define Arr(A, l, r) { cerr << #A << " = "; FOR(_, l, r) cerr << A[_] << ' '; cerr << endl; }
#define N 201000
#define pp pair<int, int>
#define next __next
#define prev __prev
#define __builtin_popcount __builtin_popcountll
#define bit(S, i) (((S) >> i) & 1)
#define IO ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
using namespace std;
int n, m, q, a[N], h[N];
int L[N][20];
vector<int> e[N];
set<int> o[N], t[N];
set<int> :: iterator io, it;
void dfs(int u, int p) {
for (int v : e[u]) if (v != p) {
h[v] = h[u] + 1;
L[v][0] = u;
dfs(v, u);
}
}
int lca(int u, int v) {
if (h[u] < h[v]) swap(u, v);
int delta = h[u] - h[v];
FORD(i, 17, 0) if (bit(delta, i)) u = L[u][i];
if (u == v) return u;
FORD(i, 17, 0) if (L[u][i] != L[v][i]) {
u = L[u][i]; v = L[v][i];
}
return L[u][0];
}
int main() {
IO;
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
cin >> n >> m >> q;
FOR(i, 2, n) {
int u, v;
cin >> u >> v;
e[u].push_back(v);
e[v].push_back(u);
}
dfs(1, -1);
FOR(j, 1, 17) FOR(v, 1, n) L[v][j] = L[L[v][j - 1]][j - 1];
FOR(i, 1, m) {
cin >> a[i];
o[a[i]].insert(i);
if (i != 1) {
t[lca(a[i], a[i - 1])].insert(i);
}
}
while (q--) {
int type, v, l, r;
cin >> type;
if (type == 1) {
cin >> l >> v;
o[a[l]].erase(l);
if (l > 1) t[lca(a[l - 1], a[l])].erase(l);
if (l < m) t[lca(a[l], a[l + 1])].erase(l + 1);
a[l] = v;
o[a[l]].insert(l);
if (l > 1) t[lca(a[l], a[l - 1])].insert(l);
if (l < m) t[lca(a[l], a[l + 1])].insert(l + 1);
}
else {
cin >> l >> r >> v;
int x = -1, y = -1;
io = lower_bound(o[v].begin(), o[v].end(), l);
it = lower_bound(t[v].begin(), t[v].end(), l + 1);
if (io != o[v].end() && *io <= r) x = *io, y = *io;
if (it != t[v].end() && *it <= r) x = (*it) - 1, y = *it;
cout << x << ' ' << y << '\n';
}
}
}
Compilation message
treearray.cpp: In function 'int main()':
treearray.cpp:41:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen("test.inp","r",stdin);
^
treearray.cpp:42:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen("test.out","w",stdout);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
42 ms |
47736 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
42 ms |
47736 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
42 ms |
47736 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
42 ms |
47736 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |