#include <bits/stdc++.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define N 200010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mod 1000000007
#define pii pair <int, int>
#define sz(a) int(a.size())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
ll bigmod(ll a,ll e) {if(e==0)return 1;ll x=bigmod(a*a%mod,e>>1);return e&1?x*a%mod:x;}
set <pii> S[N];
int n, m, q, a, b;
vector <int> E[N];
int L[N], Pr[N][30], v[N];
void dfs(int nd, int pr)
{
L[nd] = L[pr] + 1;
Pr[nd][0] = pr;
for(auto i: E[nd]) if(i != pr) dfs(i, nd);
}
int lca(int a, int b)
{
if(L[a] < L[b]) swap(a, b);
for(int i = 20; i >= 0; i--)
if(L[a] - (1<<i) >= L[b])
a = Pr[a][i];
if(a == b) return a;
for(int i = 20; i >= 0; i--)
if(Pr[a][i] != Pr[b][i])
a = Pr[a][i], b = Pr[b][i];
return Pr[a][0];
}
int main()
{
cin >> n >> m >> q;
for(int i = 1; i < n; i++) {
cin >> a >> b;
E[a].pb(b);
E[b].pb(a);
}
dfs(1, 0);
for(int i = 1; (1<<i) <= n; i++)
for(int h = 1; h <= n; h++)
Pr[h][i] = Pr[Pr[h][i-1]][i-1];
for(int i = 1; i <= m; i++) cin >> v[i];
for(int i = 1; i < m; i++) S[lca(v[i], v[i+1])].insert({i, 1});
for(int i = 1; i <= m; i++) S[v[i]].insert({i, 0});
while(q--) {
int tp;
cin >> tp;
if(tp == 1) {
int pos, x;
cin >> pos >> x;
if(pos != 1) {
int Lca = lca(v[pos-1], v[pos]);
S[Lca].erase({pos-1, 1});
Lca = lca(v[pos-1], x);
S[Lca].insert({pos-1, 1});
}
if(pos != n) {
int Lca = lca(v[pos+1], v[pos]);
S[Lca].erase({pos, 1});
Lca = lca(v[pos+1], x);
S[Lca].insert({pos, 1});
}
S[v[pos]].erase({pos, 0});
v[pos] = x;
S[v[pos]].insert({pos, 0});
} else {
int l, r, x;
cin >> l >> r >> x;
pii in = *S[x].lower_bound({l, 0});
if(in.ff+in.ss <= r && in.ff >= l) cout << in.ff << " " << in.ff+in.ss << "\n";
else cout << "-1 -1\n";
}
}
}
Compilation message
treearray.cpp:23: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
23 | #pragma GCC optimization ("O3")
|
treearray.cpp:24: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
24 | #pragma GCC optimization ("unroll-loops")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14464 KB |
n=5 |
2 |
Correct |
10 ms |
14496 KB |
n=100 |
3 |
Correct |
11 ms |
14592 KB |
n=100 |
4 |
Correct |
11 ms |
14464 KB |
n=100 |
5 |
Correct |
10 ms |
14464 KB |
n=100 |
6 |
Correct |
11 ms |
14464 KB |
n=100 |
7 |
Correct |
10 ms |
14464 KB |
n=100 |
8 |
Correct |
10 ms |
14464 KB |
n=100 |
9 |
Correct |
10 ms |
14464 KB |
n=100 |
10 |
Correct |
11 ms |
14464 KB |
n=100 |
11 |
Correct |
10 ms |
14464 KB |
n=100 |
12 |
Correct |
11 ms |
14464 KB |
n=100 |
13 |
Correct |
11 ms |
14464 KB |
n=100 |
14 |
Correct |
10 ms |
14464 KB |
n=100 |
15 |
Correct |
10 ms |
14464 KB |
n=100 |
16 |
Correct |
11 ms |
14592 KB |
n=100 |
17 |
Correct |
10 ms |
14464 KB |
n=100 |
18 |
Correct |
12 ms |
14464 KB |
n=100 |
19 |
Correct |
10 ms |
14464 KB |
n=100 |
20 |
Correct |
11 ms |
14464 KB |
n=100 |
21 |
Correct |
10 ms |
14464 KB |
n=100 |
22 |
Correct |
10 ms |
14464 KB |
n=100 |
23 |
Correct |
10 ms |
14464 KB |
n=100 |
24 |
Correct |
10 ms |
14464 KB |
n=100 |
25 |
Correct |
10 ms |
14464 KB |
n=100 |
26 |
Correct |
10 ms |
14464 KB |
n=12 |
27 |
Correct |
10 ms |
14464 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14464 KB |
n=5 |
2 |
Correct |
10 ms |
14496 KB |
n=100 |
3 |
Correct |
11 ms |
14592 KB |
n=100 |
4 |
Correct |
11 ms |
14464 KB |
n=100 |
5 |
Correct |
10 ms |
14464 KB |
n=100 |
6 |
Correct |
11 ms |
14464 KB |
n=100 |
7 |
Correct |
10 ms |
14464 KB |
n=100 |
8 |
Correct |
10 ms |
14464 KB |
n=100 |
9 |
Correct |
10 ms |
14464 KB |
n=100 |
10 |
Correct |
11 ms |
14464 KB |
n=100 |
11 |
Correct |
10 ms |
14464 KB |
n=100 |
12 |
Correct |
11 ms |
14464 KB |
n=100 |
13 |
Correct |
11 ms |
14464 KB |
n=100 |
14 |
Correct |
10 ms |
14464 KB |
n=100 |
15 |
Correct |
10 ms |
14464 KB |
n=100 |
16 |
Correct |
11 ms |
14592 KB |
n=100 |
17 |
Correct |
10 ms |
14464 KB |
n=100 |
18 |
Correct |
12 ms |
14464 KB |
n=100 |
19 |
Correct |
10 ms |
14464 KB |
n=100 |
20 |
Correct |
11 ms |
14464 KB |
n=100 |
21 |
Correct |
10 ms |
14464 KB |
n=100 |
22 |
Correct |
10 ms |
14464 KB |
n=100 |
23 |
Correct |
10 ms |
14464 KB |
n=100 |
24 |
Correct |
10 ms |
14464 KB |
n=100 |
25 |
Correct |
10 ms |
14464 KB |
n=100 |
26 |
Correct |
10 ms |
14464 KB |
n=12 |
27 |
Correct |
10 ms |
14464 KB |
n=100 |
28 |
Correct |
13 ms |
14592 KB |
n=500 |
29 |
Correct |
12 ms |
14592 KB |
n=500 |
30 |
Correct |
12 ms |
14592 KB |
n=500 |
31 |
Correct |
14 ms |
14592 KB |
n=500 |
32 |
Correct |
15 ms |
14592 KB |
n=500 |
33 |
Correct |
12 ms |
14592 KB |
n=500 |
34 |
Correct |
12 ms |
14592 KB |
n=500 |
35 |
Correct |
12 ms |
14592 KB |
n=500 |
36 |
Correct |
12 ms |
14592 KB |
n=500 |
37 |
Correct |
14 ms |
14592 KB |
n=500 |
38 |
Correct |
13 ms |
14496 KB |
n=500 |
39 |
Correct |
13 ms |
14592 KB |
n=500 |
40 |
Correct |
13 ms |
14592 KB |
n=500 |
41 |
Correct |
13 ms |
14592 KB |
n=500 |
42 |
Correct |
12 ms |
14592 KB |
n=500 |
43 |
Correct |
12 ms |
14592 KB |
n=500 |
44 |
Correct |
13 ms |
14592 KB |
n=500 |
45 |
Correct |
13 ms |
14592 KB |
n=500 |
46 |
Correct |
12 ms |
14592 KB |
n=500 |
47 |
Correct |
13 ms |
14592 KB |
n=500 |
48 |
Correct |
12 ms |
14592 KB |
n=500 |
49 |
Correct |
13 ms |
14592 KB |
n=500 |
50 |
Correct |
12 ms |
14592 KB |
n=500 |
51 |
Correct |
13 ms |
14592 KB |
n=500 |
52 |
Correct |
13 ms |
14592 KB |
n=500 |
53 |
Correct |
12 ms |
14592 KB |
n=500 |
54 |
Correct |
12 ms |
14592 KB |
n=500 |
55 |
Correct |
11 ms |
14464 KB |
n=278 |
56 |
Correct |
12 ms |
14592 KB |
n=500 |
57 |
Correct |
12 ms |
14592 KB |
n=500 |
58 |
Correct |
13 ms |
14592 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14464 KB |
n=5 |
2 |
Correct |
10 ms |
14496 KB |
n=100 |
3 |
Correct |
11 ms |
14592 KB |
n=100 |
4 |
Correct |
11 ms |
14464 KB |
n=100 |
5 |
Correct |
10 ms |
14464 KB |
n=100 |
6 |
Correct |
11 ms |
14464 KB |
n=100 |
7 |
Correct |
10 ms |
14464 KB |
n=100 |
8 |
Correct |
10 ms |
14464 KB |
n=100 |
9 |
Correct |
10 ms |
14464 KB |
n=100 |
10 |
Correct |
11 ms |
14464 KB |
n=100 |
11 |
Correct |
10 ms |
14464 KB |
n=100 |
12 |
Correct |
11 ms |
14464 KB |
n=100 |
13 |
Correct |
11 ms |
14464 KB |
n=100 |
14 |
Correct |
10 ms |
14464 KB |
n=100 |
15 |
Correct |
10 ms |
14464 KB |
n=100 |
16 |
Correct |
11 ms |
14592 KB |
n=100 |
17 |
Correct |
10 ms |
14464 KB |
n=100 |
18 |
Correct |
12 ms |
14464 KB |
n=100 |
19 |
Correct |
10 ms |
14464 KB |
n=100 |
20 |
Correct |
11 ms |
14464 KB |
n=100 |
21 |
Correct |
10 ms |
14464 KB |
n=100 |
22 |
Correct |
10 ms |
14464 KB |
n=100 |
23 |
Correct |
10 ms |
14464 KB |
n=100 |
24 |
Correct |
10 ms |
14464 KB |
n=100 |
25 |
Correct |
10 ms |
14464 KB |
n=100 |
26 |
Correct |
10 ms |
14464 KB |
n=12 |
27 |
Correct |
10 ms |
14464 KB |
n=100 |
28 |
Correct |
13 ms |
14592 KB |
n=500 |
29 |
Correct |
12 ms |
14592 KB |
n=500 |
30 |
Correct |
12 ms |
14592 KB |
n=500 |
31 |
Correct |
14 ms |
14592 KB |
n=500 |
32 |
Correct |
15 ms |
14592 KB |
n=500 |
33 |
Correct |
12 ms |
14592 KB |
n=500 |
34 |
Correct |
12 ms |
14592 KB |
n=500 |
35 |
Correct |
12 ms |
14592 KB |
n=500 |
36 |
Correct |
12 ms |
14592 KB |
n=500 |
37 |
Correct |
14 ms |
14592 KB |
n=500 |
38 |
Correct |
13 ms |
14496 KB |
n=500 |
39 |
Correct |
13 ms |
14592 KB |
n=500 |
40 |
Correct |
13 ms |
14592 KB |
n=500 |
41 |
Correct |
13 ms |
14592 KB |
n=500 |
42 |
Correct |
12 ms |
14592 KB |
n=500 |
43 |
Correct |
12 ms |
14592 KB |
n=500 |
44 |
Correct |
13 ms |
14592 KB |
n=500 |
45 |
Correct |
13 ms |
14592 KB |
n=500 |
46 |
Correct |
12 ms |
14592 KB |
n=500 |
47 |
Correct |
13 ms |
14592 KB |
n=500 |
48 |
Correct |
12 ms |
14592 KB |
n=500 |
49 |
Correct |
13 ms |
14592 KB |
n=500 |
50 |
Correct |
12 ms |
14592 KB |
n=500 |
51 |
Correct |
13 ms |
14592 KB |
n=500 |
52 |
Correct |
13 ms |
14592 KB |
n=500 |
53 |
Correct |
12 ms |
14592 KB |
n=500 |
54 |
Correct |
12 ms |
14592 KB |
n=500 |
55 |
Correct |
11 ms |
14464 KB |
n=278 |
56 |
Correct |
12 ms |
14592 KB |
n=500 |
57 |
Correct |
12 ms |
14592 KB |
n=500 |
58 |
Correct |
13 ms |
14592 KB |
n=500 |
59 |
Correct |
20 ms |
14976 KB |
n=2000 |
60 |
Correct |
20 ms |
15104 KB |
n=2000 |
61 |
Correct |
22 ms |
15104 KB |
n=2000 |
62 |
Correct |
21 ms |
14976 KB |
n=2000 |
63 |
Correct |
20 ms |
14976 KB |
n=2000 |
64 |
Correct |
21 ms |
15008 KB |
n=2000 |
65 |
Correct |
21 ms |
14976 KB |
n=2000 |
66 |
Correct |
21 ms |
15104 KB |
n=2000 |
67 |
Correct |
21 ms |
14976 KB |
n=2000 |
68 |
Correct |
21 ms |
14976 KB |
n=2000 |
69 |
Correct |
21 ms |
14976 KB |
n=2000 |
70 |
Correct |
23 ms |
14976 KB |
n=2000 |
71 |
Correct |
21 ms |
14968 KB |
n=2000 |
72 |
Correct |
21 ms |
14976 KB |
n=2000 |
73 |
Correct |
21 ms |
14976 KB |
n=2000 |
74 |
Correct |
19 ms |
14976 KB |
n=1844 |
75 |
Correct |
22 ms |
15104 KB |
n=2000 |
76 |
Correct |
21 ms |
14976 KB |
n=2000 |
77 |
Correct |
20 ms |
14976 KB |
n=2000 |
78 |
Correct |
21 ms |
14976 KB |
n=2000 |
79 |
Correct |
20 ms |
14976 KB |
n=2000 |
80 |
Correct |
21 ms |
15104 KB |
n=2000 |
81 |
Correct |
21 ms |
14976 KB |
n=2000 |
82 |
Correct |
20 ms |
14976 KB |
n=2000 |
83 |
Correct |
21 ms |
15104 KB |
n=2000 |
84 |
Correct |
20 ms |
14976 KB |
n=2000 |
85 |
Correct |
21 ms |
14976 KB |
n=2000 |
86 |
Correct |
21 ms |
14976 KB |
n=2000 |
87 |
Correct |
20 ms |
14976 KB |
n=2000 |
88 |
Correct |
20 ms |
15104 KB |
n=2000 |
89 |
Correct |
20 ms |
15104 KB |
n=2000 |
90 |
Correct |
20 ms |
15104 KB |
n=2000 |
91 |
Correct |
22 ms |
14976 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14464 KB |
n=5 |
2 |
Correct |
10 ms |
14496 KB |
n=100 |
3 |
Correct |
11 ms |
14592 KB |
n=100 |
4 |
Correct |
11 ms |
14464 KB |
n=100 |
5 |
Correct |
10 ms |
14464 KB |
n=100 |
6 |
Correct |
11 ms |
14464 KB |
n=100 |
7 |
Correct |
10 ms |
14464 KB |
n=100 |
8 |
Correct |
10 ms |
14464 KB |
n=100 |
9 |
Correct |
10 ms |
14464 KB |
n=100 |
10 |
Correct |
11 ms |
14464 KB |
n=100 |
11 |
Correct |
10 ms |
14464 KB |
n=100 |
12 |
Correct |
11 ms |
14464 KB |
n=100 |
13 |
Correct |
11 ms |
14464 KB |
n=100 |
14 |
Correct |
10 ms |
14464 KB |
n=100 |
15 |
Correct |
10 ms |
14464 KB |
n=100 |
16 |
Correct |
11 ms |
14592 KB |
n=100 |
17 |
Correct |
10 ms |
14464 KB |
n=100 |
18 |
Correct |
12 ms |
14464 KB |
n=100 |
19 |
Correct |
10 ms |
14464 KB |
n=100 |
20 |
Correct |
11 ms |
14464 KB |
n=100 |
21 |
Correct |
10 ms |
14464 KB |
n=100 |
22 |
Correct |
10 ms |
14464 KB |
n=100 |
23 |
Correct |
10 ms |
14464 KB |
n=100 |
24 |
Correct |
10 ms |
14464 KB |
n=100 |
25 |
Correct |
10 ms |
14464 KB |
n=100 |
26 |
Correct |
10 ms |
14464 KB |
n=12 |
27 |
Correct |
10 ms |
14464 KB |
n=100 |
28 |
Correct |
13 ms |
14592 KB |
n=500 |
29 |
Correct |
12 ms |
14592 KB |
n=500 |
30 |
Correct |
12 ms |
14592 KB |
n=500 |
31 |
Correct |
14 ms |
14592 KB |
n=500 |
32 |
Correct |
15 ms |
14592 KB |
n=500 |
33 |
Correct |
12 ms |
14592 KB |
n=500 |
34 |
Correct |
12 ms |
14592 KB |
n=500 |
35 |
Correct |
12 ms |
14592 KB |
n=500 |
36 |
Correct |
12 ms |
14592 KB |
n=500 |
37 |
Correct |
14 ms |
14592 KB |
n=500 |
38 |
Correct |
13 ms |
14496 KB |
n=500 |
39 |
Correct |
13 ms |
14592 KB |
n=500 |
40 |
Correct |
13 ms |
14592 KB |
n=500 |
41 |
Correct |
13 ms |
14592 KB |
n=500 |
42 |
Correct |
12 ms |
14592 KB |
n=500 |
43 |
Correct |
12 ms |
14592 KB |
n=500 |
44 |
Correct |
13 ms |
14592 KB |
n=500 |
45 |
Correct |
13 ms |
14592 KB |
n=500 |
46 |
Correct |
12 ms |
14592 KB |
n=500 |
47 |
Correct |
13 ms |
14592 KB |
n=500 |
48 |
Correct |
12 ms |
14592 KB |
n=500 |
49 |
Correct |
13 ms |
14592 KB |
n=500 |
50 |
Correct |
12 ms |
14592 KB |
n=500 |
51 |
Correct |
13 ms |
14592 KB |
n=500 |
52 |
Correct |
13 ms |
14592 KB |
n=500 |
53 |
Correct |
12 ms |
14592 KB |
n=500 |
54 |
Correct |
12 ms |
14592 KB |
n=500 |
55 |
Correct |
11 ms |
14464 KB |
n=278 |
56 |
Correct |
12 ms |
14592 KB |
n=500 |
57 |
Correct |
12 ms |
14592 KB |
n=500 |
58 |
Correct |
13 ms |
14592 KB |
n=500 |
59 |
Correct |
20 ms |
14976 KB |
n=2000 |
60 |
Correct |
20 ms |
15104 KB |
n=2000 |
61 |
Correct |
22 ms |
15104 KB |
n=2000 |
62 |
Correct |
21 ms |
14976 KB |
n=2000 |
63 |
Correct |
20 ms |
14976 KB |
n=2000 |
64 |
Correct |
21 ms |
15008 KB |
n=2000 |
65 |
Correct |
21 ms |
14976 KB |
n=2000 |
66 |
Correct |
21 ms |
15104 KB |
n=2000 |
67 |
Correct |
21 ms |
14976 KB |
n=2000 |
68 |
Correct |
21 ms |
14976 KB |
n=2000 |
69 |
Correct |
21 ms |
14976 KB |
n=2000 |
70 |
Correct |
23 ms |
14976 KB |
n=2000 |
71 |
Correct |
21 ms |
14968 KB |
n=2000 |
72 |
Correct |
21 ms |
14976 KB |
n=2000 |
73 |
Correct |
21 ms |
14976 KB |
n=2000 |
74 |
Correct |
19 ms |
14976 KB |
n=1844 |
75 |
Correct |
22 ms |
15104 KB |
n=2000 |
76 |
Correct |
21 ms |
14976 KB |
n=2000 |
77 |
Correct |
20 ms |
14976 KB |
n=2000 |
78 |
Correct |
21 ms |
14976 KB |
n=2000 |
79 |
Correct |
20 ms |
14976 KB |
n=2000 |
80 |
Correct |
21 ms |
15104 KB |
n=2000 |
81 |
Correct |
21 ms |
14976 KB |
n=2000 |
82 |
Correct |
20 ms |
14976 KB |
n=2000 |
83 |
Correct |
21 ms |
15104 KB |
n=2000 |
84 |
Correct |
20 ms |
14976 KB |
n=2000 |
85 |
Correct |
21 ms |
14976 KB |
n=2000 |
86 |
Correct |
21 ms |
14976 KB |
n=2000 |
87 |
Correct |
20 ms |
14976 KB |
n=2000 |
88 |
Correct |
20 ms |
15104 KB |
n=2000 |
89 |
Correct |
20 ms |
15104 KB |
n=2000 |
90 |
Correct |
20 ms |
15104 KB |
n=2000 |
91 |
Correct |
22 ms |
14976 KB |
n=2000 |
92 |
Correct |
1617 ms |
73280 KB |
n=200000 |
93 |
Correct |
2120 ms |
77900 KB |
n=200000 |
94 |
Correct |
2050 ms |
81372 KB |
n=200000 |
95 |
Correct |
1580 ms |
72812 KB |
n=200000 |
96 |
Correct |
1621 ms |
72940 KB |
n=200000 |
97 |
Correct |
2130 ms |
77036 KB |
n=200000 |
98 |
Correct |
1599 ms |
72812 KB |
n=200000 |
99 |
Correct |
1914 ms |
73000 KB |
n=200000 |
100 |
Correct |
1600 ms |
72848 KB |
n=200000 |
101 |
Correct |
2066 ms |
82488 KB |
n=200000 |
102 |
Correct |
1490 ms |
74068 KB |
n=200000 |
103 |
Correct |
1491 ms |
74104 KB |
n=200000 |
104 |
Correct |
1478 ms |
73980 KB |
n=200000 |
105 |
Correct |
1527 ms |
74488 KB |
n=200000 |
106 |
Correct |
1532 ms |
74436 KB |
n=200000 |
107 |
Correct |
1528 ms |
74520 KB |
n=200000 |
108 |
Correct |
1743 ms |
72848 KB |
n=200000 |
109 |
Correct |
1768 ms |
73000 KB |
n=200000 |
110 |
Correct |
1749 ms |
72904 KB |
n=200000 |
111 |
Correct |
1609 ms |
72428 KB |
n=200000 |
112 |
Correct |
2017 ms |
81528 KB |
n=200000 |
113 |
Correct |
2074 ms |
76920 KB |
n=200000 |
114 |
Correct |
1611 ms |
72428 KB |
n=200000 |
115 |
Correct |
2237 ms |
75000 KB |
n=200000 |
116 |
Correct |
1547 ms |
73068 KB |
n=200000 |
117 |
Correct |
2003 ms |
81920 KB |
n=200000 |
118 |
Correct |
2091 ms |
75768 KB |
n=200000 |
119 |
Correct |
1551 ms |
73164 KB |
n=200000 |
120 |
Correct |
1931 ms |
81568 KB |
n=200000 |
121 |
Correct |
1964 ms |
81672 KB |
n=200000 |
122 |
Correct |
1941 ms |
82092 KB |
n=200000 |
123 |
Correct |
1560 ms |
74488 KB |
n=200000 |
124 |
Correct |
504 ms |
30456 KB |
n=25264 |