#include <bits/stdc++.h>
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
typedef pair<int, int> ii;
const int N = 2e5 + 5;
vector<int> g[N];
int n, m, q, a[N], dep[N], par[N][20], b[N];
void dfs(int u, int p) {
par[u][0] = p;
fa (v, g[u]) if (v != p) {
dep[v] = dep[u] + 1;
dfs(v, u);
}
}
void sparse() {
fw (j, 1, 20) fw (i, 0, n) if (par[i][j - 1] != -1) {
par[i][j] = par[par[i][j - 1]][j - 1];
}
}
int getLCA(int u, int v) {
if (dep[u] < dep[v]) swap(u, v);
int diff = dep[u] - dep[v];
fw (i, 0, 20) if (diff & (1 << i)) u = par[u][i];
if (u == v) return u;
bw (i, 20, 0) if (par[u][i] != par[v][i]) {
u = par[u][i], v = par[v][i];
}
return par[u][0];
}
set<int> app1[N], app2[N];
signed main() {
#ifdef BLU
in("blu.inp");
#endif
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m >> q;
fw (i, 1, n) {
int u, v;
cin >> u >> v;
u--, v--;
g[u].pb(v), g[v].pb(u);
}
fw (i, 0, m) cin >> a[i], a[i]--;
dfs(0, -1);
sparse();
//b[i] = lca(a[i], a[i + 1])
fw (i, 0, m - 1) b[i] = getLCA(a[i], a[i + 1]);
fw (i, 0, m) app1[a[i]].insert(i);
fw (i, 0, m - 1) app2[b[i]].insert(i);
while (q--) {
int type;
cin >> type;
if (type == 1) {
int pos, v;
cin >> pos >> v;
pos--, v--;
app1[a[pos]].erase(pos);
if (pos) app2[b[pos - 1]].erase(pos - 1);
if (pos < m - 1) app2[b[pos]].erase(pos);
a[pos] = v;
app1[a[pos]].insert(pos);
if (pos) {
b[pos - 1] = getLCA(a[pos - 1], a[pos]);
app2[b[pos - 1]].insert(pos - 1);
}
if (pos < m - 1) {
b[pos] = getLCA(a[pos], a[pos + 1]);
// st2.ins(pos, b[pos]);
app2[b[pos]].insert(pos);
}
} else {
int l, r, v;
cin >> l >> r >> v;
l--, r--, v--;
auto lol = app1[v].upper_bound(r);
int x = -1;
if (lol != app1[v].begin()) {
--lol;
x = *lol;
}
if (x >= l && x <= r) {
// cout << "what's cookin'\n";
cout << x + 1 << " " << x + 1 << "\n";
} else {
// x = st2.check(l, r - 1, v);
lol = app2[v].upper_bound(r - 1);
x = -1;
if (lol != app2[v].begin()) {
--lol;
x = *lol;
}
if (x >= l && x < r) cout << x + 1 << " " << x + 2 << "\n";
else cout << "-1 -1\n";
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
n=5 |
2 |
Correct |
23 ms |
23928 KB |
n=100 |
3 |
Correct |
23 ms |
23928 KB |
n=100 |
4 |
Correct |
23 ms |
23928 KB |
n=100 |
5 |
Correct |
23 ms |
23928 KB |
n=100 |
6 |
Correct |
23 ms |
23808 KB |
n=100 |
7 |
Correct |
23 ms |
23800 KB |
n=100 |
8 |
Correct |
23 ms |
23900 KB |
n=100 |
9 |
Correct |
22 ms |
23800 KB |
n=100 |
10 |
Correct |
23 ms |
23928 KB |
n=100 |
11 |
Correct |
23 ms |
23928 KB |
n=100 |
12 |
Correct |
23 ms |
23800 KB |
n=100 |
13 |
Correct |
23 ms |
23800 KB |
n=100 |
14 |
Correct |
23 ms |
23800 KB |
n=100 |
15 |
Correct |
22 ms |
23672 KB |
n=100 |
16 |
Correct |
23 ms |
23800 KB |
n=100 |
17 |
Correct |
23 ms |
23928 KB |
n=100 |
18 |
Correct |
23 ms |
23800 KB |
n=100 |
19 |
Correct |
23 ms |
23800 KB |
n=100 |
20 |
Correct |
23 ms |
23800 KB |
n=100 |
21 |
Correct |
24 ms |
23912 KB |
n=100 |
22 |
Correct |
23 ms |
23800 KB |
n=100 |
23 |
Correct |
23 ms |
23928 KB |
n=100 |
24 |
Correct |
23 ms |
23928 KB |
n=100 |
25 |
Correct |
23 ms |
23800 KB |
n=100 |
26 |
Correct |
23 ms |
23852 KB |
n=12 |
27 |
Correct |
23 ms |
23800 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
n=5 |
2 |
Correct |
23 ms |
23928 KB |
n=100 |
3 |
Correct |
23 ms |
23928 KB |
n=100 |
4 |
Correct |
23 ms |
23928 KB |
n=100 |
5 |
Correct |
23 ms |
23928 KB |
n=100 |
6 |
Correct |
23 ms |
23808 KB |
n=100 |
7 |
Correct |
23 ms |
23800 KB |
n=100 |
8 |
Correct |
23 ms |
23900 KB |
n=100 |
9 |
Correct |
22 ms |
23800 KB |
n=100 |
10 |
Correct |
23 ms |
23928 KB |
n=100 |
11 |
Correct |
23 ms |
23928 KB |
n=100 |
12 |
Correct |
23 ms |
23800 KB |
n=100 |
13 |
Correct |
23 ms |
23800 KB |
n=100 |
14 |
Correct |
23 ms |
23800 KB |
n=100 |
15 |
Correct |
22 ms |
23672 KB |
n=100 |
16 |
Correct |
23 ms |
23800 KB |
n=100 |
17 |
Correct |
23 ms |
23928 KB |
n=100 |
18 |
Correct |
23 ms |
23800 KB |
n=100 |
19 |
Correct |
23 ms |
23800 KB |
n=100 |
20 |
Correct |
23 ms |
23800 KB |
n=100 |
21 |
Correct |
24 ms |
23912 KB |
n=100 |
22 |
Correct |
23 ms |
23800 KB |
n=100 |
23 |
Correct |
23 ms |
23928 KB |
n=100 |
24 |
Correct |
23 ms |
23928 KB |
n=100 |
25 |
Correct |
23 ms |
23800 KB |
n=100 |
26 |
Correct |
23 ms |
23852 KB |
n=12 |
27 |
Correct |
23 ms |
23800 KB |
n=100 |
28 |
Correct |
24 ms |
24056 KB |
n=500 |
29 |
Correct |
23 ms |
23928 KB |
n=500 |
30 |
Correct |
23 ms |
23928 KB |
n=500 |
31 |
Correct |
25 ms |
24184 KB |
n=500 |
32 |
Correct |
24 ms |
23928 KB |
n=500 |
33 |
Correct |
28 ms |
23928 KB |
n=500 |
34 |
Correct |
30 ms |
23928 KB |
n=500 |
35 |
Correct |
23 ms |
23928 KB |
n=500 |
36 |
Correct |
24 ms |
23940 KB |
n=500 |
37 |
Correct |
23 ms |
23928 KB |
n=500 |
38 |
Correct |
24 ms |
23936 KB |
n=500 |
39 |
Correct |
24 ms |
24056 KB |
n=500 |
40 |
Correct |
24 ms |
23928 KB |
n=500 |
41 |
Correct |
24 ms |
23928 KB |
n=500 |
42 |
Correct |
23 ms |
23928 KB |
n=500 |
43 |
Correct |
24 ms |
23928 KB |
n=500 |
44 |
Correct |
23 ms |
23928 KB |
n=500 |
45 |
Correct |
24 ms |
23928 KB |
n=500 |
46 |
Correct |
23 ms |
23928 KB |
n=500 |
47 |
Correct |
24 ms |
23940 KB |
n=500 |
48 |
Correct |
24 ms |
24056 KB |
n=500 |
49 |
Correct |
24 ms |
23932 KB |
n=500 |
50 |
Correct |
23 ms |
23928 KB |
n=500 |
51 |
Correct |
23 ms |
23928 KB |
n=500 |
52 |
Correct |
24 ms |
24056 KB |
n=500 |
53 |
Correct |
23 ms |
23928 KB |
n=500 |
54 |
Correct |
24 ms |
24056 KB |
n=500 |
55 |
Correct |
24 ms |
23928 KB |
n=278 |
56 |
Correct |
24 ms |
23928 KB |
n=500 |
57 |
Correct |
23 ms |
23928 KB |
n=500 |
58 |
Correct |
24 ms |
23928 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
n=5 |
2 |
Correct |
23 ms |
23928 KB |
n=100 |
3 |
Correct |
23 ms |
23928 KB |
n=100 |
4 |
Correct |
23 ms |
23928 KB |
n=100 |
5 |
Correct |
23 ms |
23928 KB |
n=100 |
6 |
Correct |
23 ms |
23808 KB |
n=100 |
7 |
Correct |
23 ms |
23800 KB |
n=100 |
8 |
Correct |
23 ms |
23900 KB |
n=100 |
9 |
Correct |
22 ms |
23800 KB |
n=100 |
10 |
Correct |
23 ms |
23928 KB |
n=100 |
11 |
Correct |
23 ms |
23928 KB |
n=100 |
12 |
Correct |
23 ms |
23800 KB |
n=100 |
13 |
Correct |
23 ms |
23800 KB |
n=100 |
14 |
Correct |
23 ms |
23800 KB |
n=100 |
15 |
Correct |
22 ms |
23672 KB |
n=100 |
16 |
Correct |
23 ms |
23800 KB |
n=100 |
17 |
Correct |
23 ms |
23928 KB |
n=100 |
18 |
Correct |
23 ms |
23800 KB |
n=100 |
19 |
Correct |
23 ms |
23800 KB |
n=100 |
20 |
Correct |
23 ms |
23800 KB |
n=100 |
21 |
Correct |
24 ms |
23912 KB |
n=100 |
22 |
Correct |
23 ms |
23800 KB |
n=100 |
23 |
Correct |
23 ms |
23928 KB |
n=100 |
24 |
Correct |
23 ms |
23928 KB |
n=100 |
25 |
Correct |
23 ms |
23800 KB |
n=100 |
26 |
Correct |
23 ms |
23852 KB |
n=12 |
27 |
Correct |
23 ms |
23800 KB |
n=100 |
28 |
Correct |
24 ms |
24056 KB |
n=500 |
29 |
Correct |
23 ms |
23928 KB |
n=500 |
30 |
Correct |
23 ms |
23928 KB |
n=500 |
31 |
Correct |
25 ms |
24184 KB |
n=500 |
32 |
Correct |
24 ms |
23928 KB |
n=500 |
33 |
Correct |
28 ms |
23928 KB |
n=500 |
34 |
Correct |
30 ms |
23928 KB |
n=500 |
35 |
Correct |
23 ms |
23928 KB |
n=500 |
36 |
Correct |
24 ms |
23940 KB |
n=500 |
37 |
Correct |
23 ms |
23928 KB |
n=500 |
38 |
Correct |
24 ms |
23936 KB |
n=500 |
39 |
Correct |
24 ms |
24056 KB |
n=500 |
40 |
Correct |
24 ms |
23928 KB |
n=500 |
41 |
Correct |
24 ms |
23928 KB |
n=500 |
42 |
Correct |
23 ms |
23928 KB |
n=500 |
43 |
Correct |
24 ms |
23928 KB |
n=500 |
44 |
Correct |
23 ms |
23928 KB |
n=500 |
45 |
Correct |
24 ms |
23928 KB |
n=500 |
46 |
Correct |
23 ms |
23928 KB |
n=500 |
47 |
Correct |
24 ms |
23940 KB |
n=500 |
48 |
Correct |
24 ms |
24056 KB |
n=500 |
49 |
Correct |
24 ms |
23932 KB |
n=500 |
50 |
Correct |
23 ms |
23928 KB |
n=500 |
51 |
Correct |
23 ms |
23928 KB |
n=500 |
52 |
Correct |
24 ms |
24056 KB |
n=500 |
53 |
Correct |
23 ms |
23928 KB |
n=500 |
54 |
Correct |
24 ms |
24056 KB |
n=500 |
55 |
Correct |
24 ms |
23928 KB |
n=278 |
56 |
Correct |
24 ms |
23928 KB |
n=500 |
57 |
Correct |
23 ms |
23928 KB |
n=500 |
58 |
Correct |
24 ms |
23928 KB |
n=500 |
59 |
Correct |
26 ms |
24312 KB |
n=2000 |
60 |
Correct |
27 ms |
24440 KB |
n=2000 |
61 |
Correct |
26 ms |
24440 KB |
n=2000 |
62 |
Correct |
28 ms |
24440 KB |
n=2000 |
63 |
Correct |
27 ms |
24312 KB |
n=2000 |
64 |
Correct |
27 ms |
24412 KB |
n=2000 |
65 |
Correct |
27 ms |
24316 KB |
n=2000 |
66 |
Correct |
26 ms |
24440 KB |
n=2000 |
67 |
Correct |
27 ms |
24312 KB |
n=2000 |
68 |
Correct |
27 ms |
24440 KB |
n=2000 |
69 |
Correct |
26 ms |
24312 KB |
n=2000 |
70 |
Correct |
27 ms |
24404 KB |
n=2000 |
71 |
Correct |
26 ms |
24312 KB |
n=2000 |
72 |
Correct |
26 ms |
24312 KB |
n=2000 |
73 |
Correct |
26 ms |
24312 KB |
n=2000 |
74 |
Correct |
27 ms |
24312 KB |
n=1844 |
75 |
Correct |
26 ms |
24312 KB |
n=2000 |
76 |
Correct |
27 ms |
24312 KB |
n=2000 |
77 |
Correct |
27 ms |
24408 KB |
n=2000 |
78 |
Correct |
27 ms |
24312 KB |
n=2000 |
79 |
Correct |
27 ms |
24312 KB |
n=2000 |
80 |
Correct |
28 ms |
24444 KB |
n=2000 |
81 |
Correct |
33 ms |
24440 KB |
n=2000 |
82 |
Correct |
29 ms |
24568 KB |
n=2000 |
83 |
Correct |
27 ms |
24440 KB |
n=2000 |
84 |
Correct |
27 ms |
24440 KB |
n=2000 |
85 |
Correct |
27 ms |
24440 KB |
n=2000 |
86 |
Correct |
28 ms |
24356 KB |
n=2000 |
87 |
Correct |
27 ms |
24312 KB |
n=2000 |
88 |
Correct |
26 ms |
24440 KB |
n=2000 |
89 |
Correct |
26 ms |
24440 KB |
n=2000 |
90 |
Correct |
27 ms |
24412 KB |
n=2000 |
91 |
Correct |
26 ms |
24312 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
n=5 |
2 |
Correct |
23 ms |
23928 KB |
n=100 |
3 |
Correct |
23 ms |
23928 KB |
n=100 |
4 |
Correct |
23 ms |
23928 KB |
n=100 |
5 |
Correct |
23 ms |
23928 KB |
n=100 |
6 |
Correct |
23 ms |
23808 KB |
n=100 |
7 |
Correct |
23 ms |
23800 KB |
n=100 |
8 |
Correct |
23 ms |
23900 KB |
n=100 |
9 |
Correct |
22 ms |
23800 KB |
n=100 |
10 |
Correct |
23 ms |
23928 KB |
n=100 |
11 |
Correct |
23 ms |
23928 KB |
n=100 |
12 |
Correct |
23 ms |
23800 KB |
n=100 |
13 |
Correct |
23 ms |
23800 KB |
n=100 |
14 |
Correct |
23 ms |
23800 KB |
n=100 |
15 |
Correct |
22 ms |
23672 KB |
n=100 |
16 |
Correct |
23 ms |
23800 KB |
n=100 |
17 |
Correct |
23 ms |
23928 KB |
n=100 |
18 |
Correct |
23 ms |
23800 KB |
n=100 |
19 |
Correct |
23 ms |
23800 KB |
n=100 |
20 |
Correct |
23 ms |
23800 KB |
n=100 |
21 |
Correct |
24 ms |
23912 KB |
n=100 |
22 |
Correct |
23 ms |
23800 KB |
n=100 |
23 |
Correct |
23 ms |
23928 KB |
n=100 |
24 |
Correct |
23 ms |
23928 KB |
n=100 |
25 |
Correct |
23 ms |
23800 KB |
n=100 |
26 |
Correct |
23 ms |
23852 KB |
n=12 |
27 |
Correct |
23 ms |
23800 KB |
n=100 |
28 |
Correct |
24 ms |
24056 KB |
n=500 |
29 |
Correct |
23 ms |
23928 KB |
n=500 |
30 |
Correct |
23 ms |
23928 KB |
n=500 |
31 |
Correct |
25 ms |
24184 KB |
n=500 |
32 |
Correct |
24 ms |
23928 KB |
n=500 |
33 |
Correct |
28 ms |
23928 KB |
n=500 |
34 |
Correct |
30 ms |
23928 KB |
n=500 |
35 |
Correct |
23 ms |
23928 KB |
n=500 |
36 |
Correct |
24 ms |
23940 KB |
n=500 |
37 |
Correct |
23 ms |
23928 KB |
n=500 |
38 |
Correct |
24 ms |
23936 KB |
n=500 |
39 |
Correct |
24 ms |
24056 KB |
n=500 |
40 |
Correct |
24 ms |
23928 KB |
n=500 |
41 |
Correct |
24 ms |
23928 KB |
n=500 |
42 |
Correct |
23 ms |
23928 KB |
n=500 |
43 |
Correct |
24 ms |
23928 KB |
n=500 |
44 |
Correct |
23 ms |
23928 KB |
n=500 |
45 |
Correct |
24 ms |
23928 KB |
n=500 |
46 |
Correct |
23 ms |
23928 KB |
n=500 |
47 |
Correct |
24 ms |
23940 KB |
n=500 |
48 |
Correct |
24 ms |
24056 KB |
n=500 |
49 |
Correct |
24 ms |
23932 KB |
n=500 |
50 |
Correct |
23 ms |
23928 KB |
n=500 |
51 |
Correct |
23 ms |
23928 KB |
n=500 |
52 |
Correct |
24 ms |
24056 KB |
n=500 |
53 |
Correct |
23 ms |
23928 KB |
n=500 |
54 |
Correct |
24 ms |
24056 KB |
n=500 |
55 |
Correct |
24 ms |
23928 KB |
n=278 |
56 |
Correct |
24 ms |
23928 KB |
n=500 |
57 |
Correct |
23 ms |
23928 KB |
n=500 |
58 |
Correct |
24 ms |
23928 KB |
n=500 |
59 |
Correct |
26 ms |
24312 KB |
n=2000 |
60 |
Correct |
27 ms |
24440 KB |
n=2000 |
61 |
Correct |
26 ms |
24440 KB |
n=2000 |
62 |
Correct |
28 ms |
24440 KB |
n=2000 |
63 |
Correct |
27 ms |
24312 KB |
n=2000 |
64 |
Correct |
27 ms |
24412 KB |
n=2000 |
65 |
Correct |
27 ms |
24316 KB |
n=2000 |
66 |
Correct |
26 ms |
24440 KB |
n=2000 |
67 |
Correct |
27 ms |
24312 KB |
n=2000 |
68 |
Correct |
27 ms |
24440 KB |
n=2000 |
69 |
Correct |
26 ms |
24312 KB |
n=2000 |
70 |
Correct |
27 ms |
24404 KB |
n=2000 |
71 |
Correct |
26 ms |
24312 KB |
n=2000 |
72 |
Correct |
26 ms |
24312 KB |
n=2000 |
73 |
Correct |
26 ms |
24312 KB |
n=2000 |
74 |
Correct |
27 ms |
24312 KB |
n=1844 |
75 |
Correct |
26 ms |
24312 KB |
n=2000 |
76 |
Correct |
27 ms |
24312 KB |
n=2000 |
77 |
Correct |
27 ms |
24408 KB |
n=2000 |
78 |
Correct |
27 ms |
24312 KB |
n=2000 |
79 |
Correct |
27 ms |
24312 KB |
n=2000 |
80 |
Correct |
28 ms |
24444 KB |
n=2000 |
81 |
Correct |
33 ms |
24440 KB |
n=2000 |
82 |
Correct |
29 ms |
24568 KB |
n=2000 |
83 |
Correct |
27 ms |
24440 KB |
n=2000 |
84 |
Correct |
27 ms |
24440 KB |
n=2000 |
85 |
Correct |
27 ms |
24440 KB |
n=2000 |
86 |
Correct |
28 ms |
24356 KB |
n=2000 |
87 |
Correct |
27 ms |
24312 KB |
n=2000 |
88 |
Correct |
26 ms |
24440 KB |
n=2000 |
89 |
Correct |
26 ms |
24440 KB |
n=2000 |
90 |
Correct |
27 ms |
24412 KB |
n=2000 |
91 |
Correct |
26 ms |
24312 KB |
n=2000 |
92 |
Correct |
795 ms |
70424 KB |
n=200000 |
93 |
Correct |
921 ms |
77492 KB |
n=200000 |
94 |
Correct |
933 ms |
80728 KB |
n=200000 |
95 |
Correct |
793 ms |
70648 KB |
n=200000 |
96 |
Correct |
744 ms |
70760 KB |
n=200000 |
97 |
Correct |
1008 ms |
76640 KB |
n=200000 |
98 |
Correct |
786 ms |
71100 KB |
n=200000 |
99 |
Correct |
906 ms |
74656 KB |
n=200000 |
100 |
Correct |
792 ms |
72240 KB |
n=200000 |
101 |
Correct |
876 ms |
80348 KB |
n=200000 |
102 |
Correct |
592 ms |
75232 KB |
n=200000 |
103 |
Correct |
517 ms |
75180 KB |
n=200000 |
104 |
Correct |
488 ms |
76420 KB |
n=200000 |
105 |
Correct |
520 ms |
72696 KB |
n=200000 |
106 |
Correct |
508 ms |
72628 KB |
n=200000 |
107 |
Correct |
496 ms |
72712 KB |
n=200000 |
108 |
Correct |
896 ms |
75280 KB |
n=200000 |
109 |
Correct |
929 ms |
73880 KB |
n=200000 |
110 |
Correct |
915 ms |
75292 KB |
n=200000 |
111 |
Correct |
928 ms |
72852 KB |
n=200000 |
112 |
Correct |
1144 ms |
81488 KB |
n=200000 |
113 |
Correct |
1026 ms |
74476 KB |
n=200000 |
114 |
Correct |
793 ms |
72636 KB |
n=200000 |
115 |
Correct |
1002 ms |
72404 KB |
n=200000 |
116 |
Correct |
753 ms |
72316 KB |
n=200000 |
117 |
Correct |
974 ms |
79496 KB |
n=200000 |
118 |
Correct |
1071 ms |
73552 KB |
n=200000 |
119 |
Correct |
975 ms |
72052 KB |
n=200000 |
120 |
Correct |
985 ms |
81868 KB |
n=200000 |
121 |
Correct |
822 ms |
82912 KB |
n=200000 |
122 |
Correct |
883 ms |
80576 KB |
n=200000 |
123 |
Correct |
487 ms |
72180 KB |
n=200000 |
124 |
Correct |
232 ms |
39160 KB |
n=25264 |