#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define ld long double
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define veci vector <int>
#define vecll vector <ll>
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;
const int MAXN = 2e5 + 10;
int n, m, q;
int tin[MAXN], tout[MAXN];
int up[MAXN][19];
vector <int> g[MAXN];
set <int> st[MAXN], poses[MAXN];
int a[MAXN];
int tmr;
void dfs(int v = 1, int p = 0) {
tin[v] = ++tmr;
up[v][0] = p;
for(int i = 1; i < 18; ++i)
if(up[v][i - 1])
up[v][i] = up[up[v][i - 1]][i - 1];
for(auto to : g[v])
if(to != p)
dfs(to, v);
tout[v] = ++tmr;
}
bool upper(int v, int u) {
return (tin[v] <= tin[u] && tout[v] >= tout[u]);
}
int lca(int a, int b) {
if(upper(a, b)) return a;
if(upper(b, a)) return b;
for(int i = 17; i >= 0; --i)
if(up[a][i] && !upper(up[a][i], b))
a = up[a][i];
assert(up[a][0] > 0);
return up[a][0];
}
void solve() {
cin >> n >> m >> q;
for(int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
dfs();
for(int i = 1; i <= m; ++i)
cin >> a[i], poses[a[i]].insert(i);
for(int i = 2; i <= m; ++i)
st[lca(a[i], a[i - 1])].insert(i);
for(int i = 1; i <= q; ++i) {
int type;
cin >> type;
if(type == 1) {
int pos, v;
cin >> pos >> v;
poses[a[pos]].erase(pos);
if(pos > 1) st[lca(a[pos], a[pos - 1])].erase(pos);
if(pos < m) st[lca(a[pos], a[pos + 1])].erase(pos + 1);
a[pos] = v;
poses[v].insert(pos);
if(pos > 1) st[lca(v, a[pos - 1])].insert(pos);
if(pos < m) st[lca(v, a[pos + 1])].insert(pos + 1);
} else {
int l, r, v;
cin >> l >> r >> v;
if(!poses[v].empty()) {
auto it = poses[v].lower_bound(l);
if(it != poses[v].end()) {
int k = *it;
if(k <= r) {
cout << k << ' ' << k << '\n';
continue;
}
}
}
if(st[v].empty()) {
cout << "-1 -1" << '\n';
continue;
}
auto it = st[v].upper_bound(l);
int ans1 = -1, ans2 = -1;
if(it != st[v].end()) {
int cur = *it;
if(cur <= r) {
ans1 = cur - 1;
ans2 = cur;
}
}
cout << ans1 << ' ' << ans2 << '\n';
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
///cin >> T;
while(T--) solve(), cout << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
n=5 |
2 |
Correct |
15 ms |
24044 KB |
n=100 |
3 |
Correct |
18 ms |
23916 KB |
n=100 |
4 |
Correct |
15 ms |
23916 KB |
n=100 |
5 |
Correct |
15 ms |
23916 KB |
n=100 |
6 |
Correct |
15 ms |
23916 KB |
n=100 |
7 |
Correct |
15 ms |
23916 KB |
n=100 |
8 |
Correct |
16 ms |
23916 KB |
n=100 |
9 |
Correct |
16 ms |
23916 KB |
n=100 |
10 |
Correct |
15 ms |
23916 KB |
n=100 |
11 |
Correct |
15 ms |
23916 KB |
n=100 |
12 |
Correct |
15 ms |
23916 KB |
n=100 |
13 |
Correct |
15 ms |
23916 KB |
n=100 |
14 |
Correct |
15 ms |
23916 KB |
n=100 |
15 |
Correct |
15 ms |
23916 KB |
n=100 |
16 |
Correct |
16 ms |
23916 KB |
n=100 |
17 |
Correct |
18 ms |
23916 KB |
n=100 |
18 |
Correct |
15 ms |
23916 KB |
n=100 |
19 |
Correct |
15 ms |
23916 KB |
n=100 |
20 |
Correct |
15 ms |
23916 KB |
n=100 |
21 |
Correct |
15 ms |
23916 KB |
n=100 |
22 |
Correct |
15 ms |
23916 KB |
n=100 |
23 |
Correct |
17 ms |
23916 KB |
n=100 |
24 |
Correct |
15 ms |
23916 KB |
n=100 |
25 |
Correct |
15 ms |
23916 KB |
n=100 |
26 |
Correct |
15 ms |
23916 KB |
n=12 |
27 |
Correct |
15 ms |
23916 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
n=5 |
2 |
Correct |
15 ms |
24044 KB |
n=100 |
3 |
Correct |
18 ms |
23916 KB |
n=100 |
4 |
Correct |
15 ms |
23916 KB |
n=100 |
5 |
Correct |
15 ms |
23916 KB |
n=100 |
6 |
Correct |
15 ms |
23916 KB |
n=100 |
7 |
Correct |
15 ms |
23916 KB |
n=100 |
8 |
Correct |
16 ms |
23916 KB |
n=100 |
9 |
Correct |
16 ms |
23916 KB |
n=100 |
10 |
Correct |
15 ms |
23916 KB |
n=100 |
11 |
Correct |
15 ms |
23916 KB |
n=100 |
12 |
Correct |
15 ms |
23916 KB |
n=100 |
13 |
Correct |
15 ms |
23916 KB |
n=100 |
14 |
Correct |
15 ms |
23916 KB |
n=100 |
15 |
Correct |
15 ms |
23916 KB |
n=100 |
16 |
Correct |
16 ms |
23916 KB |
n=100 |
17 |
Correct |
18 ms |
23916 KB |
n=100 |
18 |
Correct |
15 ms |
23916 KB |
n=100 |
19 |
Correct |
15 ms |
23916 KB |
n=100 |
20 |
Correct |
15 ms |
23916 KB |
n=100 |
21 |
Correct |
15 ms |
23916 KB |
n=100 |
22 |
Correct |
15 ms |
23916 KB |
n=100 |
23 |
Correct |
17 ms |
23916 KB |
n=100 |
24 |
Correct |
15 ms |
23916 KB |
n=100 |
25 |
Correct |
15 ms |
23916 KB |
n=100 |
26 |
Correct |
15 ms |
23916 KB |
n=12 |
27 |
Correct |
15 ms |
23916 KB |
n=100 |
28 |
Correct |
17 ms |
23916 KB |
n=500 |
29 |
Correct |
15 ms |
23916 KB |
n=500 |
30 |
Correct |
16 ms |
24044 KB |
n=500 |
31 |
Correct |
18 ms |
24064 KB |
n=500 |
32 |
Correct |
16 ms |
23916 KB |
n=500 |
33 |
Correct |
18 ms |
23916 KB |
n=500 |
34 |
Correct |
15 ms |
23916 KB |
n=500 |
35 |
Correct |
16 ms |
23916 KB |
n=500 |
36 |
Correct |
15 ms |
23916 KB |
n=500 |
37 |
Correct |
16 ms |
23908 KB |
n=500 |
38 |
Correct |
16 ms |
23916 KB |
n=500 |
39 |
Correct |
18 ms |
23916 KB |
n=500 |
40 |
Correct |
15 ms |
23916 KB |
n=500 |
41 |
Correct |
15 ms |
23916 KB |
n=500 |
42 |
Correct |
18 ms |
23916 KB |
n=500 |
43 |
Correct |
16 ms |
24044 KB |
n=500 |
44 |
Correct |
19 ms |
23916 KB |
n=500 |
45 |
Correct |
15 ms |
23916 KB |
n=500 |
46 |
Correct |
15 ms |
23916 KB |
n=500 |
47 |
Correct |
16 ms |
23916 KB |
n=500 |
48 |
Correct |
17 ms |
23916 KB |
n=500 |
49 |
Correct |
15 ms |
23916 KB |
n=500 |
50 |
Correct |
15 ms |
23916 KB |
n=500 |
51 |
Correct |
16 ms |
23916 KB |
n=500 |
52 |
Correct |
15 ms |
23916 KB |
n=500 |
53 |
Correct |
15 ms |
23916 KB |
n=500 |
54 |
Correct |
16 ms |
23916 KB |
n=500 |
55 |
Correct |
15 ms |
23916 KB |
n=278 |
56 |
Correct |
16 ms |
23916 KB |
n=500 |
57 |
Correct |
16 ms |
23916 KB |
n=500 |
58 |
Correct |
18 ms |
23916 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
n=5 |
2 |
Correct |
15 ms |
24044 KB |
n=100 |
3 |
Correct |
18 ms |
23916 KB |
n=100 |
4 |
Correct |
15 ms |
23916 KB |
n=100 |
5 |
Correct |
15 ms |
23916 KB |
n=100 |
6 |
Correct |
15 ms |
23916 KB |
n=100 |
7 |
Correct |
15 ms |
23916 KB |
n=100 |
8 |
Correct |
16 ms |
23916 KB |
n=100 |
9 |
Correct |
16 ms |
23916 KB |
n=100 |
10 |
Correct |
15 ms |
23916 KB |
n=100 |
11 |
Correct |
15 ms |
23916 KB |
n=100 |
12 |
Correct |
15 ms |
23916 KB |
n=100 |
13 |
Correct |
15 ms |
23916 KB |
n=100 |
14 |
Correct |
15 ms |
23916 KB |
n=100 |
15 |
Correct |
15 ms |
23916 KB |
n=100 |
16 |
Correct |
16 ms |
23916 KB |
n=100 |
17 |
Correct |
18 ms |
23916 KB |
n=100 |
18 |
Correct |
15 ms |
23916 KB |
n=100 |
19 |
Correct |
15 ms |
23916 KB |
n=100 |
20 |
Correct |
15 ms |
23916 KB |
n=100 |
21 |
Correct |
15 ms |
23916 KB |
n=100 |
22 |
Correct |
15 ms |
23916 KB |
n=100 |
23 |
Correct |
17 ms |
23916 KB |
n=100 |
24 |
Correct |
15 ms |
23916 KB |
n=100 |
25 |
Correct |
15 ms |
23916 KB |
n=100 |
26 |
Correct |
15 ms |
23916 KB |
n=12 |
27 |
Correct |
15 ms |
23916 KB |
n=100 |
28 |
Correct |
17 ms |
23916 KB |
n=500 |
29 |
Correct |
15 ms |
23916 KB |
n=500 |
30 |
Correct |
16 ms |
24044 KB |
n=500 |
31 |
Correct |
18 ms |
24064 KB |
n=500 |
32 |
Correct |
16 ms |
23916 KB |
n=500 |
33 |
Correct |
18 ms |
23916 KB |
n=500 |
34 |
Correct |
15 ms |
23916 KB |
n=500 |
35 |
Correct |
16 ms |
23916 KB |
n=500 |
36 |
Correct |
15 ms |
23916 KB |
n=500 |
37 |
Correct |
16 ms |
23908 KB |
n=500 |
38 |
Correct |
16 ms |
23916 KB |
n=500 |
39 |
Correct |
18 ms |
23916 KB |
n=500 |
40 |
Correct |
15 ms |
23916 KB |
n=500 |
41 |
Correct |
15 ms |
23916 KB |
n=500 |
42 |
Correct |
18 ms |
23916 KB |
n=500 |
43 |
Correct |
16 ms |
24044 KB |
n=500 |
44 |
Correct |
19 ms |
23916 KB |
n=500 |
45 |
Correct |
15 ms |
23916 KB |
n=500 |
46 |
Correct |
15 ms |
23916 KB |
n=500 |
47 |
Correct |
16 ms |
23916 KB |
n=500 |
48 |
Correct |
17 ms |
23916 KB |
n=500 |
49 |
Correct |
15 ms |
23916 KB |
n=500 |
50 |
Correct |
15 ms |
23916 KB |
n=500 |
51 |
Correct |
16 ms |
23916 KB |
n=500 |
52 |
Correct |
15 ms |
23916 KB |
n=500 |
53 |
Correct |
15 ms |
23916 KB |
n=500 |
54 |
Correct |
16 ms |
23916 KB |
n=500 |
55 |
Correct |
15 ms |
23916 KB |
n=278 |
56 |
Correct |
16 ms |
23916 KB |
n=500 |
57 |
Correct |
16 ms |
23916 KB |
n=500 |
58 |
Correct |
18 ms |
23916 KB |
n=500 |
59 |
Correct |
18 ms |
24300 KB |
n=2000 |
60 |
Correct |
18 ms |
24428 KB |
n=2000 |
61 |
Correct |
18 ms |
24300 KB |
n=2000 |
62 |
Correct |
19 ms |
24300 KB |
n=2000 |
63 |
Correct |
18 ms |
24300 KB |
n=2000 |
64 |
Correct |
18 ms |
24300 KB |
n=2000 |
65 |
Correct |
18 ms |
24300 KB |
n=2000 |
66 |
Correct |
18 ms |
24300 KB |
n=2000 |
67 |
Correct |
19 ms |
24300 KB |
n=2000 |
68 |
Correct |
19 ms |
24300 KB |
n=2000 |
69 |
Correct |
18 ms |
24300 KB |
n=2000 |
70 |
Correct |
17 ms |
24300 KB |
n=2000 |
71 |
Correct |
21 ms |
24292 KB |
n=2000 |
72 |
Correct |
17 ms |
24300 KB |
n=2000 |
73 |
Correct |
18 ms |
24300 KB |
n=2000 |
74 |
Correct |
18 ms |
24300 KB |
n=1844 |
75 |
Correct |
17 ms |
24300 KB |
n=2000 |
76 |
Correct |
19 ms |
24300 KB |
n=2000 |
77 |
Correct |
19 ms |
24300 KB |
n=2000 |
78 |
Correct |
18 ms |
24300 KB |
n=2000 |
79 |
Correct |
18 ms |
24300 KB |
n=2000 |
80 |
Correct |
19 ms |
24300 KB |
n=2000 |
81 |
Correct |
19 ms |
24556 KB |
n=2000 |
82 |
Correct |
18 ms |
24300 KB |
n=2000 |
83 |
Correct |
22 ms |
24292 KB |
n=2000 |
84 |
Correct |
18 ms |
24300 KB |
n=2000 |
85 |
Correct |
19 ms |
24428 KB |
n=2000 |
86 |
Correct |
23 ms |
24292 KB |
n=2000 |
87 |
Correct |
19 ms |
24300 KB |
n=2000 |
88 |
Correct |
18 ms |
24428 KB |
n=2000 |
89 |
Correct |
19 ms |
24428 KB |
n=2000 |
90 |
Correct |
18 ms |
24428 KB |
n=2000 |
91 |
Correct |
18 ms |
24300 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
n=5 |
2 |
Correct |
15 ms |
24044 KB |
n=100 |
3 |
Correct |
18 ms |
23916 KB |
n=100 |
4 |
Correct |
15 ms |
23916 KB |
n=100 |
5 |
Correct |
15 ms |
23916 KB |
n=100 |
6 |
Correct |
15 ms |
23916 KB |
n=100 |
7 |
Correct |
15 ms |
23916 KB |
n=100 |
8 |
Correct |
16 ms |
23916 KB |
n=100 |
9 |
Correct |
16 ms |
23916 KB |
n=100 |
10 |
Correct |
15 ms |
23916 KB |
n=100 |
11 |
Correct |
15 ms |
23916 KB |
n=100 |
12 |
Correct |
15 ms |
23916 KB |
n=100 |
13 |
Correct |
15 ms |
23916 KB |
n=100 |
14 |
Correct |
15 ms |
23916 KB |
n=100 |
15 |
Correct |
15 ms |
23916 KB |
n=100 |
16 |
Correct |
16 ms |
23916 KB |
n=100 |
17 |
Correct |
18 ms |
23916 KB |
n=100 |
18 |
Correct |
15 ms |
23916 KB |
n=100 |
19 |
Correct |
15 ms |
23916 KB |
n=100 |
20 |
Correct |
15 ms |
23916 KB |
n=100 |
21 |
Correct |
15 ms |
23916 KB |
n=100 |
22 |
Correct |
15 ms |
23916 KB |
n=100 |
23 |
Correct |
17 ms |
23916 KB |
n=100 |
24 |
Correct |
15 ms |
23916 KB |
n=100 |
25 |
Correct |
15 ms |
23916 KB |
n=100 |
26 |
Correct |
15 ms |
23916 KB |
n=12 |
27 |
Correct |
15 ms |
23916 KB |
n=100 |
28 |
Correct |
17 ms |
23916 KB |
n=500 |
29 |
Correct |
15 ms |
23916 KB |
n=500 |
30 |
Correct |
16 ms |
24044 KB |
n=500 |
31 |
Correct |
18 ms |
24064 KB |
n=500 |
32 |
Correct |
16 ms |
23916 KB |
n=500 |
33 |
Correct |
18 ms |
23916 KB |
n=500 |
34 |
Correct |
15 ms |
23916 KB |
n=500 |
35 |
Correct |
16 ms |
23916 KB |
n=500 |
36 |
Correct |
15 ms |
23916 KB |
n=500 |
37 |
Correct |
16 ms |
23908 KB |
n=500 |
38 |
Correct |
16 ms |
23916 KB |
n=500 |
39 |
Correct |
18 ms |
23916 KB |
n=500 |
40 |
Correct |
15 ms |
23916 KB |
n=500 |
41 |
Correct |
15 ms |
23916 KB |
n=500 |
42 |
Correct |
18 ms |
23916 KB |
n=500 |
43 |
Correct |
16 ms |
24044 KB |
n=500 |
44 |
Correct |
19 ms |
23916 KB |
n=500 |
45 |
Correct |
15 ms |
23916 KB |
n=500 |
46 |
Correct |
15 ms |
23916 KB |
n=500 |
47 |
Correct |
16 ms |
23916 KB |
n=500 |
48 |
Correct |
17 ms |
23916 KB |
n=500 |
49 |
Correct |
15 ms |
23916 KB |
n=500 |
50 |
Correct |
15 ms |
23916 KB |
n=500 |
51 |
Correct |
16 ms |
23916 KB |
n=500 |
52 |
Correct |
15 ms |
23916 KB |
n=500 |
53 |
Correct |
15 ms |
23916 KB |
n=500 |
54 |
Correct |
16 ms |
23916 KB |
n=500 |
55 |
Correct |
15 ms |
23916 KB |
n=278 |
56 |
Correct |
16 ms |
23916 KB |
n=500 |
57 |
Correct |
16 ms |
23916 KB |
n=500 |
58 |
Correct |
18 ms |
23916 KB |
n=500 |
59 |
Correct |
18 ms |
24300 KB |
n=2000 |
60 |
Correct |
18 ms |
24428 KB |
n=2000 |
61 |
Correct |
18 ms |
24300 KB |
n=2000 |
62 |
Correct |
19 ms |
24300 KB |
n=2000 |
63 |
Correct |
18 ms |
24300 KB |
n=2000 |
64 |
Correct |
18 ms |
24300 KB |
n=2000 |
65 |
Correct |
18 ms |
24300 KB |
n=2000 |
66 |
Correct |
18 ms |
24300 KB |
n=2000 |
67 |
Correct |
19 ms |
24300 KB |
n=2000 |
68 |
Correct |
19 ms |
24300 KB |
n=2000 |
69 |
Correct |
18 ms |
24300 KB |
n=2000 |
70 |
Correct |
17 ms |
24300 KB |
n=2000 |
71 |
Correct |
21 ms |
24292 KB |
n=2000 |
72 |
Correct |
17 ms |
24300 KB |
n=2000 |
73 |
Correct |
18 ms |
24300 KB |
n=2000 |
74 |
Correct |
18 ms |
24300 KB |
n=1844 |
75 |
Correct |
17 ms |
24300 KB |
n=2000 |
76 |
Correct |
19 ms |
24300 KB |
n=2000 |
77 |
Correct |
19 ms |
24300 KB |
n=2000 |
78 |
Correct |
18 ms |
24300 KB |
n=2000 |
79 |
Correct |
18 ms |
24300 KB |
n=2000 |
80 |
Correct |
19 ms |
24300 KB |
n=2000 |
81 |
Correct |
19 ms |
24556 KB |
n=2000 |
82 |
Correct |
18 ms |
24300 KB |
n=2000 |
83 |
Correct |
22 ms |
24292 KB |
n=2000 |
84 |
Correct |
18 ms |
24300 KB |
n=2000 |
85 |
Correct |
19 ms |
24428 KB |
n=2000 |
86 |
Correct |
23 ms |
24292 KB |
n=2000 |
87 |
Correct |
19 ms |
24300 KB |
n=2000 |
88 |
Correct |
18 ms |
24428 KB |
n=2000 |
89 |
Correct |
19 ms |
24428 KB |
n=2000 |
90 |
Correct |
18 ms |
24428 KB |
n=2000 |
91 |
Correct |
18 ms |
24300 KB |
n=2000 |
92 |
Correct |
793 ms |
68224 KB |
n=200000 |
93 |
Correct |
968 ms |
71912 KB |
n=200000 |
94 |
Correct |
755 ms |
75364 KB |
n=200000 |
95 |
Correct |
785 ms |
68056 KB |
n=200000 |
96 |
Correct |
772 ms |
68048 KB |
n=200000 |
97 |
Correct |
1036 ms |
71012 KB |
n=200000 |
98 |
Correct |
763 ms |
68180 KB |
n=200000 |
99 |
Correct |
918 ms |
67672 KB |
n=200000 |
100 |
Correct |
789 ms |
68232 KB |
n=200000 |
101 |
Correct |
664 ms |
76644 KB |
n=200000 |
102 |
Correct |
469 ms |
69092 KB |
n=200000 |
103 |
Correct |
472 ms |
69092 KB |
n=200000 |
104 |
Correct |
465 ms |
68964 KB |
n=200000 |
105 |
Correct |
463 ms |
68964 KB |
n=200000 |
106 |
Correct |
476 ms |
68708 KB |
n=200000 |
107 |
Correct |
472 ms |
68668 KB |
n=200000 |
108 |
Correct |
813 ms |
67600 KB |
n=200000 |
109 |
Correct |
811 ms |
67696 KB |
n=200000 |
110 |
Correct |
811 ms |
67684 KB |
n=200000 |
111 |
Correct |
733 ms |
68080 KB |
n=200000 |
112 |
Correct |
670 ms |
75620 KB |
n=200000 |
113 |
Correct |
965 ms |
70884 KB |
n=200000 |
114 |
Correct |
744 ms |
68052 KB |
n=200000 |
115 |
Correct |
1182 ms |
68816 KB |
n=200000 |
116 |
Correct |
705 ms |
67800 KB |
n=200000 |
117 |
Correct |
648 ms |
75868 KB |
n=200000 |
118 |
Correct |
1048 ms |
69752 KB |
n=200000 |
119 |
Correct |
702 ms |
67692 KB |
n=200000 |
120 |
Correct |
570 ms |
76320 KB |
n=200000 |
121 |
Correct |
579 ms |
76260 KB |
n=200000 |
122 |
Correct |
572 ms |
76516 KB |
n=200000 |
123 |
Correct |
480 ms |
68324 KB |
n=200000 |
124 |
Correct |
200 ms |
36836 KB |
n=25264 |