#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve vector
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18; const int iinf = 1e9;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); }
template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); }
const int N = 2e5 + 100;
ve<int> gr[N];
const int lg = 19;
int in[N], out[N], up[N][lg];
int tim = 0;
inline void dfs(int v, int p) {
up[v][0] = p;
in[v] = ++tim;
for (auto &to : gr[v]) {
if (to == p) continue;
dfs(to, v);
} out[v] = ++tim;
}
inline bool anc(int a, int b) { return in[a] <= in[b] && out[b] <= out[a]; }
inline int lca(int a, int b) {
if (anc(a, b)) return a;
if (anc(b, a)) return b;
for (int i = lg - 1; ~i; --i) {
if (!anc(up[a][i], b)) {
a = up[a][i];
}
} return up[a][0];
}
multiset<pii> t[4 * N];
inline void ins(int v, int vl, int vr, int pos, pii x) {
t[v].insert(x);
if (vl == vr) return;
int m = vl + vr >> 1;
if (pos <= m) ins(2 * v + 1, vl, m, pos, x);
else ins(2 * v + 2, m + 1, vr, pos, x);
}
inline void del(int v, int vl, int vr, int pos, pii x) {
t[v].erase(t[v].find(x));
if (vl == vr) return;
int m = vl + vr >> 1;
if (pos <= m) del(2 * v + 1, vl, m, pos, x);
else del(2 * v + 2, m + 1, vr, pos, x);
}
inline pii ok(int v, int vl, int vr, int l, int r, int x) {
if (l > r) return {-1, -1};
else if (vl == l && vr == r) {
auto it = t[v].lower_bound(mpp(x, -1));
if (it == t[v].end() || it->fi != x) return mpp(-1, -1);
return *it;
}
int m = vl + vr >> 1;
pii a = ok(2 * v + 1, vl, m, l, min(r, m), x);
pii b = ok(2 * v + 2, m + 1, vr, max(l, m + 1), r, x);
if (b.fi != -1) swap(a, b);
return a;
}
inline void solve() {
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i < n; ++i) {
int v, u;
cin >> v >> u, --v, --u;
gr[v].pb(u), gr[u].pb(v);
} dfs(0, 0);
for (int i = 1; i < lg; ++i) {
for (int v = 0; v < n; ++v) {
up[v][i] = up[up[v][i - 1]][i - 1];
}
}
ve<int> a(m);
for (auto &i : a) cin >> i, --i;
for (int i = 0; i < m; ++i) ins(0, 0, m - 1, i, mpp(a[i], i));
for (int i = 1; i < m; ++i) ins(0, 0, m - 1, i, mpp(lca(a[i], a[i - 1]), i));
while (q--) {
int e;
cin >> e;
if (e == 1) {
int pos, x;
cin >> pos >> x, --pos, --x;
if (pos) del(0, 0, m - 1, pos, mpp(lca(a[pos], a[pos - 1]), pos));
if (pos + 1 < m) del(0, 0, m - 1, pos + 1, mpp(lca(a[pos], a[pos + 1]), pos + 1));
del(0, 0, m - 1, pos, mpp(a[pos], pos));
a[pos] = x;
if (pos) ins(0, 0, m - 1, pos, mpp(lca(a[pos], a[pos - 1]), pos));
if (pos + 1 < m) ins(0, 0, m - 1, pos + 1, mpp(lca(a[pos], a[pos + 1]), pos + 1));
ins(0, 0, m - 1, pos, mpp(a[pos], pos));
}
else {
int l, r, v;
cin >> l >> r >> v, --l, --r, --v;
if (a[l] == v) cout << l + 1 << " " << l + 1 << '\n';
else {
pii ans = ok(0, 0, m - 1, l + 1, r, v);
if (ans.fi == -1) cout << "-1 -1" << '\n';
else {
if (a[ans.se] == v) cout << ans.se + 1 << " " << ans.se + 1 << '\n';
else cout << ans.se << " " << ans.se + 1 << '\n';
}
}
}
}
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int q = 1; // cin >> q;
while (q--) solve();
cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl;
}
Compilation message
treearray.cpp: In function 'void ins(int, int, int, int, pii)':
treearray.cpp:52:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
52 | int m = vl + vr >> 1;
| ~~~^~~~
treearray.cpp: In function 'void del(int, int, int, int, pii)':
treearray.cpp:59:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
59 | int m = vl + vr >> 1;
| ~~~^~~~
treearray.cpp: In function 'pii ok(int, int, int, int, int, int)':
treearray.cpp:70:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
70 | int m = vl + vr >> 1;
| ~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
42608 KB |
n=5 |
2 |
Correct |
20 ms |
42708 KB |
n=100 |
3 |
Correct |
23 ms |
42712 KB |
n=100 |
4 |
Correct |
23 ms |
42836 KB |
n=100 |
5 |
Correct |
21 ms |
42620 KB |
n=100 |
6 |
Correct |
19 ms |
42632 KB |
n=100 |
7 |
Correct |
19 ms |
42652 KB |
n=100 |
8 |
Correct |
20 ms |
42700 KB |
n=100 |
9 |
Correct |
20 ms |
42628 KB |
n=100 |
10 |
Correct |
22 ms |
42664 KB |
n=100 |
11 |
Correct |
21 ms |
42588 KB |
n=100 |
12 |
Correct |
23 ms |
42644 KB |
n=100 |
13 |
Correct |
25 ms |
42600 KB |
n=100 |
14 |
Correct |
21 ms |
42664 KB |
n=100 |
15 |
Correct |
24 ms |
42588 KB |
n=100 |
16 |
Correct |
21 ms |
42708 KB |
n=100 |
17 |
Correct |
20 ms |
42700 KB |
n=100 |
18 |
Correct |
20 ms |
42708 KB |
n=100 |
19 |
Correct |
20 ms |
42708 KB |
n=100 |
20 |
Correct |
21 ms |
42704 KB |
n=100 |
21 |
Correct |
21 ms |
42620 KB |
n=100 |
22 |
Correct |
20 ms |
42708 KB |
n=100 |
23 |
Correct |
27 ms |
42660 KB |
n=100 |
24 |
Correct |
22 ms |
42632 KB |
n=100 |
25 |
Correct |
22 ms |
42708 KB |
n=100 |
26 |
Correct |
25 ms |
42668 KB |
n=12 |
27 |
Correct |
21 ms |
42708 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
42608 KB |
n=5 |
2 |
Correct |
20 ms |
42708 KB |
n=100 |
3 |
Correct |
23 ms |
42712 KB |
n=100 |
4 |
Correct |
23 ms |
42836 KB |
n=100 |
5 |
Correct |
21 ms |
42620 KB |
n=100 |
6 |
Correct |
19 ms |
42632 KB |
n=100 |
7 |
Correct |
19 ms |
42652 KB |
n=100 |
8 |
Correct |
20 ms |
42700 KB |
n=100 |
9 |
Correct |
20 ms |
42628 KB |
n=100 |
10 |
Correct |
22 ms |
42664 KB |
n=100 |
11 |
Correct |
21 ms |
42588 KB |
n=100 |
12 |
Correct |
23 ms |
42644 KB |
n=100 |
13 |
Correct |
25 ms |
42600 KB |
n=100 |
14 |
Correct |
21 ms |
42664 KB |
n=100 |
15 |
Correct |
24 ms |
42588 KB |
n=100 |
16 |
Correct |
21 ms |
42708 KB |
n=100 |
17 |
Correct |
20 ms |
42700 KB |
n=100 |
18 |
Correct |
20 ms |
42708 KB |
n=100 |
19 |
Correct |
20 ms |
42708 KB |
n=100 |
20 |
Correct |
21 ms |
42704 KB |
n=100 |
21 |
Correct |
21 ms |
42620 KB |
n=100 |
22 |
Correct |
20 ms |
42708 KB |
n=100 |
23 |
Correct |
27 ms |
42660 KB |
n=100 |
24 |
Correct |
22 ms |
42632 KB |
n=100 |
25 |
Correct |
22 ms |
42708 KB |
n=100 |
26 |
Correct |
25 ms |
42668 KB |
n=12 |
27 |
Correct |
21 ms |
42708 KB |
n=100 |
28 |
Correct |
23 ms |
43084 KB |
n=500 |
29 |
Correct |
24 ms |
43140 KB |
n=500 |
30 |
Correct |
23 ms |
43148 KB |
n=500 |
31 |
Correct |
23 ms |
43140 KB |
n=500 |
32 |
Correct |
23 ms |
43068 KB |
n=500 |
33 |
Correct |
26 ms |
43092 KB |
n=500 |
34 |
Correct |
25 ms |
43160 KB |
n=500 |
35 |
Correct |
23 ms |
43192 KB |
n=500 |
36 |
Correct |
22 ms |
43092 KB |
n=500 |
37 |
Correct |
22 ms |
43060 KB |
n=500 |
38 |
Correct |
26 ms |
43100 KB |
n=500 |
39 |
Correct |
23 ms |
43084 KB |
n=500 |
40 |
Correct |
25 ms |
43152 KB |
n=500 |
41 |
Correct |
24 ms |
43140 KB |
n=500 |
42 |
Correct |
26 ms |
43080 KB |
n=500 |
43 |
Correct |
25 ms |
43172 KB |
n=500 |
44 |
Correct |
24 ms |
43220 KB |
n=500 |
45 |
Correct |
22 ms |
43128 KB |
n=500 |
46 |
Correct |
27 ms |
43152 KB |
n=500 |
47 |
Correct |
25 ms |
43116 KB |
n=500 |
48 |
Correct |
24 ms |
43096 KB |
n=500 |
49 |
Correct |
22 ms |
43116 KB |
n=500 |
50 |
Correct |
23 ms |
43088 KB |
n=500 |
51 |
Correct |
24 ms |
43152 KB |
n=500 |
52 |
Correct |
25 ms |
43148 KB |
n=500 |
53 |
Correct |
24 ms |
43148 KB |
n=500 |
54 |
Correct |
23 ms |
43136 KB |
n=500 |
55 |
Correct |
22 ms |
43012 KB |
n=278 |
56 |
Correct |
23 ms |
43100 KB |
n=500 |
57 |
Correct |
23 ms |
43104 KB |
n=500 |
58 |
Correct |
22 ms |
43168 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
42608 KB |
n=5 |
2 |
Correct |
20 ms |
42708 KB |
n=100 |
3 |
Correct |
23 ms |
42712 KB |
n=100 |
4 |
Correct |
23 ms |
42836 KB |
n=100 |
5 |
Correct |
21 ms |
42620 KB |
n=100 |
6 |
Correct |
19 ms |
42632 KB |
n=100 |
7 |
Correct |
19 ms |
42652 KB |
n=100 |
8 |
Correct |
20 ms |
42700 KB |
n=100 |
9 |
Correct |
20 ms |
42628 KB |
n=100 |
10 |
Correct |
22 ms |
42664 KB |
n=100 |
11 |
Correct |
21 ms |
42588 KB |
n=100 |
12 |
Correct |
23 ms |
42644 KB |
n=100 |
13 |
Correct |
25 ms |
42600 KB |
n=100 |
14 |
Correct |
21 ms |
42664 KB |
n=100 |
15 |
Correct |
24 ms |
42588 KB |
n=100 |
16 |
Correct |
21 ms |
42708 KB |
n=100 |
17 |
Correct |
20 ms |
42700 KB |
n=100 |
18 |
Correct |
20 ms |
42708 KB |
n=100 |
19 |
Correct |
20 ms |
42708 KB |
n=100 |
20 |
Correct |
21 ms |
42704 KB |
n=100 |
21 |
Correct |
21 ms |
42620 KB |
n=100 |
22 |
Correct |
20 ms |
42708 KB |
n=100 |
23 |
Correct |
27 ms |
42660 KB |
n=100 |
24 |
Correct |
22 ms |
42632 KB |
n=100 |
25 |
Correct |
22 ms |
42708 KB |
n=100 |
26 |
Correct |
25 ms |
42668 KB |
n=12 |
27 |
Correct |
21 ms |
42708 KB |
n=100 |
28 |
Correct |
23 ms |
43084 KB |
n=500 |
29 |
Correct |
24 ms |
43140 KB |
n=500 |
30 |
Correct |
23 ms |
43148 KB |
n=500 |
31 |
Correct |
23 ms |
43140 KB |
n=500 |
32 |
Correct |
23 ms |
43068 KB |
n=500 |
33 |
Correct |
26 ms |
43092 KB |
n=500 |
34 |
Correct |
25 ms |
43160 KB |
n=500 |
35 |
Correct |
23 ms |
43192 KB |
n=500 |
36 |
Correct |
22 ms |
43092 KB |
n=500 |
37 |
Correct |
22 ms |
43060 KB |
n=500 |
38 |
Correct |
26 ms |
43100 KB |
n=500 |
39 |
Correct |
23 ms |
43084 KB |
n=500 |
40 |
Correct |
25 ms |
43152 KB |
n=500 |
41 |
Correct |
24 ms |
43140 KB |
n=500 |
42 |
Correct |
26 ms |
43080 KB |
n=500 |
43 |
Correct |
25 ms |
43172 KB |
n=500 |
44 |
Correct |
24 ms |
43220 KB |
n=500 |
45 |
Correct |
22 ms |
43128 KB |
n=500 |
46 |
Correct |
27 ms |
43152 KB |
n=500 |
47 |
Correct |
25 ms |
43116 KB |
n=500 |
48 |
Correct |
24 ms |
43096 KB |
n=500 |
49 |
Correct |
22 ms |
43116 KB |
n=500 |
50 |
Correct |
23 ms |
43088 KB |
n=500 |
51 |
Correct |
24 ms |
43152 KB |
n=500 |
52 |
Correct |
25 ms |
43148 KB |
n=500 |
53 |
Correct |
24 ms |
43148 KB |
n=500 |
54 |
Correct |
23 ms |
43136 KB |
n=500 |
55 |
Correct |
22 ms |
43012 KB |
n=278 |
56 |
Correct |
23 ms |
43100 KB |
n=500 |
57 |
Correct |
23 ms |
43104 KB |
n=500 |
58 |
Correct |
22 ms |
43168 KB |
n=500 |
59 |
Correct |
43 ms |
45172 KB |
n=2000 |
60 |
Correct |
43 ms |
45224 KB |
n=2000 |
61 |
Correct |
38 ms |
45140 KB |
n=2000 |
62 |
Correct |
41 ms |
45176 KB |
n=2000 |
63 |
Correct |
37 ms |
45140 KB |
n=2000 |
64 |
Correct |
40 ms |
45140 KB |
n=2000 |
65 |
Correct |
37 ms |
45140 KB |
n=2000 |
66 |
Correct |
39 ms |
45260 KB |
n=2000 |
67 |
Correct |
39 ms |
45088 KB |
n=2000 |
68 |
Correct |
39 ms |
45124 KB |
n=2000 |
69 |
Correct |
31 ms |
45140 KB |
n=2000 |
70 |
Correct |
30 ms |
45140 KB |
n=2000 |
71 |
Correct |
29 ms |
45136 KB |
n=2000 |
72 |
Correct |
30 ms |
45060 KB |
n=2000 |
73 |
Correct |
30 ms |
45184 KB |
n=2000 |
74 |
Correct |
39 ms |
45032 KB |
n=1844 |
75 |
Correct |
30 ms |
45132 KB |
n=2000 |
76 |
Correct |
38 ms |
45140 KB |
n=2000 |
77 |
Correct |
39 ms |
45100 KB |
n=2000 |
78 |
Correct |
37 ms |
45092 KB |
n=2000 |
79 |
Correct |
36 ms |
45168 KB |
n=2000 |
80 |
Correct |
38 ms |
45140 KB |
n=2000 |
81 |
Correct |
48 ms |
45108 KB |
n=2000 |
82 |
Correct |
36 ms |
45080 KB |
n=2000 |
83 |
Correct |
38 ms |
45212 KB |
n=2000 |
84 |
Correct |
38 ms |
45112 KB |
n=2000 |
85 |
Correct |
40 ms |
45140 KB |
n=2000 |
86 |
Correct |
41 ms |
45184 KB |
n=2000 |
87 |
Correct |
37 ms |
45196 KB |
n=2000 |
88 |
Correct |
38 ms |
45136 KB |
n=2000 |
89 |
Correct |
39 ms |
45220 KB |
n=2000 |
90 |
Correct |
38 ms |
45140 KB |
n=2000 |
91 |
Correct |
30 ms |
45176 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
42608 KB |
n=5 |
2 |
Correct |
20 ms |
42708 KB |
n=100 |
3 |
Correct |
23 ms |
42712 KB |
n=100 |
4 |
Correct |
23 ms |
42836 KB |
n=100 |
5 |
Correct |
21 ms |
42620 KB |
n=100 |
6 |
Correct |
19 ms |
42632 KB |
n=100 |
7 |
Correct |
19 ms |
42652 KB |
n=100 |
8 |
Correct |
20 ms |
42700 KB |
n=100 |
9 |
Correct |
20 ms |
42628 KB |
n=100 |
10 |
Correct |
22 ms |
42664 KB |
n=100 |
11 |
Correct |
21 ms |
42588 KB |
n=100 |
12 |
Correct |
23 ms |
42644 KB |
n=100 |
13 |
Correct |
25 ms |
42600 KB |
n=100 |
14 |
Correct |
21 ms |
42664 KB |
n=100 |
15 |
Correct |
24 ms |
42588 KB |
n=100 |
16 |
Correct |
21 ms |
42708 KB |
n=100 |
17 |
Correct |
20 ms |
42700 KB |
n=100 |
18 |
Correct |
20 ms |
42708 KB |
n=100 |
19 |
Correct |
20 ms |
42708 KB |
n=100 |
20 |
Correct |
21 ms |
42704 KB |
n=100 |
21 |
Correct |
21 ms |
42620 KB |
n=100 |
22 |
Correct |
20 ms |
42708 KB |
n=100 |
23 |
Correct |
27 ms |
42660 KB |
n=100 |
24 |
Correct |
22 ms |
42632 KB |
n=100 |
25 |
Correct |
22 ms |
42708 KB |
n=100 |
26 |
Correct |
25 ms |
42668 KB |
n=12 |
27 |
Correct |
21 ms |
42708 KB |
n=100 |
28 |
Correct |
23 ms |
43084 KB |
n=500 |
29 |
Correct |
24 ms |
43140 KB |
n=500 |
30 |
Correct |
23 ms |
43148 KB |
n=500 |
31 |
Correct |
23 ms |
43140 KB |
n=500 |
32 |
Correct |
23 ms |
43068 KB |
n=500 |
33 |
Correct |
26 ms |
43092 KB |
n=500 |
34 |
Correct |
25 ms |
43160 KB |
n=500 |
35 |
Correct |
23 ms |
43192 KB |
n=500 |
36 |
Correct |
22 ms |
43092 KB |
n=500 |
37 |
Correct |
22 ms |
43060 KB |
n=500 |
38 |
Correct |
26 ms |
43100 KB |
n=500 |
39 |
Correct |
23 ms |
43084 KB |
n=500 |
40 |
Correct |
25 ms |
43152 KB |
n=500 |
41 |
Correct |
24 ms |
43140 KB |
n=500 |
42 |
Correct |
26 ms |
43080 KB |
n=500 |
43 |
Correct |
25 ms |
43172 KB |
n=500 |
44 |
Correct |
24 ms |
43220 KB |
n=500 |
45 |
Correct |
22 ms |
43128 KB |
n=500 |
46 |
Correct |
27 ms |
43152 KB |
n=500 |
47 |
Correct |
25 ms |
43116 KB |
n=500 |
48 |
Correct |
24 ms |
43096 KB |
n=500 |
49 |
Correct |
22 ms |
43116 KB |
n=500 |
50 |
Correct |
23 ms |
43088 KB |
n=500 |
51 |
Correct |
24 ms |
43152 KB |
n=500 |
52 |
Correct |
25 ms |
43148 KB |
n=500 |
53 |
Correct |
24 ms |
43148 KB |
n=500 |
54 |
Correct |
23 ms |
43136 KB |
n=500 |
55 |
Correct |
22 ms |
43012 KB |
n=278 |
56 |
Correct |
23 ms |
43100 KB |
n=500 |
57 |
Correct |
23 ms |
43104 KB |
n=500 |
58 |
Correct |
22 ms |
43168 KB |
n=500 |
59 |
Correct |
43 ms |
45172 KB |
n=2000 |
60 |
Correct |
43 ms |
45224 KB |
n=2000 |
61 |
Correct |
38 ms |
45140 KB |
n=2000 |
62 |
Correct |
41 ms |
45176 KB |
n=2000 |
63 |
Correct |
37 ms |
45140 KB |
n=2000 |
64 |
Correct |
40 ms |
45140 KB |
n=2000 |
65 |
Correct |
37 ms |
45140 KB |
n=2000 |
66 |
Correct |
39 ms |
45260 KB |
n=2000 |
67 |
Correct |
39 ms |
45088 KB |
n=2000 |
68 |
Correct |
39 ms |
45124 KB |
n=2000 |
69 |
Correct |
31 ms |
45140 KB |
n=2000 |
70 |
Correct |
30 ms |
45140 KB |
n=2000 |
71 |
Correct |
29 ms |
45136 KB |
n=2000 |
72 |
Correct |
30 ms |
45060 KB |
n=2000 |
73 |
Correct |
30 ms |
45184 KB |
n=2000 |
74 |
Correct |
39 ms |
45032 KB |
n=1844 |
75 |
Correct |
30 ms |
45132 KB |
n=2000 |
76 |
Correct |
38 ms |
45140 KB |
n=2000 |
77 |
Correct |
39 ms |
45100 KB |
n=2000 |
78 |
Correct |
37 ms |
45092 KB |
n=2000 |
79 |
Correct |
36 ms |
45168 KB |
n=2000 |
80 |
Correct |
38 ms |
45140 KB |
n=2000 |
81 |
Correct |
48 ms |
45108 KB |
n=2000 |
82 |
Correct |
36 ms |
45080 KB |
n=2000 |
83 |
Correct |
38 ms |
45212 KB |
n=2000 |
84 |
Correct |
38 ms |
45112 KB |
n=2000 |
85 |
Correct |
40 ms |
45140 KB |
n=2000 |
86 |
Correct |
41 ms |
45184 KB |
n=2000 |
87 |
Correct |
37 ms |
45196 KB |
n=2000 |
88 |
Correct |
38 ms |
45136 KB |
n=2000 |
89 |
Correct |
39 ms |
45220 KB |
n=2000 |
90 |
Correct |
38 ms |
45140 KB |
n=2000 |
91 |
Correct |
30 ms |
45176 KB |
n=2000 |
92 |
Runtime error |
1032 ms |
262144 KB |
Execution killed with signal 9 |
93 |
Halted |
0 ms |
0 KB |
- |