#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
#define pb push_back
#define ld long double
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vec vector
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
const ld eps = 1e-6;
const int mod = 998244353;
const int oo = 2e9;
const ll OO = 2e18;
const int N = 2e5 + 10;
const int K = 20;
int n, m, q, a[N], timer, tin[N], tout[N], p[N][K];
vec<int> g[N];
set<pii> pos[N];
void dfs(int v, int pr = 1)
{
tin[v] = ++timer;
p[v][0] = pr;
for (int k = 1; k < K; k++) p[v][k] = p[p[v][k - 1]][k - 1];
for (int &to : g[v])
{
if (to == pr) continue;
dfs(to, v);
}
tout[v] = timer;
}
bool upper(int u, int v)
{
return tin[u] <= tin[v] && tout[u] >= tout[v];
}
int LCA(int u, int v)
{
if (upper(u, v)) return u;
if (upper(v, u)) return v;
for (int k = K - 1; k >= 0; k--) if (!upper(p[u][k], v)) u = p[u][k];
return p[u][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(1);
for (int i = 1; i <= m; i++) cin >> a[i];
for (int i = 1; i <= m; i++)
{
pos[a[i]].insert({i, i});
if (i + 1 <= m) pos[LCA(a[i], a[i + 1])].insert({i, i + 1});
}
while (q--)
{
int type;
cin >> type;
if (type == 1)
{
int idx, v;
cin >> idx >> v;
pos[a[idx]].erase({idx, idx});
if (idx > 1) pos[LCA(a[idx - 1], a[idx])].erase({idx - 1, idx});
if (idx + 1 <= m) pos[LCA(a[idx], a[idx + 1])].erase({idx, idx + 1});
a[idx] = v;
pos[a[idx]].insert({idx, idx});
if (idx > 1) pos[LCA(a[idx - 1], a[idx])].insert({idx - 1, idx});
if (idx + 1 <= m) pos[LCA(a[idx], a[idx + 1])].insert({idx, idx + 1});
}
else
{
int l, r, v;
cin >> l >> r >> v;
auto it = pos[v].lower_bound({l, l});
if (it == pos[v].end()) cout << "-1 -1";
else
{
pii p = *it;
if (p.f >= l && p.s <= r) cout << p.f << " " << p.s;
else cout << "-1 -1";
}
cout << "\n";
}
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
n=5 |
2 |
Correct |
8 ms |
14344 KB |
n=100 |
3 |
Correct |
8 ms |
14420 KB |
n=100 |
4 |
Correct |
8 ms |
14420 KB |
n=100 |
5 |
Correct |
8 ms |
14420 KB |
n=100 |
6 |
Correct |
8 ms |
14420 KB |
n=100 |
7 |
Correct |
8 ms |
14420 KB |
n=100 |
8 |
Correct |
9 ms |
14416 KB |
n=100 |
9 |
Correct |
8 ms |
14448 KB |
n=100 |
10 |
Correct |
8 ms |
14420 KB |
n=100 |
11 |
Correct |
8 ms |
14420 KB |
n=100 |
12 |
Correct |
8 ms |
14416 KB |
n=100 |
13 |
Correct |
9 ms |
14416 KB |
n=100 |
14 |
Correct |
10 ms |
14416 KB |
n=100 |
15 |
Correct |
8 ms |
14460 KB |
n=100 |
16 |
Correct |
9 ms |
14420 KB |
n=100 |
17 |
Correct |
7 ms |
14420 KB |
n=100 |
18 |
Correct |
8 ms |
14420 KB |
n=100 |
19 |
Correct |
8 ms |
14420 KB |
n=100 |
20 |
Correct |
9 ms |
14420 KB |
n=100 |
21 |
Correct |
8 ms |
14420 KB |
n=100 |
22 |
Correct |
9 ms |
14440 KB |
n=100 |
23 |
Correct |
8 ms |
14420 KB |
n=100 |
24 |
Correct |
8 ms |
14424 KB |
n=100 |
25 |
Correct |
8 ms |
14420 KB |
n=100 |
26 |
Correct |
8 ms |
14420 KB |
n=12 |
27 |
Correct |
8 ms |
14424 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
n=5 |
2 |
Correct |
8 ms |
14344 KB |
n=100 |
3 |
Correct |
8 ms |
14420 KB |
n=100 |
4 |
Correct |
8 ms |
14420 KB |
n=100 |
5 |
Correct |
8 ms |
14420 KB |
n=100 |
6 |
Correct |
8 ms |
14420 KB |
n=100 |
7 |
Correct |
8 ms |
14420 KB |
n=100 |
8 |
Correct |
9 ms |
14416 KB |
n=100 |
9 |
Correct |
8 ms |
14448 KB |
n=100 |
10 |
Correct |
8 ms |
14420 KB |
n=100 |
11 |
Correct |
8 ms |
14420 KB |
n=100 |
12 |
Correct |
8 ms |
14416 KB |
n=100 |
13 |
Correct |
9 ms |
14416 KB |
n=100 |
14 |
Correct |
10 ms |
14416 KB |
n=100 |
15 |
Correct |
8 ms |
14460 KB |
n=100 |
16 |
Correct |
9 ms |
14420 KB |
n=100 |
17 |
Correct |
7 ms |
14420 KB |
n=100 |
18 |
Correct |
8 ms |
14420 KB |
n=100 |
19 |
Correct |
8 ms |
14420 KB |
n=100 |
20 |
Correct |
9 ms |
14420 KB |
n=100 |
21 |
Correct |
8 ms |
14420 KB |
n=100 |
22 |
Correct |
9 ms |
14440 KB |
n=100 |
23 |
Correct |
8 ms |
14420 KB |
n=100 |
24 |
Correct |
8 ms |
14424 KB |
n=100 |
25 |
Correct |
8 ms |
14420 KB |
n=100 |
26 |
Correct |
8 ms |
14420 KB |
n=12 |
27 |
Correct |
8 ms |
14424 KB |
n=100 |
28 |
Correct |
9 ms |
14556 KB |
n=500 |
29 |
Correct |
9 ms |
14548 KB |
n=500 |
30 |
Correct |
9 ms |
14548 KB |
n=500 |
31 |
Correct |
8 ms |
14568 KB |
n=500 |
32 |
Correct |
9 ms |
14548 KB |
n=500 |
33 |
Correct |
10 ms |
14548 KB |
n=500 |
34 |
Correct |
9 ms |
14548 KB |
n=500 |
35 |
Correct |
9 ms |
14644 KB |
n=500 |
36 |
Correct |
9 ms |
14556 KB |
n=500 |
37 |
Correct |
9 ms |
14528 KB |
n=500 |
38 |
Correct |
9 ms |
14612 KB |
n=500 |
39 |
Correct |
8 ms |
14676 KB |
n=500 |
40 |
Correct |
8 ms |
14564 KB |
n=500 |
41 |
Correct |
8 ms |
14548 KB |
n=500 |
42 |
Correct |
8 ms |
14676 KB |
n=500 |
43 |
Correct |
10 ms |
14548 KB |
n=500 |
44 |
Correct |
10 ms |
14624 KB |
n=500 |
45 |
Correct |
9 ms |
14536 KB |
n=500 |
46 |
Correct |
8 ms |
14556 KB |
n=500 |
47 |
Correct |
9 ms |
14568 KB |
n=500 |
48 |
Correct |
8 ms |
14548 KB |
n=500 |
49 |
Correct |
11 ms |
14548 KB |
n=500 |
50 |
Correct |
9 ms |
14596 KB |
n=500 |
51 |
Correct |
10 ms |
14548 KB |
n=500 |
52 |
Correct |
8 ms |
14596 KB |
n=500 |
53 |
Correct |
8 ms |
14560 KB |
n=500 |
54 |
Correct |
8 ms |
14548 KB |
n=500 |
55 |
Correct |
9 ms |
14476 KB |
n=278 |
56 |
Correct |
9 ms |
14532 KB |
n=500 |
57 |
Correct |
8 ms |
14548 KB |
n=500 |
58 |
Correct |
9 ms |
14548 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
n=5 |
2 |
Correct |
8 ms |
14344 KB |
n=100 |
3 |
Correct |
8 ms |
14420 KB |
n=100 |
4 |
Correct |
8 ms |
14420 KB |
n=100 |
5 |
Correct |
8 ms |
14420 KB |
n=100 |
6 |
Correct |
8 ms |
14420 KB |
n=100 |
7 |
Correct |
8 ms |
14420 KB |
n=100 |
8 |
Correct |
9 ms |
14416 KB |
n=100 |
9 |
Correct |
8 ms |
14448 KB |
n=100 |
10 |
Correct |
8 ms |
14420 KB |
n=100 |
11 |
Correct |
8 ms |
14420 KB |
n=100 |
12 |
Correct |
8 ms |
14416 KB |
n=100 |
13 |
Correct |
9 ms |
14416 KB |
n=100 |
14 |
Correct |
10 ms |
14416 KB |
n=100 |
15 |
Correct |
8 ms |
14460 KB |
n=100 |
16 |
Correct |
9 ms |
14420 KB |
n=100 |
17 |
Correct |
7 ms |
14420 KB |
n=100 |
18 |
Correct |
8 ms |
14420 KB |
n=100 |
19 |
Correct |
8 ms |
14420 KB |
n=100 |
20 |
Correct |
9 ms |
14420 KB |
n=100 |
21 |
Correct |
8 ms |
14420 KB |
n=100 |
22 |
Correct |
9 ms |
14440 KB |
n=100 |
23 |
Correct |
8 ms |
14420 KB |
n=100 |
24 |
Correct |
8 ms |
14424 KB |
n=100 |
25 |
Correct |
8 ms |
14420 KB |
n=100 |
26 |
Correct |
8 ms |
14420 KB |
n=12 |
27 |
Correct |
8 ms |
14424 KB |
n=100 |
28 |
Correct |
9 ms |
14556 KB |
n=500 |
29 |
Correct |
9 ms |
14548 KB |
n=500 |
30 |
Correct |
9 ms |
14548 KB |
n=500 |
31 |
Correct |
8 ms |
14568 KB |
n=500 |
32 |
Correct |
9 ms |
14548 KB |
n=500 |
33 |
Correct |
10 ms |
14548 KB |
n=500 |
34 |
Correct |
9 ms |
14548 KB |
n=500 |
35 |
Correct |
9 ms |
14644 KB |
n=500 |
36 |
Correct |
9 ms |
14556 KB |
n=500 |
37 |
Correct |
9 ms |
14528 KB |
n=500 |
38 |
Correct |
9 ms |
14612 KB |
n=500 |
39 |
Correct |
8 ms |
14676 KB |
n=500 |
40 |
Correct |
8 ms |
14564 KB |
n=500 |
41 |
Correct |
8 ms |
14548 KB |
n=500 |
42 |
Correct |
8 ms |
14676 KB |
n=500 |
43 |
Correct |
10 ms |
14548 KB |
n=500 |
44 |
Correct |
10 ms |
14624 KB |
n=500 |
45 |
Correct |
9 ms |
14536 KB |
n=500 |
46 |
Correct |
8 ms |
14556 KB |
n=500 |
47 |
Correct |
9 ms |
14568 KB |
n=500 |
48 |
Correct |
8 ms |
14548 KB |
n=500 |
49 |
Correct |
11 ms |
14548 KB |
n=500 |
50 |
Correct |
9 ms |
14596 KB |
n=500 |
51 |
Correct |
10 ms |
14548 KB |
n=500 |
52 |
Correct |
8 ms |
14596 KB |
n=500 |
53 |
Correct |
8 ms |
14560 KB |
n=500 |
54 |
Correct |
8 ms |
14548 KB |
n=500 |
55 |
Correct |
9 ms |
14476 KB |
n=278 |
56 |
Correct |
9 ms |
14532 KB |
n=500 |
57 |
Correct |
8 ms |
14548 KB |
n=500 |
58 |
Correct |
9 ms |
14548 KB |
n=500 |
59 |
Correct |
13 ms |
15188 KB |
n=2000 |
60 |
Correct |
11 ms |
15164 KB |
n=2000 |
61 |
Correct |
11 ms |
15188 KB |
n=2000 |
62 |
Correct |
11 ms |
15188 KB |
n=2000 |
63 |
Correct |
11 ms |
15188 KB |
n=2000 |
64 |
Correct |
12 ms |
15216 KB |
n=2000 |
65 |
Correct |
11 ms |
15188 KB |
n=2000 |
66 |
Correct |
12 ms |
15188 KB |
n=2000 |
67 |
Correct |
12 ms |
15188 KB |
n=2000 |
68 |
Correct |
10 ms |
15188 KB |
n=2000 |
69 |
Correct |
11 ms |
15160 KB |
n=2000 |
70 |
Correct |
11 ms |
15188 KB |
n=2000 |
71 |
Correct |
11 ms |
15188 KB |
n=2000 |
72 |
Correct |
10 ms |
15076 KB |
n=2000 |
73 |
Correct |
10 ms |
15188 KB |
n=2000 |
74 |
Correct |
14 ms |
15068 KB |
n=1844 |
75 |
Correct |
10 ms |
15188 KB |
n=2000 |
76 |
Correct |
12 ms |
15060 KB |
n=2000 |
77 |
Correct |
11 ms |
15076 KB |
n=2000 |
78 |
Correct |
12 ms |
15188 KB |
n=2000 |
79 |
Correct |
11 ms |
15188 KB |
n=2000 |
80 |
Correct |
12 ms |
15252 KB |
n=2000 |
81 |
Correct |
12 ms |
15200 KB |
n=2000 |
82 |
Correct |
11 ms |
15188 KB |
n=2000 |
83 |
Correct |
11 ms |
15196 KB |
n=2000 |
84 |
Correct |
11 ms |
15188 KB |
n=2000 |
85 |
Correct |
10 ms |
15188 KB |
n=2000 |
86 |
Correct |
13 ms |
15200 KB |
n=2000 |
87 |
Correct |
12 ms |
15172 KB |
n=2000 |
88 |
Correct |
11 ms |
15188 KB |
n=2000 |
89 |
Correct |
9 ms |
15188 KB |
n=2000 |
90 |
Correct |
10 ms |
15188 KB |
n=2000 |
91 |
Correct |
10 ms |
15188 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
n=5 |
2 |
Correct |
8 ms |
14344 KB |
n=100 |
3 |
Correct |
8 ms |
14420 KB |
n=100 |
4 |
Correct |
8 ms |
14420 KB |
n=100 |
5 |
Correct |
8 ms |
14420 KB |
n=100 |
6 |
Correct |
8 ms |
14420 KB |
n=100 |
7 |
Correct |
8 ms |
14420 KB |
n=100 |
8 |
Correct |
9 ms |
14416 KB |
n=100 |
9 |
Correct |
8 ms |
14448 KB |
n=100 |
10 |
Correct |
8 ms |
14420 KB |
n=100 |
11 |
Correct |
8 ms |
14420 KB |
n=100 |
12 |
Correct |
8 ms |
14416 KB |
n=100 |
13 |
Correct |
9 ms |
14416 KB |
n=100 |
14 |
Correct |
10 ms |
14416 KB |
n=100 |
15 |
Correct |
8 ms |
14460 KB |
n=100 |
16 |
Correct |
9 ms |
14420 KB |
n=100 |
17 |
Correct |
7 ms |
14420 KB |
n=100 |
18 |
Correct |
8 ms |
14420 KB |
n=100 |
19 |
Correct |
8 ms |
14420 KB |
n=100 |
20 |
Correct |
9 ms |
14420 KB |
n=100 |
21 |
Correct |
8 ms |
14420 KB |
n=100 |
22 |
Correct |
9 ms |
14440 KB |
n=100 |
23 |
Correct |
8 ms |
14420 KB |
n=100 |
24 |
Correct |
8 ms |
14424 KB |
n=100 |
25 |
Correct |
8 ms |
14420 KB |
n=100 |
26 |
Correct |
8 ms |
14420 KB |
n=12 |
27 |
Correct |
8 ms |
14424 KB |
n=100 |
28 |
Correct |
9 ms |
14556 KB |
n=500 |
29 |
Correct |
9 ms |
14548 KB |
n=500 |
30 |
Correct |
9 ms |
14548 KB |
n=500 |
31 |
Correct |
8 ms |
14568 KB |
n=500 |
32 |
Correct |
9 ms |
14548 KB |
n=500 |
33 |
Correct |
10 ms |
14548 KB |
n=500 |
34 |
Correct |
9 ms |
14548 KB |
n=500 |
35 |
Correct |
9 ms |
14644 KB |
n=500 |
36 |
Correct |
9 ms |
14556 KB |
n=500 |
37 |
Correct |
9 ms |
14528 KB |
n=500 |
38 |
Correct |
9 ms |
14612 KB |
n=500 |
39 |
Correct |
8 ms |
14676 KB |
n=500 |
40 |
Correct |
8 ms |
14564 KB |
n=500 |
41 |
Correct |
8 ms |
14548 KB |
n=500 |
42 |
Correct |
8 ms |
14676 KB |
n=500 |
43 |
Correct |
10 ms |
14548 KB |
n=500 |
44 |
Correct |
10 ms |
14624 KB |
n=500 |
45 |
Correct |
9 ms |
14536 KB |
n=500 |
46 |
Correct |
8 ms |
14556 KB |
n=500 |
47 |
Correct |
9 ms |
14568 KB |
n=500 |
48 |
Correct |
8 ms |
14548 KB |
n=500 |
49 |
Correct |
11 ms |
14548 KB |
n=500 |
50 |
Correct |
9 ms |
14596 KB |
n=500 |
51 |
Correct |
10 ms |
14548 KB |
n=500 |
52 |
Correct |
8 ms |
14596 KB |
n=500 |
53 |
Correct |
8 ms |
14560 KB |
n=500 |
54 |
Correct |
8 ms |
14548 KB |
n=500 |
55 |
Correct |
9 ms |
14476 KB |
n=278 |
56 |
Correct |
9 ms |
14532 KB |
n=500 |
57 |
Correct |
8 ms |
14548 KB |
n=500 |
58 |
Correct |
9 ms |
14548 KB |
n=500 |
59 |
Correct |
13 ms |
15188 KB |
n=2000 |
60 |
Correct |
11 ms |
15164 KB |
n=2000 |
61 |
Correct |
11 ms |
15188 KB |
n=2000 |
62 |
Correct |
11 ms |
15188 KB |
n=2000 |
63 |
Correct |
11 ms |
15188 KB |
n=2000 |
64 |
Correct |
12 ms |
15216 KB |
n=2000 |
65 |
Correct |
11 ms |
15188 KB |
n=2000 |
66 |
Correct |
12 ms |
15188 KB |
n=2000 |
67 |
Correct |
12 ms |
15188 KB |
n=2000 |
68 |
Correct |
10 ms |
15188 KB |
n=2000 |
69 |
Correct |
11 ms |
15160 KB |
n=2000 |
70 |
Correct |
11 ms |
15188 KB |
n=2000 |
71 |
Correct |
11 ms |
15188 KB |
n=2000 |
72 |
Correct |
10 ms |
15076 KB |
n=2000 |
73 |
Correct |
10 ms |
15188 KB |
n=2000 |
74 |
Correct |
14 ms |
15068 KB |
n=1844 |
75 |
Correct |
10 ms |
15188 KB |
n=2000 |
76 |
Correct |
12 ms |
15060 KB |
n=2000 |
77 |
Correct |
11 ms |
15076 KB |
n=2000 |
78 |
Correct |
12 ms |
15188 KB |
n=2000 |
79 |
Correct |
11 ms |
15188 KB |
n=2000 |
80 |
Correct |
12 ms |
15252 KB |
n=2000 |
81 |
Correct |
12 ms |
15200 KB |
n=2000 |
82 |
Correct |
11 ms |
15188 KB |
n=2000 |
83 |
Correct |
11 ms |
15196 KB |
n=2000 |
84 |
Correct |
11 ms |
15188 KB |
n=2000 |
85 |
Correct |
10 ms |
15188 KB |
n=2000 |
86 |
Correct |
13 ms |
15200 KB |
n=2000 |
87 |
Correct |
12 ms |
15172 KB |
n=2000 |
88 |
Correct |
11 ms |
15188 KB |
n=2000 |
89 |
Correct |
9 ms |
15188 KB |
n=2000 |
90 |
Correct |
10 ms |
15188 KB |
n=2000 |
91 |
Correct |
10 ms |
15188 KB |
n=2000 |
92 |
Correct |
807 ms |
86324 KB |
n=200000 |
93 |
Correct |
944 ms |
89912 KB |
n=200000 |
94 |
Correct |
755 ms |
92876 KB |
n=200000 |
95 |
Correct |
740 ms |
86244 KB |
n=200000 |
96 |
Correct |
726 ms |
86008 KB |
n=200000 |
97 |
Correct |
949 ms |
89080 KB |
n=200000 |
98 |
Correct |
759 ms |
85960 KB |
n=200000 |
99 |
Correct |
863 ms |
85636 KB |
n=200000 |
100 |
Correct |
745 ms |
86052 KB |
n=200000 |
101 |
Correct |
482 ms |
93732 KB |
n=200000 |
102 |
Correct |
431 ms |
87160 KB |
n=200000 |
103 |
Correct |
428 ms |
87156 KB |
n=200000 |
104 |
Correct |
434 ms |
87180 KB |
n=200000 |
105 |
Correct |
425 ms |
87056 KB |
n=200000 |
106 |
Correct |
419 ms |
86860 KB |
n=200000 |
107 |
Correct |
412 ms |
86768 KB |
n=200000 |
108 |
Correct |
785 ms |
85772 KB |
n=200000 |
109 |
Correct |
761 ms |
85872 KB |
n=200000 |
110 |
Correct |
782 ms |
85868 KB |
n=200000 |
111 |
Correct |
861 ms |
85804 KB |
n=200000 |
112 |
Correct |
543 ms |
92764 KB |
n=200000 |
113 |
Correct |
893 ms |
88872 KB |
n=200000 |
114 |
Correct |
737 ms |
85796 KB |
n=200000 |
115 |
Correct |
1104 ms |
86844 KB |
n=200000 |
116 |
Correct |
680 ms |
85776 KB |
n=200000 |
117 |
Correct |
529 ms |
93032 KB |
n=200000 |
118 |
Correct |
1022 ms |
87700 KB |
n=200000 |
119 |
Correct |
682 ms |
85528 KB |
n=200000 |
120 |
Correct |
437 ms |
93244 KB |
n=200000 |
121 |
Correct |
451 ms |
92856 KB |
n=200000 |
122 |
Correct |
454 ms |
93044 KB |
n=200000 |
123 |
Correct |
415 ms |
85844 KB |
n=200000 |
124 |
Correct |
158 ms |
33568 KB |
n=25264 |