#pragma GCC optimize("Ofast")
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template<typename T, typename V>
void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template<typename T>
void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i: x) cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template<typename T, typename... V>
void _print(T t, V... v) {
__print(t);
if (sizeof...(v)) cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long
// #define int long long
// #define int unsigned long long
const ll inf = 1e9 + 7;
const ll weirdMod = 998244353;
vector<int> adj[200005];
set<int> pos[200005], lpos[200005];
int x, y, par[200005][18], in[200005], out[200005], tim;
void dfs(int v, int p) {
in[v] = ++tim;
par[v][0] = p;
for (int i = 1; i < 18; i++)
par[v][i] = par[par[v][i - 1]][i - 1];
for (int u : adj[v]) if (u != p) dfs(u, v);
out[v] = ++tim;
}
bool anc(int a, int b) {
return (in[a] <= in[b] && out[a] >= out[b]);
}
int lca(int x, int y) {
if (anc(x, y)) return x;
if (anc(y, x)) return y;
for (int i = 17; i >= 0; i--) {
if (par[x][i] == 0) continue;
if (!anc(par[x][i], y)) x = par[x][i];
}
return par[x][0];
}
void solve() {
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i < n; i++) {
cin >> x >> y;
adj[x].pb(y); adj[y].pb(x);
} int arr[m + 1];
for (int i = 1; i <= m; i++) {
cin >> arr[i]; pos[arr[i]].insert(i);
} dfs(1, 0);
for (int i = 2; i <= m; i++)
lpos[lca(arr[i], arr[i - 1])].insert(i);
int tst, l, r, v;
for (int i = 1; i <= q; i++) {
cin >> tst;
if (tst & 1) {
cin >> l >> v;
pos[arr[l]].erase(l);
if (l > 1) lpos[lca(arr[l], arr[l - 1])].erase(l);
if (l < m) lpos[lca(arr[l], arr[l + 1])].erase(l + 1);
arr[l] = v;
pos[arr[l]].insert(l);
if (l > 1) lpos[lca(arr[l], arr[l - 1])].insert(l);
if (l < m) lpos[lca(arr[l], arr[l + 1])].insert(l + 1);
} else {
cin >> l >> r >> v;
auto it = lower_bound(pos[v].begin(), pos[v].end(), l);
if (it != pos[v].end() && *it <= r) {
cout << *it << ' ' << *it << '\n'; continue;
} it = lower_bound(lpos[v].begin(), lpos[v].end(), l + 1);
if (it != lpos[v].end() && *it <= r) {
cout << *it - 1 << ' ' << *it << '\n'; continue;
} cout << "-1 -1\n";
}
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
26972 KB |
n=5 |
2 |
Correct |
6 ms |
27124 KB |
n=100 |
3 |
Correct |
6 ms |
26972 KB |
n=100 |
4 |
Correct |
6 ms |
26972 KB |
n=100 |
5 |
Correct |
6 ms |
26972 KB |
n=100 |
6 |
Correct |
6 ms |
26972 KB |
n=100 |
7 |
Correct |
6 ms |
26968 KB |
n=100 |
8 |
Correct |
6 ms |
26968 KB |
n=100 |
9 |
Correct |
6 ms |
26972 KB |
n=100 |
10 |
Correct |
6 ms |
26972 KB |
n=100 |
11 |
Correct |
6 ms |
26968 KB |
n=100 |
12 |
Correct |
6 ms |
26968 KB |
n=100 |
13 |
Correct |
6 ms |
26972 KB |
n=100 |
14 |
Correct |
6 ms |
26972 KB |
n=100 |
15 |
Correct |
7 ms |
27120 KB |
n=100 |
16 |
Correct |
6 ms |
26972 KB |
n=100 |
17 |
Correct |
6 ms |
26972 KB |
n=100 |
18 |
Correct |
6 ms |
26972 KB |
n=100 |
19 |
Correct |
6 ms |
26972 KB |
n=100 |
20 |
Correct |
6 ms |
26968 KB |
n=100 |
21 |
Correct |
6 ms |
26972 KB |
n=100 |
22 |
Correct |
6 ms |
26968 KB |
n=100 |
23 |
Correct |
6 ms |
27224 KB |
n=100 |
24 |
Correct |
6 ms |
26972 KB |
n=100 |
25 |
Correct |
6 ms |
26972 KB |
n=100 |
26 |
Correct |
6 ms |
26972 KB |
n=12 |
27 |
Correct |
6 ms |
26972 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
26972 KB |
n=5 |
2 |
Correct |
6 ms |
27124 KB |
n=100 |
3 |
Correct |
6 ms |
26972 KB |
n=100 |
4 |
Correct |
6 ms |
26972 KB |
n=100 |
5 |
Correct |
6 ms |
26972 KB |
n=100 |
6 |
Correct |
6 ms |
26972 KB |
n=100 |
7 |
Correct |
6 ms |
26968 KB |
n=100 |
8 |
Correct |
6 ms |
26968 KB |
n=100 |
9 |
Correct |
6 ms |
26972 KB |
n=100 |
10 |
Correct |
6 ms |
26972 KB |
n=100 |
11 |
Correct |
6 ms |
26968 KB |
n=100 |
12 |
Correct |
6 ms |
26968 KB |
n=100 |
13 |
Correct |
6 ms |
26972 KB |
n=100 |
14 |
Correct |
6 ms |
26972 KB |
n=100 |
15 |
Correct |
7 ms |
27120 KB |
n=100 |
16 |
Correct |
6 ms |
26972 KB |
n=100 |
17 |
Correct |
6 ms |
26972 KB |
n=100 |
18 |
Correct |
6 ms |
26972 KB |
n=100 |
19 |
Correct |
6 ms |
26972 KB |
n=100 |
20 |
Correct |
6 ms |
26968 KB |
n=100 |
21 |
Correct |
6 ms |
26972 KB |
n=100 |
22 |
Correct |
6 ms |
26968 KB |
n=100 |
23 |
Correct |
6 ms |
27224 KB |
n=100 |
24 |
Correct |
6 ms |
26972 KB |
n=100 |
25 |
Correct |
6 ms |
26972 KB |
n=100 |
26 |
Correct |
6 ms |
26972 KB |
n=12 |
27 |
Correct |
6 ms |
26972 KB |
n=100 |
28 |
Correct |
7 ms |
26972 KB |
n=500 |
29 |
Correct |
6 ms |
26972 KB |
n=500 |
30 |
Correct |
6 ms |
26972 KB |
n=500 |
31 |
Correct |
6 ms |
27052 KB |
n=500 |
32 |
Correct |
7 ms |
27060 KB |
n=500 |
33 |
Correct |
6 ms |
26972 KB |
n=500 |
34 |
Correct |
7 ms |
26972 KB |
n=500 |
35 |
Correct |
7 ms |
26972 KB |
n=500 |
36 |
Correct |
6 ms |
27032 KB |
n=500 |
37 |
Correct |
6 ms |
27436 KB |
n=500 |
38 |
Correct |
7 ms |
26972 KB |
n=500 |
39 |
Correct |
6 ms |
26972 KB |
n=500 |
40 |
Correct |
6 ms |
26968 KB |
n=500 |
41 |
Correct |
6 ms |
26972 KB |
n=500 |
42 |
Correct |
6 ms |
27056 KB |
n=500 |
43 |
Correct |
6 ms |
26968 KB |
n=500 |
44 |
Correct |
7 ms |
26972 KB |
n=500 |
45 |
Correct |
7 ms |
26972 KB |
n=500 |
46 |
Correct |
6 ms |
26968 KB |
n=500 |
47 |
Correct |
6 ms |
26972 KB |
n=500 |
48 |
Correct |
7 ms |
27076 KB |
n=500 |
49 |
Correct |
6 ms |
26972 KB |
n=500 |
50 |
Correct |
6 ms |
26972 KB |
n=500 |
51 |
Correct |
6 ms |
26972 KB |
n=500 |
52 |
Correct |
6 ms |
26972 KB |
n=500 |
53 |
Correct |
6 ms |
26968 KB |
n=500 |
54 |
Correct |
6 ms |
26972 KB |
n=500 |
55 |
Correct |
6 ms |
26972 KB |
n=278 |
56 |
Correct |
6 ms |
26972 KB |
n=500 |
57 |
Correct |
6 ms |
26972 KB |
n=500 |
58 |
Correct |
6 ms |
27180 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
26972 KB |
n=5 |
2 |
Correct |
6 ms |
27124 KB |
n=100 |
3 |
Correct |
6 ms |
26972 KB |
n=100 |
4 |
Correct |
6 ms |
26972 KB |
n=100 |
5 |
Correct |
6 ms |
26972 KB |
n=100 |
6 |
Correct |
6 ms |
26972 KB |
n=100 |
7 |
Correct |
6 ms |
26968 KB |
n=100 |
8 |
Correct |
6 ms |
26968 KB |
n=100 |
9 |
Correct |
6 ms |
26972 KB |
n=100 |
10 |
Correct |
6 ms |
26972 KB |
n=100 |
11 |
Correct |
6 ms |
26968 KB |
n=100 |
12 |
Correct |
6 ms |
26968 KB |
n=100 |
13 |
Correct |
6 ms |
26972 KB |
n=100 |
14 |
Correct |
6 ms |
26972 KB |
n=100 |
15 |
Correct |
7 ms |
27120 KB |
n=100 |
16 |
Correct |
6 ms |
26972 KB |
n=100 |
17 |
Correct |
6 ms |
26972 KB |
n=100 |
18 |
Correct |
6 ms |
26972 KB |
n=100 |
19 |
Correct |
6 ms |
26972 KB |
n=100 |
20 |
Correct |
6 ms |
26968 KB |
n=100 |
21 |
Correct |
6 ms |
26972 KB |
n=100 |
22 |
Correct |
6 ms |
26968 KB |
n=100 |
23 |
Correct |
6 ms |
27224 KB |
n=100 |
24 |
Correct |
6 ms |
26972 KB |
n=100 |
25 |
Correct |
6 ms |
26972 KB |
n=100 |
26 |
Correct |
6 ms |
26972 KB |
n=12 |
27 |
Correct |
6 ms |
26972 KB |
n=100 |
28 |
Correct |
7 ms |
26972 KB |
n=500 |
29 |
Correct |
6 ms |
26972 KB |
n=500 |
30 |
Correct |
6 ms |
26972 KB |
n=500 |
31 |
Correct |
6 ms |
27052 KB |
n=500 |
32 |
Correct |
7 ms |
27060 KB |
n=500 |
33 |
Correct |
6 ms |
26972 KB |
n=500 |
34 |
Correct |
7 ms |
26972 KB |
n=500 |
35 |
Correct |
7 ms |
26972 KB |
n=500 |
36 |
Correct |
6 ms |
27032 KB |
n=500 |
37 |
Correct |
6 ms |
27436 KB |
n=500 |
38 |
Correct |
7 ms |
26972 KB |
n=500 |
39 |
Correct |
6 ms |
26972 KB |
n=500 |
40 |
Correct |
6 ms |
26968 KB |
n=500 |
41 |
Correct |
6 ms |
26972 KB |
n=500 |
42 |
Correct |
6 ms |
27056 KB |
n=500 |
43 |
Correct |
6 ms |
26968 KB |
n=500 |
44 |
Correct |
7 ms |
26972 KB |
n=500 |
45 |
Correct |
7 ms |
26972 KB |
n=500 |
46 |
Correct |
6 ms |
26968 KB |
n=500 |
47 |
Correct |
6 ms |
26972 KB |
n=500 |
48 |
Correct |
7 ms |
27076 KB |
n=500 |
49 |
Correct |
6 ms |
26972 KB |
n=500 |
50 |
Correct |
6 ms |
26972 KB |
n=500 |
51 |
Correct |
6 ms |
26972 KB |
n=500 |
52 |
Correct |
6 ms |
26972 KB |
n=500 |
53 |
Correct |
6 ms |
26968 KB |
n=500 |
54 |
Correct |
6 ms |
26972 KB |
n=500 |
55 |
Correct |
6 ms |
26972 KB |
n=278 |
56 |
Correct |
6 ms |
26972 KB |
n=500 |
57 |
Correct |
6 ms |
26972 KB |
n=500 |
58 |
Correct |
6 ms |
27180 KB |
n=500 |
59 |
Correct |
19 ms |
27392 KB |
n=2000 |
60 |
Correct |
7 ms |
27480 KB |
n=2000 |
61 |
Correct |
8 ms |
27224 KB |
n=2000 |
62 |
Correct |
8 ms |
27228 KB |
n=2000 |
63 |
Correct |
22 ms |
27228 KB |
n=2000 |
64 |
Correct |
8 ms |
27224 KB |
n=2000 |
65 |
Correct |
24 ms |
27636 KB |
n=2000 |
66 |
Correct |
8 ms |
27228 KB |
n=2000 |
67 |
Correct |
15 ms |
27228 KB |
n=2000 |
68 |
Correct |
8 ms |
27228 KB |
n=2000 |
69 |
Correct |
7 ms |
27228 KB |
n=2000 |
70 |
Correct |
7 ms |
27228 KB |
n=2000 |
71 |
Correct |
7 ms |
27228 KB |
n=2000 |
72 |
Correct |
7 ms |
27228 KB |
n=2000 |
73 |
Correct |
7 ms |
27228 KB |
n=2000 |
74 |
Correct |
17 ms |
27228 KB |
n=1844 |
75 |
Correct |
7 ms |
27228 KB |
n=2000 |
76 |
Correct |
10 ms |
27224 KB |
n=2000 |
77 |
Correct |
8 ms |
27228 KB |
n=2000 |
78 |
Correct |
8 ms |
27228 KB |
n=2000 |
79 |
Correct |
14 ms |
27228 KB |
n=2000 |
80 |
Correct |
8 ms |
27228 KB |
n=2000 |
81 |
Correct |
8 ms |
27228 KB |
n=2000 |
82 |
Correct |
17 ms |
27300 KB |
n=2000 |
83 |
Correct |
8 ms |
27228 KB |
n=2000 |
84 |
Correct |
8 ms |
27228 KB |
n=2000 |
85 |
Correct |
8 ms |
27308 KB |
n=2000 |
86 |
Correct |
8 ms |
27228 KB |
n=2000 |
87 |
Correct |
8 ms |
27228 KB |
n=2000 |
88 |
Correct |
8 ms |
27480 KB |
n=2000 |
89 |
Correct |
7 ms |
27480 KB |
n=2000 |
90 |
Correct |
7 ms |
27484 KB |
n=2000 |
91 |
Correct |
7 ms |
27316 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
26972 KB |
n=5 |
2 |
Correct |
6 ms |
27124 KB |
n=100 |
3 |
Correct |
6 ms |
26972 KB |
n=100 |
4 |
Correct |
6 ms |
26972 KB |
n=100 |
5 |
Correct |
6 ms |
26972 KB |
n=100 |
6 |
Correct |
6 ms |
26972 KB |
n=100 |
7 |
Correct |
6 ms |
26968 KB |
n=100 |
8 |
Correct |
6 ms |
26968 KB |
n=100 |
9 |
Correct |
6 ms |
26972 KB |
n=100 |
10 |
Correct |
6 ms |
26972 KB |
n=100 |
11 |
Correct |
6 ms |
26968 KB |
n=100 |
12 |
Correct |
6 ms |
26968 KB |
n=100 |
13 |
Correct |
6 ms |
26972 KB |
n=100 |
14 |
Correct |
6 ms |
26972 KB |
n=100 |
15 |
Correct |
7 ms |
27120 KB |
n=100 |
16 |
Correct |
6 ms |
26972 KB |
n=100 |
17 |
Correct |
6 ms |
26972 KB |
n=100 |
18 |
Correct |
6 ms |
26972 KB |
n=100 |
19 |
Correct |
6 ms |
26972 KB |
n=100 |
20 |
Correct |
6 ms |
26968 KB |
n=100 |
21 |
Correct |
6 ms |
26972 KB |
n=100 |
22 |
Correct |
6 ms |
26968 KB |
n=100 |
23 |
Correct |
6 ms |
27224 KB |
n=100 |
24 |
Correct |
6 ms |
26972 KB |
n=100 |
25 |
Correct |
6 ms |
26972 KB |
n=100 |
26 |
Correct |
6 ms |
26972 KB |
n=12 |
27 |
Correct |
6 ms |
26972 KB |
n=100 |
28 |
Correct |
7 ms |
26972 KB |
n=500 |
29 |
Correct |
6 ms |
26972 KB |
n=500 |
30 |
Correct |
6 ms |
26972 KB |
n=500 |
31 |
Correct |
6 ms |
27052 KB |
n=500 |
32 |
Correct |
7 ms |
27060 KB |
n=500 |
33 |
Correct |
6 ms |
26972 KB |
n=500 |
34 |
Correct |
7 ms |
26972 KB |
n=500 |
35 |
Correct |
7 ms |
26972 KB |
n=500 |
36 |
Correct |
6 ms |
27032 KB |
n=500 |
37 |
Correct |
6 ms |
27436 KB |
n=500 |
38 |
Correct |
7 ms |
26972 KB |
n=500 |
39 |
Correct |
6 ms |
26972 KB |
n=500 |
40 |
Correct |
6 ms |
26968 KB |
n=500 |
41 |
Correct |
6 ms |
26972 KB |
n=500 |
42 |
Correct |
6 ms |
27056 KB |
n=500 |
43 |
Correct |
6 ms |
26968 KB |
n=500 |
44 |
Correct |
7 ms |
26972 KB |
n=500 |
45 |
Correct |
7 ms |
26972 KB |
n=500 |
46 |
Correct |
6 ms |
26968 KB |
n=500 |
47 |
Correct |
6 ms |
26972 KB |
n=500 |
48 |
Correct |
7 ms |
27076 KB |
n=500 |
49 |
Correct |
6 ms |
26972 KB |
n=500 |
50 |
Correct |
6 ms |
26972 KB |
n=500 |
51 |
Correct |
6 ms |
26972 KB |
n=500 |
52 |
Correct |
6 ms |
26972 KB |
n=500 |
53 |
Correct |
6 ms |
26968 KB |
n=500 |
54 |
Correct |
6 ms |
26972 KB |
n=500 |
55 |
Correct |
6 ms |
26972 KB |
n=278 |
56 |
Correct |
6 ms |
26972 KB |
n=500 |
57 |
Correct |
6 ms |
26972 KB |
n=500 |
58 |
Correct |
6 ms |
27180 KB |
n=500 |
59 |
Correct |
19 ms |
27392 KB |
n=2000 |
60 |
Correct |
7 ms |
27480 KB |
n=2000 |
61 |
Correct |
8 ms |
27224 KB |
n=2000 |
62 |
Correct |
8 ms |
27228 KB |
n=2000 |
63 |
Correct |
22 ms |
27228 KB |
n=2000 |
64 |
Correct |
8 ms |
27224 KB |
n=2000 |
65 |
Correct |
24 ms |
27636 KB |
n=2000 |
66 |
Correct |
8 ms |
27228 KB |
n=2000 |
67 |
Correct |
15 ms |
27228 KB |
n=2000 |
68 |
Correct |
8 ms |
27228 KB |
n=2000 |
69 |
Correct |
7 ms |
27228 KB |
n=2000 |
70 |
Correct |
7 ms |
27228 KB |
n=2000 |
71 |
Correct |
7 ms |
27228 KB |
n=2000 |
72 |
Correct |
7 ms |
27228 KB |
n=2000 |
73 |
Correct |
7 ms |
27228 KB |
n=2000 |
74 |
Correct |
17 ms |
27228 KB |
n=1844 |
75 |
Correct |
7 ms |
27228 KB |
n=2000 |
76 |
Correct |
10 ms |
27224 KB |
n=2000 |
77 |
Correct |
8 ms |
27228 KB |
n=2000 |
78 |
Correct |
8 ms |
27228 KB |
n=2000 |
79 |
Correct |
14 ms |
27228 KB |
n=2000 |
80 |
Correct |
8 ms |
27228 KB |
n=2000 |
81 |
Correct |
8 ms |
27228 KB |
n=2000 |
82 |
Correct |
17 ms |
27300 KB |
n=2000 |
83 |
Correct |
8 ms |
27228 KB |
n=2000 |
84 |
Correct |
8 ms |
27228 KB |
n=2000 |
85 |
Correct |
8 ms |
27308 KB |
n=2000 |
86 |
Correct |
8 ms |
27228 KB |
n=2000 |
87 |
Correct |
8 ms |
27228 KB |
n=2000 |
88 |
Correct |
8 ms |
27480 KB |
n=2000 |
89 |
Correct |
7 ms |
27480 KB |
n=2000 |
90 |
Correct |
7 ms |
27484 KB |
n=2000 |
91 |
Correct |
7 ms |
27316 KB |
n=2000 |
92 |
Execution timed out |
4078 ms |
66348 KB |
Time limit exceeded |
93 |
Halted |
0 ms |
0 KB |
- |