///https://codeforces.com/group/Chft8wRRWW/contest/391796/problem/D
///https://oj.uz/problem/submit/IZhO18_treearray
#include<bits/stdc++.h>
#define task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 2e5 + 5;
const ll INF = 1e18 + 5;
const int LOGN = 18;
int n, m, q;
vector<int> Adj[MAXN];
int a[MAXN];
void Input()
{
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];
}
}
int P[MAXN][LOGN], dep[MAXN];
void DFS(int u, int par)
{
for (int v : Adj[u])
{
if (v == par)
{
continue;
}
dep[v] = dep[u] + 1;
P[v][0] = u;
DFS(v, u);
}
}
int LCA(int u, int v)
{
if (dep[u] > dep[v])
swap(u, v);
for (int i = LOGN - 1; i >= 0; i--)
{
if (dep[u] <= dep[P[v][i]])
{
v = P[v][i];
}
}
for (int i = LOGN - 1; i >= 0; i--)
{
if (P[u][i] != P[v][i])
{
u = P[u][i];
v = P[v][i];
}
}
if (u != v)
{
u = P[u][0];
}
return u;
}
set<int> S[MAXN], S1[MAXN];
void Solve()
{
dep[1] = 1;
DFS(1, 0);
for (int i = 1; i < LOGN; i++)
for (int j = 1; j <= n; j++)
P[j][i] = P[P[j][i - 1]][i - 1];
for (int i = 1; i <= m; i++)
{
S[a[i]].insert(i);
if (i < m)
S1[LCA(a[i], a[i + 1])].insert(i);
}
while (q-- > 0)
{
int t, l, r;
cin >> t >> l >> r;
if (t == 1)
{
S[a[l]].erase(l);
S[r].insert(l);
if (l < m)
{
S1[LCA(a[l], a[l + 1])].erase(l);
S1[LCA(r, a[l + 1])].insert(l);
}
if (l > 1)
{
S1[LCA(a[l - 1], a[l])].erase(l - 1);
S1[LCA(a[l - 1], r)].insert(l - 1);
}
a[l] = r;
} else
{
int k;
cin >> k;
auto it = S[k].lower_bound(l);
if (it != S[k].end() && *it <= r)
{
cout << *it << ' ' << *it << '\n';
} else
{
it = S1[k].lower_bound(l);
if (it != S1[k].end() && *it + 1 <= r)
{
cout << *it << ' ' << *it + 1 << '\n';
} else
cout << -1 << ' ' << -1 << '\n';
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(task".INP","r"))
{
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
Input();
Solve();
}
Compilation message
treearray.cpp: In function 'int main()':
treearray.cpp:143:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
143 | freopen(task".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
n=5 |
2 |
Correct |
13 ms |
23764 KB |
n=100 |
3 |
Correct |
11 ms |
23764 KB |
n=100 |
4 |
Correct |
12 ms |
23788 KB |
n=100 |
5 |
Correct |
11 ms |
23764 KB |
n=100 |
6 |
Correct |
11 ms |
23764 KB |
n=100 |
7 |
Correct |
11 ms |
23764 KB |
n=100 |
8 |
Correct |
13 ms |
23764 KB |
n=100 |
9 |
Correct |
13 ms |
23764 KB |
n=100 |
10 |
Correct |
13 ms |
23856 KB |
n=100 |
11 |
Correct |
13 ms |
23804 KB |
n=100 |
12 |
Correct |
12 ms |
23764 KB |
n=100 |
13 |
Correct |
11 ms |
23764 KB |
n=100 |
14 |
Correct |
11 ms |
23764 KB |
n=100 |
15 |
Correct |
11 ms |
23720 KB |
n=100 |
16 |
Correct |
11 ms |
23764 KB |
n=100 |
17 |
Correct |
12 ms |
23764 KB |
n=100 |
18 |
Correct |
11 ms |
23764 KB |
n=100 |
19 |
Correct |
13 ms |
23764 KB |
n=100 |
20 |
Correct |
14 ms |
23724 KB |
n=100 |
21 |
Correct |
11 ms |
23728 KB |
n=100 |
22 |
Correct |
12 ms |
23800 KB |
n=100 |
23 |
Correct |
11 ms |
23804 KB |
n=100 |
24 |
Correct |
11 ms |
23764 KB |
n=100 |
25 |
Correct |
11 ms |
23764 KB |
n=100 |
26 |
Correct |
11 ms |
23816 KB |
n=12 |
27 |
Correct |
13 ms |
23712 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
n=5 |
2 |
Correct |
13 ms |
23764 KB |
n=100 |
3 |
Correct |
11 ms |
23764 KB |
n=100 |
4 |
Correct |
12 ms |
23788 KB |
n=100 |
5 |
Correct |
11 ms |
23764 KB |
n=100 |
6 |
Correct |
11 ms |
23764 KB |
n=100 |
7 |
Correct |
11 ms |
23764 KB |
n=100 |
8 |
Correct |
13 ms |
23764 KB |
n=100 |
9 |
Correct |
13 ms |
23764 KB |
n=100 |
10 |
Correct |
13 ms |
23856 KB |
n=100 |
11 |
Correct |
13 ms |
23804 KB |
n=100 |
12 |
Correct |
12 ms |
23764 KB |
n=100 |
13 |
Correct |
11 ms |
23764 KB |
n=100 |
14 |
Correct |
11 ms |
23764 KB |
n=100 |
15 |
Correct |
11 ms |
23720 KB |
n=100 |
16 |
Correct |
11 ms |
23764 KB |
n=100 |
17 |
Correct |
12 ms |
23764 KB |
n=100 |
18 |
Correct |
11 ms |
23764 KB |
n=100 |
19 |
Correct |
13 ms |
23764 KB |
n=100 |
20 |
Correct |
14 ms |
23724 KB |
n=100 |
21 |
Correct |
11 ms |
23728 KB |
n=100 |
22 |
Correct |
12 ms |
23800 KB |
n=100 |
23 |
Correct |
11 ms |
23804 KB |
n=100 |
24 |
Correct |
11 ms |
23764 KB |
n=100 |
25 |
Correct |
11 ms |
23764 KB |
n=100 |
26 |
Correct |
11 ms |
23816 KB |
n=12 |
27 |
Correct |
13 ms |
23712 KB |
n=100 |
28 |
Correct |
14 ms |
23892 KB |
n=500 |
29 |
Correct |
12 ms |
23848 KB |
n=500 |
30 |
Correct |
12 ms |
23892 KB |
n=500 |
31 |
Correct |
14 ms |
23932 KB |
n=500 |
32 |
Correct |
12 ms |
23908 KB |
n=500 |
33 |
Correct |
12 ms |
23892 KB |
n=500 |
34 |
Correct |
13 ms |
23892 KB |
n=500 |
35 |
Correct |
12 ms |
23864 KB |
n=500 |
36 |
Correct |
11 ms |
23892 KB |
n=500 |
37 |
Correct |
12 ms |
23912 KB |
n=500 |
38 |
Correct |
11 ms |
23928 KB |
n=500 |
39 |
Correct |
12 ms |
23884 KB |
n=500 |
40 |
Correct |
14 ms |
23840 KB |
n=500 |
41 |
Correct |
13 ms |
23860 KB |
n=500 |
42 |
Correct |
12 ms |
23876 KB |
n=500 |
43 |
Correct |
12 ms |
23892 KB |
n=500 |
44 |
Correct |
12 ms |
23892 KB |
n=500 |
45 |
Correct |
12 ms |
23892 KB |
n=500 |
46 |
Correct |
12 ms |
23892 KB |
n=500 |
47 |
Correct |
12 ms |
23832 KB |
n=500 |
48 |
Correct |
14 ms |
23892 KB |
n=500 |
49 |
Correct |
12 ms |
23892 KB |
n=500 |
50 |
Correct |
13 ms |
23928 KB |
n=500 |
51 |
Correct |
12 ms |
23936 KB |
n=500 |
52 |
Correct |
12 ms |
24036 KB |
n=500 |
53 |
Correct |
13 ms |
23892 KB |
n=500 |
54 |
Correct |
12 ms |
23892 KB |
n=500 |
55 |
Correct |
11 ms |
23892 KB |
n=278 |
56 |
Correct |
12 ms |
23856 KB |
n=500 |
57 |
Correct |
14 ms |
23892 KB |
n=500 |
58 |
Correct |
12 ms |
23892 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
n=5 |
2 |
Correct |
13 ms |
23764 KB |
n=100 |
3 |
Correct |
11 ms |
23764 KB |
n=100 |
4 |
Correct |
12 ms |
23788 KB |
n=100 |
5 |
Correct |
11 ms |
23764 KB |
n=100 |
6 |
Correct |
11 ms |
23764 KB |
n=100 |
7 |
Correct |
11 ms |
23764 KB |
n=100 |
8 |
Correct |
13 ms |
23764 KB |
n=100 |
9 |
Correct |
13 ms |
23764 KB |
n=100 |
10 |
Correct |
13 ms |
23856 KB |
n=100 |
11 |
Correct |
13 ms |
23804 KB |
n=100 |
12 |
Correct |
12 ms |
23764 KB |
n=100 |
13 |
Correct |
11 ms |
23764 KB |
n=100 |
14 |
Correct |
11 ms |
23764 KB |
n=100 |
15 |
Correct |
11 ms |
23720 KB |
n=100 |
16 |
Correct |
11 ms |
23764 KB |
n=100 |
17 |
Correct |
12 ms |
23764 KB |
n=100 |
18 |
Correct |
11 ms |
23764 KB |
n=100 |
19 |
Correct |
13 ms |
23764 KB |
n=100 |
20 |
Correct |
14 ms |
23724 KB |
n=100 |
21 |
Correct |
11 ms |
23728 KB |
n=100 |
22 |
Correct |
12 ms |
23800 KB |
n=100 |
23 |
Correct |
11 ms |
23804 KB |
n=100 |
24 |
Correct |
11 ms |
23764 KB |
n=100 |
25 |
Correct |
11 ms |
23764 KB |
n=100 |
26 |
Correct |
11 ms |
23816 KB |
n=12 |
27 |
Correct |
13 ms |
23712 KB |
n=100 |
28 |
Correct |
14 ms |
23892 KB |
n=500 |
29 |
Correct |
12 ms |
23848 KB |
n=500 |
30 |
Correct |
12 ms |
23892 KB |
n=500 |
31 |
Correct |
14 ms |
23932 KB |
n=500 |
32 |
Correct |
12 ms |
23908 KB |
n=500 |
33 |
Correct |
12 ms |
23892 KB |
n=500 |
34 |
Correct |
13 ms |
23892 KB |
n=500 |
35 |
Correct |
12 ms |
23864 KB |
n=500 |
36 |
Correct |
11 ms |
23892 KB |
n=500 |
37 |
Correct |
12 ms |
23912 KB |
n=500 |
38 |
Correct |
11 ms |
23928 KB |
n=500 |
39 |
Correct |
12 ms |
23884 KB |
n=500 |
40 |
Correct |
14 ms |
23840 KB |
n=500 |
41 |
Correct |
13 ms |
23860 KB |
n=500 |
42 |
Correct |
12 ms |
23876 KB |
n=500 |
43 |
Correct |
12 ms |
23892 KB |
n=500 |
44 |
Correct |
12 ms |
23892 KB |
n=500 |
45 |
Correct |
12 ms |
23892 KB |
n=500 |
46 |
Correct |
12 ms |
23892 KB |
n=500 |
47 |
Correct |
12 ms |
23832 KB |
n=500 |
48 |
Correct |
14 ms |
23892 KB |
n=500 |
49 |
Correct |
12 ms |
23892 KB |
n=500 |
50 |
Correct |
13 ms |
23928 KB |
n=500 |
51 |
Correct |
12 ms |
23936 KB |
n=500 |
52 |
Correct |
12 ms |
24036 KB |
n=500 |
53 |
Correct |
13 ms |
23892 KB |
n=500 |
54 |
Correct |
12 ms |
23892 KB |
n=500 |
55 |
Correct |
11 ms |
23892 KB |
n=278 |
56 |
Correct |
12 ms |
23856 KB |
n=500 |
57 |
Correct |
14 ms |
23892 KB |
n=500 |
58 |
Correct |
12 ms |
23892 KB |
n=500 |
59 |
Correct |
17 ms |
24208 KB |
n=2000 |
60 |
Correct |
14 ms |
24304 KB |
n=2000 |
61 |
Correct |
15 ms |
24260 KB |
n=2000 |
62 |
Correct |
15 ms |
24148 KB |
n=2000 |
63 |
Correct |
15 ms |
24272 KB |
n=2000 |
64 |
Correct |
14 ms |
24276 KB |
n=2000 |
65 |
Correct |
19 ms |
24148 KB |
n=2000 |
66 |
Correct |
15 ms |
24248 KB |
n=2000 |
67 |
Correct |
14 ms |
24120 KB |
n=2000 |
68 |
Correct |
14 ms |
24288 KB |
n=2000 |
69 |
Correct |
13 ms |
24180 KB |
n=2000 |
70 |
Correct |
14 ms |
24196 KB |
n=2000 |
71 |
Correct |
13 ms |
24148 KB |
n=2000 |
72 |
Correct |
14 ms |
24208 KB |
n=2000 |
73 |
Correct |
14 ms |
24152 KB |
n=2000 |
74 |
Correct |
14 ms |
24148 KB |
n=1844 |
75 |
Correct |
13 ms |
24148 KB |
n=2000 |
76 |
Correct |
14 ms |
24148 KB |
n=2000 |
77 |
Correct |
15 ms |
24148 KB |
n=2000 |
78 |
Correct |
15 ms |
24148 KB |
n=2000 |
79 |
Correct |
15 ms |
24192 KB |
n=2000 |
80 |
Correct |
15 ms |
24404 KB |
n=2000 |
81 |
Correct |
15 ms |
24276 KB |
n=2000 |
82 |
Correct |
14 ms |
24200 KB |
n=2000 |
83 |
Correct |
14 ms |
24276 KB |
n=2000 |
84 |
Correct |
15 ms |
24200 KB |
n=2000 |
85 |
Correct |
16 ms |
24276 KB |
n=2000 |
86 |
Correct |
15 ms |
24148 KB |
n=2000 |
87 |
Correct |
15 ms |
24140 KB |
n=2000 |
88 |
Correct |
15 ms |
24296 KB |
n=2000 |
89 |
Correct |
14 ms |
24292 KB |
n=2000 |
90 |
Correct |
15 ms |
24320 KB |
n=2000 |
91 |
Correct |
13 ms |
24148 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
n=5 |
2 |
Correct |
13 ms |
23764 KB |
n=100 |
3 |
Correct |
11 ms |
23764 KB |
n=100 |
4 |
Correct |
12 ms |
23788 KB |
n=100 |
5 |
Correct |
11 ms |
23764 KB |
n=100 |
6 |
Correct |
11 ms |
23764 KB |
n=100 |
7 |
Correct |
11 ms |
23764 KB |
n=100 |
8 |
Correct |
13 ms |
23764 KB |
n=100 |
9 |
Correct |
13 ms |
23764 KB |
n=100 |
10 |
Correct |
13 ms |
23856 KB |
n=100 |
11 |
Correct |
13 ms |
23804 KB |
n=100 |
12 |
Correct |
12 ms |
23764 KB |
n=100 |
13 |
Correct |
11 ms |
23764 KB |
n=100 |
14 |
Correct |
11 ms |
23764 KB |
n=100 |
15 |
Correct |
11 ms |
23720 KB |
n=100 |
16 |
Correct |
11 ms |
23764 KB |
n=100 |
17 |
Correct |
12 ms |
23764 KB |
n=100 |
18 |
Correct |
11 ms |
23764 KB |
n=100 |
19 |
Correct |
13 ms |
23764 KB |
n=100 |
20 |
Correct |
14 ms |
23724 KB |
n=100 |
21 |
Correct |
11 ms |
23728 KB |
n=100 |
22 |
Correct |
12 ms |
23800 KB |
n=100 |
23 |
Correct |
11 ms |
23804 KB |
n=100 |
24 |
Correct |
11 ms |
23764 KB |
n=100 |
25 |
Correct |
11 ms |
23764 KB |
n=100 |
26 |
Correct |
11 ms |
23816 KB |
n=12 |
27 |
Correct |
13 ms |
23712 KB |
n=100 |
28 |
Correct |
14 ms |
23892 KB |
n=500 |
29 |
Correct |
12 ms |
23848 KB |
n=500 |
30 |
Correct |
12 ms |
23892 KB |
n=500 |
31 |
Correct |
14 ms |
23932 KB |
n=500 |
32 |
Correct |
12 ms |
23908 KB |
n=500 |
33 |
Correct |
12 ms |
23892 KB |
n=500 |
34 |
Correct |
13 ms |
23892 KB |
n=500 |
35 |
Correct |
12 ms |
23864 KB |
n=500 |
36 |
Correct |
11 ms |
23892 KB |
n=500 |
37 |
Correct |
12 ms |
23912 KB |
n=500 |
38 |
Correct |
11 ms |
23928 KB |
n=500 |
39 |
Correct |
12 ms |
23884 KB |
n=500 |
40 |
Correct |
14 ms |
23840 KB |
n=500 |
41 |
Correct |
13 ms |
23860 KB |
n=500 |
42 |
Correct |
12 ms |
23876 KB |
n=500 |
43 |
Correct |
12 ms |
23892 KB |
n=500 |
44 |
Correct |
12 ms |
23892 KB |
n=500 |
45 |
Correct |
12 ms |
23892 KB |
n=500 |
46 |
Correct |
12 ms |
23892 KB |
n=500 |
47 |
Correct |
12 ms |
23832 KB |
n=500 |
48 |
Correct |
14 ms |
23892 KB |
n=500 |
49 |
Correct |
12 ms |
23892 KB |
n=500 |
50 |
Correct |
13 ms |
23928 KB |
n=500 |
51 |
Correct |
12 ms |
23936 KB |
n=500 |
52 |
Correct |
12 ms |
24036 KB |
n=500 |
53 |
Correct |
13 ms |
23892 KB |
n=500 |
54 |
Correct |
12 ms |
23892 KB |
n=500 |
55 |
Correct |
11 ms |
23892 KB |
n=278 |
56 |
Correct |
12 ms |
23856 KB |
n=500 |
57 |
Correct |
14 ms |
23892 KB |
n=500 |
58 |
Correct |
12 ms |
23892 KB |
n=500 |
59 |
Correct |
17 ms |
24208 KB |
n=2000 |
60 |
Correct |
14 ms |
24304 KB |
n=2000 |
61 |
Correct |
15 ms |
24260 KB |
n=2000 |
62 |
Correct |
15 ms |
24148 KB |
n=2000 |
63 |
Correct |
15 ms |
24272 KB |
n=2000 |
64 |
Correct |
14 ms |
24276 KB |
n=2000 |
65 |
Correct |
19 ms |
24148 KB |
n=2000 |
66 |
Correct |
15 ms |
24248 KB |
n=2000 |
67 |
Correct |
14 ms |
24120 KB |
n=2000 |
68 |
Correct |
14 ms |
24288 KB |
n=2000 |
69 |
Correct |
13 ms |
24180 KB |
n=2000 |
70 |
Correct |
14 ms |
24196 KB |
n=2000 |
71 |
Correct |
13 ms |
24148 KB |
n=2000 |
72 |
Correct |
14 ms |
24208 KB |
n=2000 |
73 |
Correct |
14 ms |
24152 KB |
n=2000 |
74 |
Correct |
14 ms |
24148 KB |
n=1844 |
75 |
Correct |
13 ms |
24148 KB |
n=2000 |
76 |
Correct |
14 ms |
24148 KB |
n=2000 |
77 |
Correct |
15 ms |
24148 KB |
n=2000 |
78 |
Correct |
15 ms |
24148 KB |
n=2000 |
79 |
Correct |
15 ms |
24192 KB |
n=2000 |
80 |
Correct |
15 ms |
24404 KB |
n=2000 |
81 |
Correct |
15 ms |
24276 KB |
n=2000 |
82 |
Correct |
14 ms |
24200 KB |
n=2000 |
83 |
Correct |
14 ms |
24276 KB |
n=2000 |
84 |
Correct |
15 ms |
24200 KB |
n=2000 |
85 |
Correct |
16 ms |
24276 KB |
n=2000 |
86 |
Correct |
15 ms |
24148 KB |
n=2000 |
87 |
Correct |
15 ms |
24140 KB |
n=2000 |
88 |
Correct |
15 ms |
24296 KB |
n=2000 |
89 |
Correct |
14 ms |
24292 KB |
n=2000 |
90 |
Correct |
15 ms |
24320 KB |
n=2000 |
91 |
Correct |
13 ms |
24148 KB |
n=2000 |
92 |
Correct |
694 ms |
66568 KB |
n=200000 |
93 |
Correct |
1078 ms |
79380 KB |
n=200000 |
94 |
Correct |
1057 ms |
83820 KB |
n=200000 |
95 |
Correct |
730 ms |
72880 KB |
n=200000 |
96 |
Correct |
660 ms |
72792 KB |
n=200000 |
97 |
Correct |
1166 ms |
78440 KB |
n=200000 |
98 |
Correct |
724 ms |
72804 KB |
n=200000 |
99 |
Correct |
907 ms |
73112 KB |
n=200000 |
100 |
Correct |
709 ms |
72876 KB |
n=200000 |
101 |
Correct |
1058 ms |
85504 KB |
n=200000 |
102 |
Correct |
413 ms |
73956 KB |
n=200000 |
103 |
Correct |
462 ms |
73964 KB |
n=200000 |
104 |
Correct |
418 ms |
73976 KB |
n=200000 |
105 |
Correct |
426 ms |
74336 KB |
n=200000 |
106 |
Correct |
406 ms |
74364 KB |
n=200000 |
107 |
Correct |
431 ms |
74376 KB |
n=200000 |
108 |
Correct |
788 ms |
72780 KB |
n=200000 |
109 |
Correct |
825 ms |
72916 KB |
n=200000 |
110 |
Correct |
809 ms |
72800 KB |
n=200000 |
111 |
Correct |
692 ms |
72240 KB |
n=200000 |
112 |
Correct |
1012 ms |
84112 KB |
n=200000 |
113 |
Correct |
1131 ms |
78176 KB |
n=200000 |
114 |
Correct |
695 ms |
72256 KB |
n=200000 |
115 |
Correct |
1169 ms |
75376 KB |
n=200000 |
116 |
Correct |
648 ms |
73012 KB |
n=200000 |
117 |
Correct |
1120 ms |
84740 KB |
n=200000 |
118 |
Correct |
1259 ms |
76704 KB |
n=200000 |
119 |
Correct |
727 ms |
72920 KB |
n=200000 |
120 |
Correct |
1119 ms |
84540 KB |
n=200000 |
121 |
Correct |
1191 ms |
84520 KB |
n=200000 |
122 |
Correct |
1146 ms |
84916 KB |
n=200000 |
123 |
Correct |
584 ms |
74184 KB |
n=200000 |
124 |
Correct |
251 ms |
38756 KB |
n=25264 |