#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, m, q;
vector<int> adj[maxN];
int f[maxN][21];
int lg[maxN];
int depth[maxN];
int a[maxN];
set<int> s[maxN], s1[maxN];
void Log()
{
for(int i=2; i<maxN; i++) lg[i] = lg[i / 2] + 1;
}
void predfs(int u, int par)
{
for(int v : adj[u])
{
if(v == par) continue;
f[v][0] = u;
depth[v] = depth[u] + 1;
for(int i=1; i<=lg[n]; i++)
f[v][i] = f[f[v][i - 1]][i - 1];
predfs(v, u);
}
}
int LCA(int u, int v)
{
if(depth[u] < depth[v]) swap(u, v);
int k = depth[u] - depth[v];
for(int i=lg[n]; i>=0; i--)
{
if(k & (1 << i))
{
u = f[u][i];
k -= (1 << i);
}
}
if(u == v) return u;
for(int i=lg[n]; i>=0; i--)
{
if(f[u][i] != f[v][i])
{
u = f[u][i];
v = f[v][i];
}
}
return f[u][0];
}
void ReadInput()
{
cin >> n >> m >> q;
for(int i=1; i<n; i++)
{
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
for(int i=1; i<=m; i++) cin >> a[i];
}
void Solve()
{
predfs(1, 0);
for(int i=1; i<=m; i++)
{
// cout << LCA(a[i], a[i + 1]) << " ";
s[LCA(a[i], a[i + 1])].insert(i);
s1[a[i]].insert(i);
}
while(q--)
{
int type;
cin >> type;
if(type == 1)
{
int l, r;
cin >> l >> r;
s1[a[l]].erase(l);
s1[r].insert(l);
if(l < n)
{
s[LCA(a[l], a[l + 1])].erase(l);
s[LCA(r, a[l + 1])].insert(l);
}
if(l > 1)
{
s[LCA(a[l - 1], a[l])].erase(l - 1);
s[LCA(a[l - 1], r)].insert(l - 1);
}
a[l] = r;
}
else
{
int l, r, k;
cin >> l >> r >> k;
auto it = s1[k].lower_bound(l);
if(it != s1[k].end() && *it <= r)
{
cout << *it << " " << *it << '\n';
assert(*it >= l && *it <= r);
continue;
}
it = s[k].lower_bound(l);
if(it != s[k].end() && *it < r)
{
cout << *it << " " << *it + 1 << '\n';
assert(*it >= l && *it + 1 <= r);
continue;
}
cout << -1 << " " << -1 << '\n';
}
}
}
int32_t main()
{
// freopen("x.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
Log();
ReadInput();
Solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
125516 KB |
n=5 |
2 |
Correct |
58 ms |
125684 KB |
n=100 |
3 |
Correct |
59 ms |
125540 KB |
n=100 |
4 |
Correct |
55 ms |
125600 KB |
n=100 |
5 |
Correct |
57 ms |
125512 KB |
n=100 |
6 |
Correct |
55 ms |
125564 KB |
n=100 |
7 |
Correct |
56 ms |
125776 KB |
n=100 |
8 |
Correct |
55 ms |
125532 KB |
n=100 |
9 |
Correct |
56 ms |
125568 KB |
n=100 |
10 |
Correct |
55 ms |
125516 KB |
n=100 |
11 |
Correct |
56 ms |
125604 KB |
n=100 |
12 |
Correct |
56 ms |
125532 KB |
n=100 |
13 |
Correct |
57 ms |
125528 KB |
n=100 |
14 |
Correct |
56 ms |
125540 KB |
n=100 |
15 |
Correct |
56 ms |
125496 KB |
n=100 |
16 |
Correct |
65 ms |
125580 KB |
n=100 |
17 |
Correct |
56 ms |
125492 KB |
n=100 |
18 |
Correct |
55 ms |
125520 KB |
n=100 |
19 |
Correct |
56 ms |
125520 KB |
n=100 |
20 |
Correct |
59 ms |
125584 KB |
n=100 |
21 |
Correct |
56 ms |
125604 KB |
n=100 |
22 |
Correct |
56 ms |
125604 KB |
n=100 |
23 |
Correct |
63 ms |
125564 KB |
n=100 |
24 |
Correct |
57 ms |
125496 KB |
n=100 |
25 |
Correct |
55 ms |
125508 KB |
n=100 |
26 |
Correct |
55 ms |
125480 KB |
n=12 |
27 |
Correct |
55 ms |
125548 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
125516 KB |
n=5 |
2 |
Correct |
58 ms |
125684 KB |
n=100 |
3 |
Correct |
59 ms |
125540 KB |
n=100 |
4 |
Correct |
55 ms |
125600 KB |
n=100 |
5 |
Correct |
57 ms |
125512 KB |
n=100 |
6 |
Correct |
55 ms |
125564 KB |
n=100 |
7 |
Correct |
56 ms |
125776 KB |
n=100 |
8 |
Correct |
55 ms |
125532 KB |
n=100 |
9 |
Correct |
56 ms |
125568 KB |
n=100 |
10 |
Correct |
55 ms |
125516 KB |
n=100 |
11 |
Correct |
56 ms |
125604 KB |
n=100 |
12 |
Correct |
56 ms |
125532 KB |
n=100 |
13 |
Correct |
57 ms |
125528 KB |
n=100 |
14 |
Correct |
56 ms |
125540 KB |
n=100 |
15 |
Correct |
56 ms |
125496 KB |
n=100 |
16 |
Correct |
65 ms |
125580 KB |
n=100 |
17 |
Correct |
56 ms |
125492 KB |
n=100 |
18 |
Correct |
55 ms |
125520 KB |
n=100 |
19 |
Correct |
56 ms |
125520 KB |
n=100 |
20 |
Correct |
59 ms |
125584 KB |
n=100 |
21 |
Correct |
56 ms |
125604 KB |
n=100 |
22 |
Correct |
56 ms |
125604 KB |
n=100 |
23 |
Correct |
63 ms |
125564 KB |
n=100 |
24 |
Correct |
57 ms |
125496 KB |
n=100 |
25 |
Correct |
55 ms |
125508 KB |
n=100 |
26 |
Correct |
55 ms |
125480 KB |
n=12 |
27 |
Correct |
55 ms |
125548 KB |
n=100 |
28 |
Correct |
57 ms |
125736 KB |
n=500 |
29 |
Correct |
58 ms |
125768 KB |
n=500 |
30 |
Correct |
55 ms |
125696 KB |
n=500 |
31 |
Correct |
58 ms |
125756 KB |
n=500 |
32 |
Correct |
55 ms |
125708 KB |
n=500 |
33 |
Correct |
56 ms |
125648 KB |
n=500 |
34 |
Correct |
59 ms |
125636 KB |
n=500 |
35 |
Correct |
55 ms |
125644 KB |
n=500 |
36 |
Correct |
58 ms |
125644 KB |
n=500 |
37 |
Correct |
57 ms |
125820 KB |
n=500 |
38 |
Correct |
56 ms |
125644 KB |
n=500 |
39 |
Correct |
57 ms |
125744 KB |
n=500 |
40 |
Correct |
57 ms |
125716 KB |
n=500 |
41 |
Correct |
55 ms |
125632 KB |
n=500 |
42 |
Correct |
64 ms |
125644 KB |
n=500 |
43 |
Correct |
57 ms |
125700 KB |
n=500 |
44 |
Correct |
56 ms |
125628 KB |
n=500 |
45 |
Correct |
55 ms |
125652 KB |
n=500 |
46 |
Correct |
55 ms |
125664 KB |
n=500 |
47 |
Correct |
56 ms |
125664 KB |
n=500 |
48 |
Correct |
61 ms |
125744 KB |
n=500 |
49 |
Correct |
56 ms |
125660 KB |
n=500 |
50 |
Correct |
57 ms |
125648 KB |
n=500 |
51 |
Correct |
58 ms |
125640 KB |
n=500 |
52 |
Correct |
59 ms |
125724 KB |
n=500 |
53 |
Correct |
57 ms |
125700 KB |
n=500 |
54 |
Correct |
57 ms |
125700 KB |
n=500 |
55 |
Correct |
57 ms |
125644 KB |
n=278 |
56 |
Correct |
56 ms |
125644 KB |
n=500 |
57 |
Correct |
58 ms |
125648 KB |
n=500 |
58 |
Correct |
62 ms |
125728 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
125516 KB |
n=5 |
2 |
Correct |
58 ms |
125684 KB |
n=100 |
3 |
Correct |
59 ms |
125540 KB |
n=100 |
4 |
Correct |
55 ms |
125600 KB |
n=100 |
5 |
Correct |
57 ms |
125512 KB |
n=100 |
6 |
Correct |
55 ms |
125564 KB |
n=100 |
7 |
Correct |
56 ms |
125776 KB |
n=100 |
8 |
Correct |
55 ms |
125532 KB |
n=100 |
9 |
Correct |
56 ms |
125568 KB |
n=100 |
10 |
Correct |
55 ms |
125516 KB |
n=100 |
11 |
Correct |
56 ms |
125604 KB |
n=100 |
12 |
Correct |
56 ms |
125532 KB |
n=100 |
13 |
Correct |
57 ms |
125528 KB |
n=100 |
14 |
Correct |
56 ms |
125540 KB |
n=100 |
15 |
Correct |
56 ms |
125496 KB |
n=100 |
16 |
Correct |
65 ms |
125580 KB |
n=100 |
17 |
Correct |
56 ms |
125492 KB |
n=100 |
18 |
Correct |
55 ms |
125520 KB |
n=100 |
19 |
Correct |
56 ms |
125520 KB |
n=100 |
20 |
Correct |
59 ms |
125584 KB |
n=100 |
21 |
Correct |
56 ms |
125604 KB |
n=100 |
22 |
Correct |
56 ms |
125604 KB |
n=100 |
23 |
Correct |
63 ms |
125564 KB |
n=100 |
24 |
Correct |
57 ms |
125496 KB |
n=100 |
25 |
Correct |
55 ms |
125508 KB |
n=100 |
26 |
Correct |
55 ms |
125480 KB |
n=12 |
27 |
Correct |
55 ms |
125548 KB |
n=100 |
28 |
Correct |
57 ms |
125736 KB |
n=500 |
29 |
Correct |
58 ms |
125768 KB |
n=500 |
30 |
Correct |
55 ms |
125696 KB |
n=500 |
31 |
Correct |
58 ms |
125756 KB |
n=500 |
32 |
Correct |
55 ms |
125708 KB |
n=500 |
33 |
Correct |
56 ms |
125648 KB |
n=500 |
34 |
Correct |
59 ms |
125636 KB |
n=500 |
35 |
Correct |
55 ms |
125644 KB |
n=500 |
36 |
Correct |
58 ms |
125644 KB |
n=500 |
37 |
Correct |
57 ms |
125820 KB |
n=500 |
38 |
Correct |
56 ms |
125644 KB |
n=500 |
39 |
Correct |
57 ms |
125744 KB |
n=500 |
40 |
Correct |
57 ms |
125716 KB |
n=500 |
41 |
Correct |
55 ms |
125632 KB |
n=500 |
42 |
Correct |
64 ms |
125644 KB |
n=500 |
43 |
Correct |
57 ms |
125700 KB |
n=500 |
44 |
Correct |
56 ms |
125628 KB |
n=500 |
45 |
Correct |
55 ms |
125652 KB |
n=500 |
46 |
Correct |
55 ms |
125664 KB |
n=500 |
47 |
Correct |
56 ms |
125664 KB |
n=500 |
48 |
Correct |
61 ms |
125744 KB |
n=500 |
49 |
Correct |
56 ms |
125660 KB |
n=500 |
50 |
Correct |
57 ms |
125648 KB |
n=500 |
51 |
Correct |
58 ms |
125640 KB |
n=500 |
52 |
Correct |
59 ms |
125724 KB |
n=500 |
53 |
Correct |
57 ms |
125700 KB |
n=500 |
54 |
Correct |
57 ms |
125700 KB |
n=500 |
55 |
Correct |
57 ms |
125644 KB |
n=278 |
56 |
Correct |
56 ms |
125644 KB |
n=500 |
57 |
Correct |
58 ms |
125648 KB |
n=500 |
58 |
Correct |
62 ms |
125728 KB |
n=500 |
59 |
Correct |
59 ms |
126212 KB |
n=2000 |
60 |
Correct |
61 ms |
126324 KB |
n=2000 |
61 |
Correct |
58 ms |
126292 KB |
n=2000 |
62 |
Correct |
58 ms |
126232 KB |
n=2000 |
63 |
Correct |
59 ms |
126156 KB |
n=2000 |
64 |
Correct |
62 ms |
126212 KB |
n=2000 |
65 |
Correct |
59 ms |
126188 KB |
n=2000 |
66 |
Correct |
63 ms |
126284 KB |
n=2000 |
67 |
Correct |
59 ms |
126164 KB |
n=2000 |
68 |
Correct |
59 ms |
126220 KB |
n=2000 |
69 |
Correct |
61 ms |
126220 KB |
n=2000 |
70 |
Correct |
57 ms |
126196 KB |
n=2000 |
71 |
Correct |
60 ms |
126244 KB |
n=2000 |
72 |
Correct |
57 ms |
126156 KB |
n=2000 |
73 |
Correct |
59 ms |
126260 KB |
n=2000 |
74 |
Correct |
58 ms |
126148 KB |
n=1844 |
75 |
Correct |
58 ms |
126156 KB |
n=2000 |
76 |
Correct |
59 ms |
126236 KB |
n=2000 |
77 |
Correct |
62 ms |
126220 KB |
n=2000 |
78 |
Correct |
62 ms |
126156 KB |
n=2000 |
79 |
Correct |
64 ms |
126132 KB |
n=2000 |
80 |
Correct |
60 ms |
126348 KB |
n=2000 |
81 |
Correct |
59 ms |
126252 KB |
n=2000 |
82 |
Correct |
60 ms |
126172 KB |
n=2000 |
83 |
Correct |
61 ms |
126328 KB |
n=2000 |
84 |
Correct |
61 ms |
126212 KB |
n=2000 |
85 |
Correct |
61 ms |
126220 KB |
n=2000 |
86 |
Correct |
64 ms |
126284 KB |
n=2000 |
87 |
Correct |
61 ms |
126388 KB |
n=2000 |
88 |
Correct |
60 ms |
126368 KB |
n=2000 |
89 |
Correct |
60 ms |
126256 KB |
n=2000 |
90 |
Correct |
58 ms |
126284 KB |
n=2000 |
91 |
Correct |
56 ms |
126184 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
125516 KB |
n=5 |
2 |
Correct |
58 ms |
125684 KB |
n=100 |
3 |
Correct |
59 ms |
125540 KB |
n=100 |
4 |
Correct |
55 ms |
125600 KB |
n=100 |
5 |
Correct |
57 ms |
125512 KB |
n=100 |
6 |
Correct |
55 ms |
125564 KB |
n=100 |
7 |
Correct |
56 ms |
125776 KB |
n=100 |
8 |
Correct |
55 ms |
125532 KB |
n=100 |
9 |
Correct |
56 ms |
125568 KB |
n=100 |
10 |
Correct |
55 ms |
125516 KB |
n=100 |
11 |
Correct |
56 ms |
125604 KB |
n=100 |
12 |
Correct |
56 ms |
125532 KB |
n=100 |
13 |
Correct |
57 ms |
125528 KB |
n=100 |
14 |
Correct |
56 ms |
125540 KB |
n=100 |
15 |
Correct |
56 ms |
125496 KB |
n=100 |
16 |
Correct |
65 ms |
125580 KB |
n=100 |
17 |
Correct |
56 ms |
125492 KB |
n=100 |
18 |
Correct |
55 ms |
125520 KB |
n=100 |
19 |
Correct |
56 ms |
125520 KB |
n=100 |
20 |
Correct |
59 ms |
125584 KB |
n=100 |
21 |
Correct |
56 ms |
125604 KB |
n=100 |
22 |
Correct |
56 ms |
125604 KB |
n=100 |
23 |
Correct |
63 ms |
125564 KB |
n=100 |
24 |
Correct |
57 ms |
125496 KB |
n=100 |
25 |
Correct |
55 ms |
125508 KB |
n=100 |
26 |
Correct |
55 ms |
125480 KB |
n=12 |
27 |
Correct |
55 ms |
125548 KB |
n=100 |
28 |
Correct |
57 ms |
125736 KB |
n=500 |
29 |
Correct |
58 ms |
125768 KB |
n=500 |
30 |
Correct |
55 ms |
125696 KB |
n=500 |
31 |
Correct |
58 ms |
125756 KB |
n=500 |
32 |
Correct |
55 ms |
125708 KB |
n=500 |
33 |
Correct |
56 ms |
125648 KB |
n=500 |
34 |
Correct |
59 ms |
125636 KB |
n=500 |
35 |
Correct |
55 ms |
125644 KB |
n=500 |
36 |
Correct |
58 ms |
125644 KB |
n=500 |
37 |
Correct |
57 ms |
125820 KB |
n=500 |
38 |
Correct |
56 ms |
125644 KB |
n=500 |
39 |
Correct |
57 ms |
125744 KB |
n=500 |
40 |
Correct |
57 ms |
125716 KB |
n=500 |
41 |
Correct |
55 ms |
125632 KB |
n=500 |
42 |
Correct |
64 ms |
125644 KB |
n=500 |
43 |
Correct |
57 ms |
125700 KB |
n=500 |
44 |
Correct |
56 ms |
125628 KB |
n=500 |
45 |
Correct |
55 ms |
125652 KB |
n=500 |
46 |
Correct |
55 ms |
125664 KB |
n=500 |
47 |
Correct |
56 ms |
125664 KB |
n=500 |
48 |
Correct |
61 ms |
125744 KB |
n=500 |
49 |
Correct |
56 ms |
125660 KB |
n=500 |
50 |
Correct |
57 ms |
125648 KB |
n=500 |
51 |
Correct |
58 ms |
125640 KB |
n=500 |
52 |
Correct |
59 ms |
125724 KB |
n=500 |
53 |
Correct |
57 ms |
125700 KB |
n=500 |
54 |
Correct |
57 ms |
125700 KB |
n=500 |
55 |
Correct |
57 ms |
125644 KB |
n=278 |
56 |
Correct |
56 ms |
125644 KB |
n=500 |
57 |
Correct |
58 ms |
125648 KB |
n=500 |
58 |
Correct |
62 ms |
125728 KB |
n=500 |
59 |
Correct |
59 ms |
126212 KB |
n=2000 |
60 |
Correct |
61 ms |
126324 KB |
n=2000 |
61 |
Correct |
58 ms |
126292 KB |
n=2000 |
62 |
Correct |
58 ms |
126232 KB |
n=2000 |
63 |
Correct |
59 ms |
126156 KB |
n=2000 |
64 |
Correct |
62 ms |
126212 KB |
n=2000 |
65 |
Correct |
59 ms |
126188 KB |
n=2000 |
66 |
Correct |
63 ms |
126284 KB |
n=2000 |
67 |
Correct |
59 ms |
126164 KB |
n=2000 |
68 |
Correct |
59 ms |
126220 KB |
n=2000 |
69 |
Correct |
61 ms |
126220 KB |
n=2000 |
70 |
Correct |
57 ms |
126196 KB |
n=2000 |
71 |
Correct |
60 ms |
126244 KB |
n=2000 |
72 |
Correct |
57 ms |
126156 KB |
n=2000 |
73 |
Correct |
59 ms |
126260 KB |
n=2000 |
74 |
Correct |
58 ms |
126148 KB |
n=1844 |
75 |
Correct |
58 ms |
126156 KB |
n=2000 |
76 |
Correct |
59 ms |
126236 KB |
n=2000 |
77 |
Correct |
62 ms |
126220 KB |
n=2000 |
78 |
Correct |
62 ms |
126156 KB |
n=2000 |
79 |
Correct |
64 ms |
126132 KB |
n=2000 |
80 |
Correct |
60 ms |
126348 KB |
n=2000 |
81 |
Correct |
59 ms |
126252 KB |
n=2000 |
82 |
Correct |
60 ms |
126172 KB |
n=2000 |
83 |
Correct |
61 ms |
126328 KB |
n=2000 |
84 |
Correct |
61 ms |
126212 KB |
n=2000 |
85 |
Correct |
61 ms |
126220 KB |
n=2000 |
86 |
Correct |
64 ms |
126284 KB |
n=2000 |
87 |
Correct |
61 ms |
126388 KB |
n=2000 |
88 |
Correct |
60 ms |
126368 KB |
n=2000 |
89 |
Correct |
60 ms |
126256 KB |
n=2000 |
90 |
Correct |
58 ms |
126284 KB |
n=2000 |
91 |
Correct |
56 ms |
126184 KB |
n=2000 |
92 |
Correct |
761 ms |
189560 KB |
n=200000 |
93 |
Correct |
1119 ms |
194700 KB |
n=200000 |
94 |
Correct |
1124 ms |
198760 KB |
n=200000 |
95 |
Correct |
883 ms |
189248 KB |
n=200000 |
96 |
Correct |
727 ms |
189340 KB |
n=200000 |
97 |
Correct |
1241 ms |
193500 KB |
n=200000 |
98 |
Correct |
767 ms |
189336 KB |
n=200000 |
99 |
Correct |
971 ms |
188976 KB |
n=200000 |
100 |
Correct |
740 ms |
189300 KB |
n=200000 |
101 |
Correct |
1126 ms |
200112 KB |
n=200000 |
102 |
Correct |
500 ms |
190464 KB |
n=200000 |
103 |
Correct |
481 ms |
190412 KB |
n=200000 |
104 |
Correct |
509 ms |
190404 KB |
n=200000 |
105 |
Correct |
500 ms |
190108 KB |
n=200000 |
106 |
Correct |
508 ms |
190208 KB |
n=200000 |
107 |
Correct |
508 ms |
190256 KB |
n=200000 |
108 |
Correct |
920 ms |
189064 KB |
n=200000 |
109 |
Correct |
896 ms |
189156 KB |
n=200000 |
110 |
Correct |
841 ms |
189164 KB |
n=200000 |
111 |
Correct |
715 ms |
189208 KB |
n=200000 |
112 |
Correct |
1076 ms |
198924 KB |
n=200000 |
113 |
Correct |
1187 ms |
193500 KB |
n=200000 |
114 |
Correct |
849 ms |
189116 KB |
n=200000 |
115 |
Correct |
1337 ms |
190848 KB |
n=200000 |
116 |
Correct |
751 ms |
189048 KB |
n=200000 |
117 |
Correct |
1145 ms |
199356 KB |
n=200000 |
118 |
Correct |
1307 ms |
192000 KB |
n=200000 |
119 |
Correct |
777 ms |
188936 KB |
n=200000 |
120 |
Correct |
1072 ms |
199672 KB |
n=200000 |
121 |
Correct |
993 ms |
199836 KB |
n=200000 |
122 |
Correct |
1004 ms |
200216 KB |
n=200000 |
123 |
Correct |
536 ms |
189852 KB |
n=200000 |
124 |
Incorrect |
267 ms |
141692 KB |
Wrong range. |
125 |
Halted |
0 ms |
0 KB |
- |