#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];
}
set<int> s1[N], s2[N];
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) s1[a[i]].insert(i);
for (int i = 1; i < m; ++i) s2[lca(a[i], a[i - 1])].insert(i);
while (q--) {
int e;
cin >> e;
if (e == 1) {
int pos, x;
cin >> pos >> x, --pos, --x;
s1[a[pos]].erase(pos);
if (pos) s2[lca(a[pos], a[pos - 1])].erase(pos);
if (pos + 1 < m) s2[lca(a[pos], a[pos + 1])].erase(pos + 1);
a[pos] = x;
s1[a[pos]].insert(pos);
if (pos) s2[lca(a[pos], a[pos - 1])].insert(pos);
if (pos + 1 < m) s2[lca(a[pos], a[pos + 1])].insert(pos + 1);
}
else {
int l, r, v;
cin >> l >> r >> v, --l, --r, --v;
auto it = s1[v].lower_bound(l);
if (it != s1[v].end() && *it <= r) cout << *it + 1 << " " << *it + 1 << '\n';
else {
it = s2[v].lower_bound(l + 1);
if (it != s2[v].end() && *it <= r) cout << *it << " " << *it + 1 << '\n';
else cout << "-1 -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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
n=5 |
2 |
Correct |
14 ms |
23840 KB |
n=100 |
3 |
Correct |
12 ms |
23824 KB |
n=100 |
4 |
Correct |
12 ms |
23768 KB |
n=100 |
5 |
Correct |
11 ms |
23752 KB |
n=100 |
6 |
Correct |
11 ms |
23764 KB |
n=100 |
7 |
Correct |
11 ms |
23764 KB |
n=100 |
8 |
Correct |
13 ms |
23764 KB |
n=100 |
9 |
Correct |
12 ms |
23764 KB |
n=100 |
10 |
Correct |
13 ms |
23836 KB |
n=100 |
11 |
Correct |
12 ms |
23764 KB |
n=100 |
12 |
Correct |
11 ms |
23844 KB |
n=100 |
13 |
Correct |
12 ms |
23856 KB |
n=100 |
14 |
Correct |
12 ms |
23764 KB |
n=100 |
15 |
Correct |
13 ms |
23764 KB |
n=100 |
16 |
Correct |
12 ms |
23824 KB |
n=100 |
17 |
Correct |
12 ms |
23764 KB |
n=100 |
18 |
Correct |
12 ms |
23764 KB |
n=100 |
19 |
Correct |
13 ms |
23892 KB |
n=100 |
20 |
Correct |
12 ms |
23808 KB |
n=100 |
21 |
Correct |
12 ms |
23764 KB |
n=100 |
22 |
Correct |
12 ms |
23764 KB |
n=100 |
23 |
Correct |
13 ms |
23764 KB |
n=100 |
24 |
Correct |
11 ms |
23764 KB |
n=100 |
25 |
Correct |
12 ms |
23828 KB |
n=100 |
26 |
Correct |
12 ms |
23764 KB |
n=12 |
27 |
Correct |
13 ms |
23784 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
n=5 |
2 |
Correct |
14 ms |
23840 KB |
n=100 |
3 |
Correct |
12 ms |
23824 KB |
n=100 |
4 |
Correct |
12 ms |
23768 KB |
n=100 |
5 |
Correct |
11 ms |
23752 KB |
n=100 |
6 |
Correct |
11 ms |
23764 KB |
n=100 |
7 |
Correct |
11 ms |
23764 KB |
n=100 |
8 |
Correct |
13 ms |
23764 KB |
n=100 |
9 |
Correct |
12 ms |
23764 KB |
n=100 |
10 |
Correct |
13 ms |
23836 KB |
n=100 |
11 |
Correct |
12 ms |
23764 KB |
n=100 |
12 |
Correct |
11 ms |
23844 KB |
n=100 |
13 |
Correct |
12 ms |
23856 KB |
n=100 |
14 |
Correct |
12 ms |
23764 KB |
n=100 |
15 |
Correct |
13 ms |
23764 KB |
n=100 |
16 |
Correct |
12 ms |
23824 KB |
n=100 |
17 |
Correct |
12 ms |
23764 KB |
n=100 |
18 |
Correct |
12 ms |
23764 KB |
n=100 |
19 |
Correct |
13 ms |
23892 KB |
n=100 |
20 |
Correct |
12 ms |
23808 KB |
n=100 |
21 |
Correct |
12 ms |
23764 KB |
n=100 |
22 |
Correct |
12 ms |
23764 KB |
n=100 |
23 |
Correct |
13 ms |
23764 KB |
n=100 |
24 |
Correct |
11 ms |
23764 KB |
n=100 |
25 |
Correct |
12 ms |
23828 KB |
n=100 |
26 |
Correct |
12 ms |
23764 KB |
n=12 |
27 |
Correct |
13 ms |
23784 KB |
n=100 |
28 |
Correct |
14 ms |
24020 KB |
n=500 |
29 |
Correct |
13 ms |
23912 KB |
n=500 |
30 |
Correct |
12 ms |
23892 KB |
n=500 |
31 |
Correct |
12 ms |
23848 KB |
n=500 |
32 |
Correct |
13 ms |
23892 KB |
n=500 |
33 |
Correct |
13 ms |
23892 KB |
n=500 |
34 |
Correct |
13 ms |
23892 KB |
n=500 |
35 |
Correct |
16 ms |
23840 KB |
n=500 |
36 |
Correct |
14 ms |
23832 KB |
n=500 |
37 |
Correct |
13 ms |
23876 KB |
n=500 |
38 |
Correct |
12 ms |
23892 KB |
n=500 |
39 |
Correct |
13 ms |
23892 KB |
n=500 |
40 |
Correct |
12 ms |
23832 KB |
n=500 |
41 |
Correct |
13 ms |
23960 KB |
n=500 |
42 |
Correct |
14 ms |
23892 KB |
n=500 |
43 |
Correct |
14 ms |
23904 KB |
n=500 |
44 |
Correct |
15 ms |
23928 KB |
n=500 |
45 |
Correct |
14 ms |
23944 KB |
n=500 |
46 |
Correct |
14 ms |
23892 KB |
n=500 |
47 |
Correct |
12 ms |
23892 KB |
n=500 |
48 |
Correct |
13 ms |
23892 KB |
n=500 |
49 |
Correct |
12 ms |
23852 KB |
n=500 |
50 |
Correct |
13 ms |
23908 KB |
n=500 |
51 |
Correct |
12 ms |
23892 KB |
n=500 |
52 |
Correct |
12 ms |
23880 KB |
n=500 |
53 |
Correct |
13 ms |
23892 KB |
n=500 |
54 |
Correct |
15 ms |
23836 KB |
n=500 |
55 |
Correct |
12 ms |
23892 KB |
n=278 |
56 |
Correct |
12 ms |
23892 KB |
n=500 |
57 |
Correct |
12 ms |
23892 KB |
n=500 |
58 |
Correct |
12 ms |
23844 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
n=5 |
2 |
Correct |
14 ms |
23840 KB |
n=100 |
3 |
Correct |
12 ms |
23824 KB |
n=100 |
4 |
Correct |
12 ms |
23768 KB |
n=100 |
5 |
Correct |
11 ms |
23752 KB |
n=100 |
6 |
Correct |
11 ms |
23764 KB |
n=100 |
7 |
Correct |
11 ms |
23764 KB |
n=100 |
8 |
Correct |
13 ms |
23764 KB |
n=100 |
9 |
Correct |
12 ms |
23764 KB |
n=100 |
10 |
Correct |
13 ms |
23836 KB |
n=100 |
11 |
Correct |
12 ms |
23764 KB |
n=100 |
12 |
Correct |
11 ms |
23844 KB |
n=100 |
13 |
Correct |
12 ms |
23856 KB |
n=100 |
14 |
Correct |
12 ms |
23764 KB |
n=100 |
15 |
Correct |
13 ms |
23764 KB |
n=100 |
16 |
Correct |
12 ms |
23824 KB |
n=100 |
17 |
Correct |
12 ms |
23764 KB |
n=100 |
18 |
Correct |
12 ms |
23764 KB |
n=100 |
19 |
Correct |
13 ms |
23892 KB |
n=100 |
20 |
Correct |
12 ms |
23808 KB |
n=100 |
21 |
Correct |
12 ms |
23764 KB |
n=100 |
22 |
Correct |
12 ms |
23764 KB |
n=100 |
23 |
Correct |
13 ms |
23764 KB |
n=100 |
24 |
Correct |
11 ms |
23764 KB |
n=100 |
25 |
Correct |
12 ms |
23828 KB |
n=100 |
26 |
Correct |
12 ms |
23764 KB |
n=12 |
27 |
Correct |
13 ms |
23784 KB |
n=100 |
28 |
Correct |
14 ms |
24020 KB |
n=500 |
29 |
Correct |
13 ms |
23912 KB |
n=500 |
30 |
Correct |
12 ms |
23892 KB |
n=500 |
31 |
Correct |
12 ms |
23848 KB |
n=500 |
32 |
Correct |
13 ms |
23892 KB |
n=500 |
33 |
Correct |
13 ms |
23892 KB |
n=500 |
34 |
Correct |
13 ms |
23892 KB |
n=500 |
35 |
Correct |
16 ms |
23840 KB |
n=500 |
36 |
Correct |
14 ms |
23832 KB |
n=500 |
37 |
Correct |
13 ms |
23876 KB |
n=500 |
38 |
Correct |
12 ms |
23892 KB |
n=500 |
39 |
Correct |
13 ms |
23892 KB |
n=500 |
40 |
Correct |
12 ms |
23832 KB |
n=500 |
41 |
Correct |
13 ms |
23960 KB |
n=500 |
42 |
Correct |
14 ms |
23892 KB |
n=500 |
43 |
Correct |
14 ms |
23904 KB |
n=500 |
44 |
Correct |
15 ms |
23928 KB |
n=500 |
45 |
Correct |
14 ms |
23944 KB |
n=500 |
46 |
Correct |
14 ms |
23892 KB |
n=500 |
47 |
Correct |
12 ms |
23892 KB |
n=500 |
48 |
Correct |
13 ms |
23892 KB |
n=500 |
49 |
Correct |
12 ms |
23852 KB |
n=500 |
50 |
Correct |
13 ms |
23908 KB |
n=500 |
51 |
Correct |
12 ms |
23892 KB |
n=500 |
52 |
Correct |
12 ms |
23880 KB |
n=500 |
53 |
Correct |
13 ms |
23892 KB |
n=500 |
54 |
Correct |
15 ms |
23836 KB |
n=500 |
55 |
Correct |
12 ms |
23892 KB |
n=278 |
56 |
Correct |
12 ms |
23892 KB |
n=500 |
57 |
Correct |
12 ms |
23892 KB |
n=500 |
58 |
Correct |
12 ms |
23844 KB |
n=500 |
59 |
Correct |
18 ms |
24404 KB |
n=2000 |
60 |
Correct |
13 ms |
24276 KB |
n=2000 |
61 |
Correct |
17 ms |
24296 KB |
n=2000 |
62 |
Correct |
15 ms |
24256 KB |
n=2000 |
63 |
Correct |
15 ms |
24260 KB |
n=2000 |
64 |
Correct |
14 ms |
24276 KB |
n=2000 |
65 |
Correct |
15 ms |
24236 KB |
n=2000 |
66 |
Correct |
14 ms |
24276 KB |
n=2000 |
67 |
Correct |
15 ms |
24268 KB |
n=2000 |
68 |
Correct |
15 ms |
24204 KB |
n=2000 |
69 |
Correct |
16 ms |
24276 KB |
n=2000 |
70 |
Correct |
16 ms |
24244 KB |
n=2000 |
71 |
Correct |
17 ms |
24276 KB |
n=2000 |
72 |
Correct |
14 ms |
24216 KB |
n=2000 |
73 |
Correct |
13 ms |
24276 KB |
n=2000 |
74 |
Correct |
14 ms |
24164 KB |
n=1844 |
75 |
Correct |
13 ms |
24148 KB |
n=2000 |
76 |
Correct |
14 ms |
24196 KB |
n=2000 |
77 |
Correct |
15 ms |
24156 KB |
n=2000 |
78 |
Correct |
15 ms |
24276 KB |
n=2000 |
79 |
Correct |
15 ms |
24216 KB |
n=2000 |
80 |
Correct |
16 ms |
24276 KB |
n=2000 |
81 |
Correct |
16 ms |
24292 KB |
n=2000 |
82 |
Correct |
16 ms |
24276 KB |
n=2000 |
83 |
Correct |
13 ms |
24268 KB |
n=2000 |
84 |
Correct |
15 ms |
24276 KB |
n=2000 |
85 |
Correct |
15 ms |
24232 KB |
n=2000 |
86 |
Correct |
14 ms |
24276 KB |
n=2000 |
87 |
Correct |
15 ms |
24276 KB |
n=2000 |
88 |
Correct |
14 ms |
24284 KB |
n=2000 |
89 |
Correct |
14 ms |
24276 KB |
n=2000 |
90 |
Correct |
14 ms |
24324 KB |
n=2000 |
91 |
Correct |
14 ms |
24264 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
n=5 |
2 |
Correct |
14 ms |
23840 KB |
n=100 |
3 |
Correct |
12 ms |
23824 KB |
n=100 |
4 |
Correct |
12 ms |
23768 KB |
n=100 |
5 |
Correct |
11 ms |
23752 KB |
n=100 |
6 |
Correct |
11 ms |
23764 KB |
n=100 |
7 |
Correct |
11 ms |
23764 KB |
n=100 |
8 |
Correct |
13 ms |
23764 KB |
n=100 |
9 |
Correct |
12 ms |
23764 KB |
n=100 |
10 |
Correct |
13 ms |
23836 KB |
n=100 |
11 |
Correct |
12 ms |
23764 KB |
n=100 |
12 |
Correct |
11 ms |
23844 KB |
n=100 |
13 |
Correct |
12 ms |
23856 KB |
n=100 |
14 |
Correct |
12 ms |
23764 KB |
n=100 |
15 |
Correct |
13 ms |
23764 KB |
n=100 |
16 |
Correct |
12 ms |
23824 KB |
n=100 |
17 |
Correct |
12 ms |
23764 KB |
n=100 |
18 |
Correct |
12 ms |
23764 KB |
n=100 |
19 |
Correct |
13 ms |
23892 KB |
n=100 |
20 |
Correct |
12 ms |
23808 KB |
n=100 |
21 |
Correct |
12 ms |
23764 KB |
n=100 |
22 |
Correct |
12 ms |
23764 KB |
n=100 |
23 |
Correct |
13 ms |
23764 KB |
n=100 |
24 |
Correct |
11 ms |
23764 KB |
n=100 |
25 |
Correct |
12 ms |
23828 KB |
n=100 |
26 |
Correct |
12 ms |
23764 KB |
n=12 |
27 |
Correct |
13 ms |
23784 KB |
n=100 |
28 |
Correct |
14 ms |
24020 KB |
n=500 |
29 |
Correct |
13 ms |
23912 KB |
n=500 |
30 |
Correct |
12 ms |
23892 KB |
n=500 |
31 |
Correct |
12 ms |
23848 KB |
n=500 |
32 |
Correct |
13 ms |
23892 KB |
n=500 |
33 |
Correct |
13 ms |
23892 KB |
n=500 |
34 |
Correct |
13 ms |
23892 KB |
n=500 |
35 |
Correct |
16 ms |
23840 KB |
n=500 |
36 |
Correct |
14 ms |
23832 KB |
n=500 |
37 |
Correct |
13 ms |
23876 KB |
n=500 |
38 |
Correct |
12 ms |
23892 KB |
n=500 |
39 |
Correct |
13 ms |
23892 KB |
n=500 |
40 |
Correct |
12 ms |
23832 KB |
n=500 |
41 |
Correct |
13 ms |
23960 KB |
n=500 |
42 |
Correct |
14 ms |
23892 KB |
n=500 |
43 |
Correct |
14 ms |
23904 KB |
n=500 |
44 |
Correct |
15 ms |
23928 KB |
n=500 |
45 |
Correct |
14 ms |
23944 KB |
n=500 |
46 |
Correct |
14 ms |
23892 KB |
n=500 |
47 |
Correct |
12 ms |
23892 KB |
n=500 |
48 |
Correct |
13 ms |
23892 KB |
n=500 |
49 |
Correct |
12 ms |
23852 KB |
n=500 |
50 |
Correct |
13 ms |
23908 KB |
n=500 |
51 |
Correct |
12 ms |
23892 KB |
n=500 |
52 |
Correct |
12 ms |
23880 KB |
n=500 |
53 |
Correct |
13 ms |
23892 KB |
n=500 |
54 |
Correct |
15 ms |
23836 KB |
n=500 |
55 |
Correct |
12 ms |
23892 KB |
n=278 |
56 |
Correct |
12 ms |
23892 KB |
n=500 |
57 |
Correct |
12 ms |
23892 KB |
n=500 |
58 |
Correct |
12 ms |
23844 KB |
n=500 |
59 |
Correct |
18 ms |
24404 KB |
n=2000 |
60 |
Correct |
13 ms |
24276 KB |
n=2000 |
61 |
Correct |
17 ms |
24296 KB |
n=2000 |
62 |
Correct |
15 ms |
24256 KB |
n=2000 |
63 |
Correct |
15 ms |
24260 KB |
n=2000 |
64 |
Correct |
14 ms |
24276 KB |
n=2000 |
65 |
Correct |
15 ms |
24236 KB |
n=2000 |
66 |
Correct |
14 ms |
24276 KB |
n=2000 |
67 |
Correct |
15 ms |
24268 KB |
n=2000 |
68 |
Correct |
15 ms |
24204 KB |
n=2000 |
69 |
Correct |
16 ms |
24276 KB |
n=2000 |
70 |
Correct |
16 ms |
24244 KB |
n=2000 |
71 |
Correct |
17 ms |
24276 KB |
n=2000 |
72 |
Correct |
14 ms |
24216 KB |
n=2000 |
73 |
Correct |
13 ms |
24276 KB |
n=2000 |
74 |
Correct |
14 ms |
24164 KB |
n=1844 |
75 |
Correct |
13 ms |
24148 KB |
n=2000 |
76 |
Correct |
14 ms |
24196 KB |
n=2000 |
77 |
Correct |
15 ms |
24156 KB |
n=2000 |
78 |
Correct |
15 ms |
24276 KB |
n=2000 |
79 |
Correct |
15 ms |
24216 KB |
n=2000 |
80 |
Correct |
16 ms |
24276 KB |
n=2000 |
81 |
Correct |
16 ms |
24292 KB |
n=2000 |
82 |
Correct |
16 ms |
24276 KB |
n=2000 |
83 |
Correct |
13 ms |
24268 KB |
n=2000 |
84 |
Correct |
15 ms |
24276 KB |
n=2000 |
85 |
Correct |
15 ms |
24232 KB |
n=2000 |
86 |
Correct |
14 ms |
24276 KB |
n=2000 |
87 |
Correct |
15 ms |
24276 KB |
n=2000 |
88 |
Correct |
14 ms |
24284 KB |
n=2000 |
89 |
Correct |
14 ms |
24276 KB |
n=2000 |
90 |
Correct |
14 ms |
24324 KB |
n=2000 |
91 |
Correct |
14 ms |
24264 KB |
n=2000 |
92 |
Correct |
658 ms |
74632 KB |
n=200000 |
93 |
Correct |
697 ms |
78032 KB |
n=200000 |
94 |
Correct |
548 ms |
80332 KB |
n=200000 |
95 |
Correct |
638 ms |
74232 KB |
n=200000 |
96 |
Correct |
615 ms |
74336 KB |
n=200000 |
97 |
Correct |
778 ms |
77440 KB |
n=200000 |
98 |
Correct |
648 ms |
74400 KB |
n=200000 |
99 |
Correct |
756 ms |
74696 KB |
n=200000 |
100 |
Correct |
647 ms |
74368 KB |
n=200000 |
101 |
Correct |
527 ms |
81488 KB |
n=200000 |
102 |
Correct |
377 ms |
75512 KB |
n=200000 |
103 |
Correct |
389 ms |
75632 KB |
n=200000 |
104 |
Correct |
383 ms |
75504 KB |
n=200000 |
105 |
Correct |
429 ms |
75940 KB |
n=200000 |
106 |
Correct |
382 ms |
76108 KB |
n=200000 |
107 |
Correct |
392 ms |
75912 KB |
n=200000 |
108 |
Correct |
696 ms |
74388 KB |
n=200000 |
109 |
Correct |
688 ms |
74400 KB |
n=200000 |
110 |
Correct |
729 ms |
74540 KB |
n=200000 |
111 |
Correct |
629 ms |
73756 KB |
n=200000 |
112 |
Correct |
573 ms |
80540 KB |
n=200000 |
113 |
Correct |
779 ms |
77368 KB |
n=200000 |
114 |
Correct |
662 ms |
73804 KB |
n=200000 |
115 |
Correct |
952 ms |
75924 KB |
n=200000 |
116 |
Correct |
646 ms |
74680 KB |
n=200000 |
117 |
Correct |
522 ms |
80792 KB |
n=200000 |
118 |
Correct |
831 ms |
76500 KB |
n=200000 |
119 |
Correct |
640 ms |
74476 KB |
n=200000 |
120 |
Correct |
457 ms |
80140 KB |
n=200000 |
121 |
Correct |
455 ms |
80244 KB |
n=200000 |
122 |
Correct |
468 ms |
80672 KB |
n=200000 |
123 |
Correct |
435 ms |
75928 KB |
n=200000 |
124 |
Correct |
181 ms |
38352 KB |
n=25264 |