/// adil sultanov | vonat1us
#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:36777216")
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
#define all(z) (z).begin(), (z).end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;
void fin() {
#ifdef AM
freopen(".in", "r", stdin);
#endif
}
const bool flag = 0;
const int N = 2e5+10;
const int K = 18;
set<int> s[N], one[N];
vector<int> adj[N];
int up[K][N], tin[N], tout[N], tmr;
void dfs(int x = 0, int p = 0) {
up[0][x] = p;
for (int i = 1; i < K; ++i) {
up[i][x] = up[i-1][up[i-1][x]];
}
tin[x] = ++tmr;
for (int to : adj[x]) {
if (to != p) {
dfs(to, x);
}
}
tout[x] = tmr;
}
bool upper(int a, int b) {
return tin[a] <= tin[b] && tout[a] >= tout[b];
}
int lca(int a, int b) {
if (upper(a, b)) return a;
if (upper(b, a)) return b;
for (int i = K-1; ~i; --i) {
if (!upper(up[i][a], b)) {
a = up[i][a];
}
}
return up[0][a];
}
void ma1n() {
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
u--, v--;
adj[u].pb(v);
adj[v].pb(u);
}
vector<int> a(m);
for (int& x : a) cin >> x, x--;
dfs();
for (int i = 0; i < m; ++i) {
one[a[i]].insert(i);
if (i+1 < m) s[lca(a[i+1], a[i])].insert(i);
}
for (int i = 0; i < q; ++i) {
int t;
cin >> t;
if (t == 1) {
int pos, v;
cin >> pos >> v;
pos--, v--;
one[a[pos]].erase(pos);
if (pos+1 < m) s[lca(a[pos], a[pos+1])].erase(pos);
if (pos > 0) s[lca(a[pos], a[pos-1])].erase(pos-1);
a[pos] = v;
one[v].insert(pos);
if (pos+1 < m) s[lca(v, a[pos+1])].insert(pos);
if (pos > 0) s[lca(v, a[pos-1])].insert(pos-1);
} else {
int l, r, v;
cin >> l >> r >> v;
l--, r--, v--;
auto it = one[v].lower_bound(l);
if (it != one[v].end() && *it <= r) {
cout << *it+1 << " " << *it+1 << "\n";
continue;
}
it = s[v].lower_bound(l);
if (it != s[v].end() && *it < r) {
cout << *it+1 << " " << *it+2 << "\n";
} else {
cout << "-1 -1\n";
}
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr), fin();
int ts = 1;
if (flag) {
cin >> ts;
}
while (ts--) {
ma1n();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23884 KB |
n=5 |
2 |
Correct |
14 ms |
23988 KB |
n=100 |
3 |
Correct |
14 ms |
23928 KB |
n=100 |
4 |
Correct |
14 ms |
23804 KB |
n=100 |
5 |
Correct |
14 ms |
23884 KB |
n=100 |
6 |
Correct |
14 ms |
23884 KB |
n=100 |
7 |
Correct |
13 ms |
23844 KB |
n=100 |
8 |
Correct |
13 ms |
23884 KB |
n=100 |
9 |
Correct |
13 ms |
23932 KB |
n=100 |
10 |
Correct |
13 ms |
23884 KB |
n=100 |
11 |
Correct |
12 ms |
23884 KB |
n=100 |
12 |
Correct |
14 ms |
23884 KB |
n=100 |
13 |
Correct |
14 ms |
23840 KB |
n=100 |
14 |
Correct |
13 ms |
23908 KB |
n=100 |
15 |
Correct |
13 ms |
23924 KB |
n=100 |
16 |
Correct |
13 ms |
23860 KB |
n=100 |
17 |
Correct |
12 ms |
23928 KB |
n=100 |
18 |
Correct |
12 ms |
23884 KB |
n=100 |
19 |
Correct |
14 ms |
23820 KB |
n=100 |
20 |
Correct |
13 ms |
23884 KB |
n=100 |
21 |
Correct |
13 ms |
23908 KB |
n=100 |
22 |
Correct |
13 ms |
23928 KB |
n=100 |
23 |
Correct |
13 ms |
23884 KB |
n=100 |
24 |
Correct |
13 ms |
23884 KB |
n=100 |
25 |
Correct |
13 ms |
23884 KB |
n=100 |
26 |
Correct |
13 ms |
23832 KB |
n=12 |
27 |
Correct |
13 ms |
23884 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23884 KB |
n=5 |
2 |
Correct |
14 ms |
23988 KB |
n=100 |
3 |
Correct |
14 ms |
23928 KB |
n=100 |
4 |
Correct |
14 ms |
23804 KB |
n=100 |
5 |
Correct |
14 ms |
23884 KB |
n=100 |
6 |
Correct |
14 ms |
23884 KB |
n=100 |
7 |
Correct |
13 ms |
23844 KB |
n=100 |
8 |
Correct |
13 ms |
23884 KB |
n=100 |
9 |
Correct |
13 ms |
23932 KB |
n=100 |
10 |
Correct |
13 ms |
23884 KB |
n=100 |
11 |
Correct |
12 ms |
23884 KB |
n=100 |
12 |
Correct |
14 ms |
23884 KB |
n=100 |
13 |
Correct |
14 ms |
23840 KB |
n=100 |
14 |
Correct |
13 ms |
23908 KB |
n=100 |
15 |
Correct |
13 ms |
23924 KB |
n=100 |
16 |
Correct |
13 ms |
23860 KB |
n=100 |
17 |
Correct |
12 ms |
23928 KB |
n=100 |
18 |
Correct |
12 ms |
23884 KB |
n=100 |
19 |
Correct |
14 ms |
23820 KB |
n=100 |
20 |
Correct |
13 ms |
23884 KB |
n=100 |
21 |
Correct |
13 ms |
23908 KB |
n=100 |
22 |
Correct |
13 ms |
23928 KB |
n=100 |
23 |
Correct |
13 ms |
23884 KB |
n=100 |
24 |
Correct |
13 ms |
23884 KB |
n=100 |
25 |
Correct |
13 ms |
23884 KB |
n=100 |
26 |
Correct |
13 ms |
23832 KB |
n=12 |
27 |
Correct |
13 ms |
23884 KB |
n=100 |
28 |
Correct |
14 ms |
24012 KB |
n=500 |
29 |
Correct |
14 ms |
24012 KB |
n=500 |
30 |
Correct |
13 ms |
23944 KB |
n=500 |
31 |
Correct |
16 ms |
23940 KB |
n=500 |
32 |
Correct |
14 ms |
24024 KB |
n=500 |
33 |
Correct |
14 ms |
23952 KB |
n=500 |
34 |
Correct |
15 ms |
24012 KB |
n=500 |
35 |
Correct |
14 ms |
23964 KB |
n=500 |
36 |
Correct |
16 ms |
23944 KB |
n=500 |
37 |
Correct |
13 ms |
23940 KB |
n=500 |
38 |
Correct |
14 ms |
23940 KB |
n=500 |
39 |
Correct |
14 ms |
24012 KB |
n=500 |
40 |
Correct |
13 ms |
24012 KB |
n=500 |
41 |
Correct |
13 ms |
23936 KB |
n=500 |
42 |
Correct |
15 ms |
23960 KB |
n=500 |
43 |
Correct |
14 ms |
23940 KB |
n=500 |
44 |
Correct |
14 ms |
23940 KB |
n=500 |
45 |
Correct |
14 ms |
23952 KB |
n=500 |
46 |
Correct |
13 ms |
23940 KB |
n=500 |
47 |
Correct |
13 ms |
24012 KB |
n=500 |
48 |
Correct |
14 ms |
24012 KB |
n=500 |
49 |
Correct |
14 ms |
23944 KB |
n=500 |
50 |
Correct |
14 ms |
24012 KB |
n=500 |
51 |
Correct |
14 ms |
23952 KB |
n=500 |
52 |
Correct |
17 ms |
23980 KB |
n=500 |
53 |
Correct |
15 ms |
24032 KB |
n=500 |
54 |
Correct |
17 ms |
24064 KB |
n=500 |
55 |
Correct |
14 ms |
23884 KB |
n=278 |
56 |
Correct |
14 ms |
24012 KB |
n=500 |
57 |
Correct |
14 ms |
24024 KB |
n=500 |
58 |
Correct |
14 ms |
23996 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23884 KB |
n=5 |
2 |
Correct |
14 ms |
23988 KB |
n=100 |
3 |
Correct |
14 ms |
23928 KB |
n=100 |
4 |
Correct |
14 ms |
23804 KB |
n=100 |
5 |
Correct |
14 ms |
23884 KB |
n=100 |
6 |
Correct |
14 ms |
23884 KB |
n=100 |
7 |
Correct |
13 ms |
23844 KB |
n=100 |
8 |
Correct |
13 ms |
23884 KB |
n=100 |
9 |
Correct |
13 ms |
23932 KB |
n=100 |
10 |
Correct |
13 ms |
23884 KB |
n=100 |
11 |
Correct |
12 ms |
23884 KB |
n=100 |
12 |
Correct |
14 ms |
23884 KB |
n=100 |
13 |
Correct |
14 ms |
23840 KB |
n=100 |
14 |
Correct |
13 ms |
23908 KB |
n=100 |
15 |
Correct |
13 ms |
23924 KB |
n=100 |
16 |
Correct |
13 ms |
23860 KB |
n=100 |
17 |
Correct |
12 ms |
23928 KB |
n=100 |
18 |
Correct |
12 ms |
23884 KB |
n=100 |
19 |
Correct |
14 ms |
23820 KB |
n=100 |
20 |
Correct |
13 ms |
23884 KB |
n=100 |
21 |
Correct |
13 ms |
23908 KB |
n=100 |
22 |
Correct |
13 ms |
23928 KB |
n=100 |
23 |
Correct |
13 ms |
23884 KB |
n=100 |
24 |
Correct |
13 ms |
23884 KB |
n=100 |
25 |
Correct |
13 ms |
23884 KB |
n=100 |
26 |
Correct |
13 ms |
23832 KB |
n=12 |
27 |
Correct |
13 ms |
23884 KB |
n=100 |
28 |
Correct |
14 ms |
24012 KB |
n=500 |
29 |
Correct |
14 ms |
24012 KB |
n=500 |
30 |
Correct |
13 ms |
23944 KB |
n=500 |
31 |
Correct |
16 ms |
23940 KB |
n=500 |
32 |
Correct |
14 ms |
24024 KB |
n=500 |
33 |
Correct |
14 ms |
23952 KB |
n=500 |
34 |
Correct |
15 ms |
24012 KB |
n=500 |
35 |
Correct |
14 ms |
23964 KB |
n=500 |
36 |
Correct |
16 ms |
23944 KB |
n=500 |
37 |
Correct |
13 ms |
23940 KB |
n=500 |
38 |
Correct |
14 ms |
23940 KB |
n=500 |
39 |
Correct |
14 ms |
24012 KB |
n=500 |
40 |
Correct |
13 ms |
24012 KB |
n=500 |
41 |
Correct |
13 ms |
23936 KB |
n=500 |
42 |
Correct |
15 ms |
23960 KB |
n=500 |
43 |
Correct |
14 ms |
23940 KB |
n=500 |
44 |
Correct |
14 ms |
23940 KB |
n=500 |
45 |
Correct |
14 ms |
23952 KB |
n=500 |
46 |
Correct |
13 ms |
23940 KB |
n=500 |
47 |
Correct |
13 ms |
24012 KB |
n=500 |
48 |
Correct |
14 ms |
24012 KB |
n=500 |
49 |
Correct |
14 ms |
23944 KB |
n=500 |
50 |
Correct |
14 ms |
24012 KB |
n=500 |
51 |
Correct |
14 ms |
23952 KB |
n=500 |
52 |
Correct |
17 ms |
23980 KB |
n=500 |
53 |
Correct |
15 ms |
24032 KB |
n=500 |
54 |
Correct |
17 ms |
24064 KB |
n=500 |
55 |
Correct |
14 ms |
23884 KB |
n=278 |
56 |
Correct |
14 ms |
24012 KB |
n=500 |
57 |
Correct |
14 ms |
24024 KB |
n=500 |
58 |
Correct |
14 ms |
23996 KB |
n=500 |
59 |
Correct |
15 ms |
24356 KB |
n=2000 |
60 |
Correct |
15 ms |
24456 KB |
n=2000 |
61 |
Correct |
16 ms |
24356 KB |
n=2000 |
62 |
Correct |
16 ms |
24396 KB |
n=2000 |
63 |
Correct |
16 ms |
24336 KB |
n=2000 |
64 |
Correct |
15 ms |
24400 KB |
n=2000 |
65 |
Correct |
17 ms |
24268 KB |
n=2000 |
66 |
Correct |
16 ms |
24420 KB |
n=2000 |
67 |
Correct |
16 ms |
24384 KB |
n=2000 |
68 |
Correct |
15 ms |
24396 KB |
n=2000 |
69 |
Correct |
15 ms |
24396 KB |
n=2000 |
70 |
Correct |
15 ms |
24328 KB |
n=2000 |
71 |
Correct |
15 ms |
24396 KB |
n=2000 |
72 |
Correct |
15 ms |
24356 KB |
n=2000 |
73 |
Correct |
15 ms |
24372 KB |
n=2000 |
74 |
Correct |
16 ms |
24268 KB |
n=1844 |
75 |
Correct |
15 ms |
24336 KB |
n=2000 |
76 |
Correct |
16 ms |
24280 KB |
n=2000 |
77 |
Correct |
16 ms |
24312 KB |
n=2000 |
78 |
Correct |
16 ms |
24268 KB |
n=2000 |
79 |
Correct |
16 ms |
24268 KB |
n=2000 |
80 |
Correct |
16 ms |
24396 KB |
n=2000 |
81 |
Correct |
15 ms |
24396 KB |
n=2000 |
82 |
Correct |
16 ms |
24324 KB |
n=2000 |
83 |
Correct |
16 ms |
24332 KB |
n=2000 |
84 |
Correct |
17 ms |
24308 KB |
n=2000 |
85 |
Correct |
18 ms |
24396 KB |
n=2000 |
86 |
Correct |
18 ms |
24312 KB |
n=2000 |
87 |
Correct |
17 ms |
24332 KB |
n=2000 |
88 |
Correct |
16 ms |
24464 KB |
n=2000 |
89 |
Correct |
15 ms |
24396 KB |
n=2000 |
90 |
Correct |
15 ms |
24372 KB |
n=2000 |
91 |
Correct |
16 ms |
24396 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23884 KB |
n=5 |
2 |
Correct |
14 ms |
23988 KB |
n=100 |
3 |
Correct |
14 ms |
23928 KB |
n=100 |
4 |
Correct |
14 ms |
23804 KB |
n=100 |
5 |
Correct |
14 ms |
23884 KB |
n=100 |
6 |
Correct |
14 ms |
23884 KB |
n=100 |
7 |
Correct |
13 ms |
23844 KB |
n=100 |
8 |
Correct |
13 ms |
23884 KB |
n=100 |
9 |
Correct |
13 ms |
23932 KB |
n=100 |
10 |
Correct |
13 ms |
23884 KB |
n=100 |
11 |
Correct |
12 ms |
23884 KB |
n=100 |
12 |
Correct |
14 ms |
23884 KB |
n=100 |
13 |
Correct |
14 ms |
23840 KB |
n=100 |
14 |
Correct |
13 ms |
23908 KB |
n=100 |
15 |
Correct |
13 ms |
23924 KB |
n=100 |
16 |
Correct |
13 ms |
23860 KB |
n=100 |
17 |
Correct |
12 ms |
23928 KB |
n=100 |
18 |
Correct |
12 ms |
23884 KB |
n=100 |
19 |
Correct |
14 ms |
23820 KB |
n=100 |
20 |
Correct |
13 ms |
23884 KB |
n=100 |
21 |
Correct |
13 ms |
23908 KB |
n=100 |
22 |
Correct |
13 ms |
23928 KB |
n=100 |
23 |
Correct |
13 ms |
23884 KB |
n=100 |
24 |
Correct |
13 ms |
23884 KB |
n=100 |
25 |
Correct |
13 ms |
23884 KB |
n=100 |
26 |
Correct |
13 ms |
23832 KB |
n=12 |
27 |
Correct |
13 ms |
23884 KB |
n=100 |
28 |
Correct |
14 ms |
24012 KB |
n=500 |
29 |
Correct |
14 ms |
24012 KB |
n=500 |
30 |
Correct |
13 ms |
23944 KB |
n=500 |
31 |
Correct |
16 ms |
23940 KB |
n=500 |
32 |
Correct |
14 ms |
24024 KB |
n=500 |
33 |
Correct |
14 ms |
23952 KB |
n=500 |
34 |
Correct |
15 ms |
24012 KB |
n=500 |
35 |
Correct |
14 ms |
23964 KB |
n=500 |
36 |
Correct |
16 ms |
23944 KB |
n=500 |
37 |
Correct |
13 ms |
23940 KB |
n=500 |
38 |
Correct |
14 ms |
23940 KB |
n=500 |
39 |
Correct |
14 ms |
24012 KB |
n=500 |
40 |
Correct |
13 ms |
24012 KB |
n=500 |
41 |
Correct |
13 ms |
23936 KB |
n=500 |
42 |
Correct |
15 ms |
23960 KB |
n=500 |
43 |
Correct |
14 ms |
23940 KB |
n=500 |
44 |
Correct |
14 ms |
23940 KB |
n=500 |
45 |
Correct |
14 ms |
23952 KB |
n=500 |
46 |
Correct |
13 ms |
23940 KB |
n=500 |
47 |
Correct |
13 ms |
24012 KB |
n=500 |
48 |
Correct |
14 ms |
24012 KB |
n=500 |
49 |
Correct |
14 ms |
23944 KB |
n=500 |
50 |
Correct |
14 ms |
24012 KB |
n=500 |
51 |
Correct |
14 ms |
23952 KB |
n=500 |
52 |
Correct |
17 ms |
23980 KB |
n=500 |
53 |
Correct |
15 ms |
24032 KB |
n=500 |
54 |
Correct |
17 ms |
24064 KB |
n=500 |
55 |
Correct |
14 ms |
23884 KB |
n=278 |
56 |
Correct |
14 ms |
24012 KB |
n=500 |
57 |
Correct |
14 ms |
24024 KB |
n=500 |
58 |
Correct |
14 ms |
23996 KB |
n=500 |
59 |
Correct |
15 ms |
24356 KB |
n=2000 |
60 |
Correct |
15 ms |
24456 KB |
n=2000 |
61 |
Correct |
16 ms |
24356 KB |
n=2000 |
62 |
Correct |
16 ms |
24396 KB |
n=2000 |
63 |
Correct |
16 ms |
24336 KB |
n=2000 |
64 |
Correct |
15 ms |
24400 KB |
n=2000 |
65 |
Correct |
17 ms |
24268 KB |
n=2000 |
66 |
Correct |
16 ms |
24420 KB |
n=2000 |
67 |
Correct |
16 ms |
24384 KB |
n=2000 |
68 |
Correct |
15 ms |
24396 KB |
n=2000 |
69 |
Correct |
15 ms |
24396 KB |
n=2000 |
70 |
Correct |
15 ms |
24328 KB |
n=2000 |
71 |
Correct |
15 ms |
24396 KB |
n=2000 |
72 |
Correct |
15 ms |
24356 KB |
n=2000 |
73 |
Correct |
15 ms |
24372 KB |
n=2000 |
74 |
Correct |
16 ms |
24268 KB |
n=1844 |
75 |
Correct |
15 ms |
24336 KB |
n=2000 |
76 |
Correct |
16 ms |
24280 KB |
n=2000 |
77 |
Correct |
16 ms |
24312 KB |
n=2000 |
78 |
Correct |
16 ms |
24268 KB |
n=2000 |
79 |
Correct |
16 ms |
24268 KB |
n=2000 |
80 |
Correct |
16 ms |
24396 KB |
n=2000 |
81 |
Correct |
15 ms |
24396 KB |
n=2000 |
82 |
Correct |
16 ms |
24324 KB |
n=2000 |
83 |
Correct |
16 ms |
24332 KB |
n=2000 |
84 |
Correct |
17 ms |
24308 KB |
n=2000 |
85 |
Correct |
18 ms |
24396 KB |
n=2000 |
86 |
Correct |
18 ms |
24312 KB |
n=2000 |
87 |
Correct |
17 ms |
24332 KB |
n=2000 |
88 |
Correct |
16 ms |
24464 KB |
n=2000 |
89 |
Correct |
15 ms |
24396 KB |
n=2000 |
90 |
Correct |
15 ms |
24372 KB |
n=2000 |
91 |
Correct |
16 ms |
24396 KB |
n=2000 |
92 |
Correct |
1271 ms |
71896 KB |
n=200000 |
93 |
Correct |
913 ms |
77252 KB |
n=200000 |
94 |
Correct |
619 ms |
77892 KB |
n=200000 |
95 |
Correct |
1248 ms |
70932 KB |
n=200000 |
96 |
Correct |
1209 ms |
70720 KB |
n=200000 |
97 |
Correct |
1065 ms |
73936 KB |
n=200000 |
98 |
Correct |
1229 ms |
71044 KB |
n=200000 |
99 |
Correct |
1246 ms |
70052 KB |
n=200000 |
100 |
Correct |
1197 ms |
70912 KB |
n=200000 |
101 |
Correct |
473 ms |
80360 KB |
n=200000 |
102 |
Correct |
614 ms |
71788 KB |
n=200000 |
103 |
Correct |
592 ms |
72184 KB |
n=200000 |
104 |
Correct |
608 ms |
72592 KB |
n=200000 |
105 |
Correct |
589 ms |
73348 KB |
n=200000 |
106 |
Correct |
590 ms |
73632 KB |
n=200000 |
107 |
Correct |
586 ms |
73936 KB |
n=200000 |
108 |
Correct |
1144 ms |
72872 KB |
n=200000 |
109 |
Correct |
1169 ms |
72932 KB |
n=200000 |
110 |
Correct |
1182 ms |
73348 KB |
n=200000 |
111 |
Correct |
1060 ms |
72860 KB |
n=200000 |
112 |
Correct |
529 ms |
81232 KB |
n=200000 |
113 |
Correct |
1010 ms |
76864 KB |
n=200000 |
114 |
Correct |
1133 ms |
73016 KB |
n=200000 |
115 |
Correct |
1316 ms |
74432 KB |
n=200000 |
116 |
Correct |
1200 ms |
73176 KB |
n=200000 |
117 |
Correct |
490 ms |
80628 KB |
n=200000 |
118 |
Correct |
1137 ms |
74624 KB |
n=200000 |
119 |
Correct |
1186 ms |
72564 KB |
n=200000 |
120 |
Correct |
405 ms |
80152 KB |
n=200000 |
121 |
Correct |
421 ms |
80152 KB |
n=200000 |
122 |
Correct |
415 ms |
80380 KB |
n=200000 |
123 |
Correct |
631 ms |
72188 KB |
n=200000 |
124 |
Correct |
157 ms |
38788 KB |
n=25264 |