//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
#define Log2(x) 31 - __builtin_clz(x)
using namespace std;
const int N = 2e5, cbit = 17;
int f[N + 1][cbit + 1], depth[N + 1];
vector<int> adj[N + 1];
set<int> single[N + 1], dual[N + 1];
int n, m, q, a[N + 1];
void read()
{
cin >> n >> m >> q;
for (int i = 1; i < n; ++ i)
{
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
}
void DFS(int u, int p)
{
for (int v : adj[u])
{
if (v == p)
{
continue;
}
depth[v] = depth[u] + 1;
f[v][0] = u;
for (int i = 1; i <= cbit; ++ i)
{
f[v][i] = f[f[v][i - 1]][i - 1];
}
DFS(v, u);
}
}
int LCA(int u, int v)
{
if (depth[v] < depth[u])
{
swap(u, v);
}
int k = depth[v] - depth[u];
for (int i = cbit; i >= 0; -- i)
{
if ((k >> i) & 1)
{
v = f[v][i];
}
}
if (u == v)
{
return u;
}
for (int i = cbit; i >= 0; -- i)
{
if (f[u][i] != f[v][i])
{
u = f[u][i];
v = f[v][i];
}
}
return f[u][0];
}
void solve()
{
DFS(1, 0);
for (int i = 1; i <= m; ++ i)
{
cin >> a[i];
single[a[i]].insert(i);
if (i > 1)
{
dual[LCA(a[i], a[i - 1])].insert(i - 1);
}
}
while(q--)
{
int t;
cin >> t;
if (t == 1)
{
int pos, v;
cin >> pos >> v;
single[a[pos]].erase(pos);
single[v].insert(pos);
if (pos > 1)
{
dual[LCA(a[pos], a[pos - 1])].erase(pos - 1);
dual[LCA(v, a[pos - 1])].insert(pos - 1);
}
if (pos < m)
{
dual[LCA(a[pos], a[pos + 1])].erase(pos);
dual[LCA(v, a[pos + 1])].insert(pos);
}
a[pos] = v;
}
else
{
int l, r, u;
cin >> l >> r >> u;
auto it = single[u].lower_bound(l);
if (it != single[u].end() && *it <= r)
{
cout << *it << ' ' << *it << '\n';
continue;
}
it = dual[u].lower_bound(l);
if (it != dual[u].end() && *it < r)
{
cout << *it << ' ' << *it + 1 << '\n';
continue;
}
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);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
Compilation message
treearray.cpp: In function 'int main()':
treearray.cpp:128:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
128 | freopen(TASK".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
n=5 |
2 |
Correct |
12 ms |
23720 KB |
n=100 |
3 |
Correct |
12 ms |
23848 KB |
n=100 |
4 |
Correct |
13 ms |
23832 KB |
n=100 |
5 |
Correct |
12 ms |
23764 KB |
n=100 |
6 |
Correct |
12 ms |
23776 KB |
n=100 |
7 |
Correct |
12 ms |
23764 KB |
n=100 |
8 |
Correct |
12 ms |
23800 KB |
n=100 |
9 |
Correct |
12 ms |
23764 KB |
n=100 |
10 |
Correct |
14 ms |
23844 KB |
n=100 |
11 |
Correct |
12 ms |
23816 KB |
n=100 |
12 |
Correct |
12 ms |
23816 KB |
n=100 |
13 |
Correct |
13 ms |
23764 KB |
n=100 |
14 |
Correct |
13 ms |
23764 KB |
n=100 |
15 |
Correct |
14 ms |
23804 KB |
n=100 |
16 |
Correct |
12 ms |
23764 KB |
n=100 |
17 |
Correct |
12 ms |
23764 KB |
n=100 |
18 |
Correct |
13 ms |
23816 KB |
n=100 |
19 |
Correct |
13 ms |
23816 KB |
n=100 |
20 |
Correct |
13 ms |
23820 KB |
n=100 |
21 |
Correct |
12 ms |
23764 KB |
n=100 |
22 |
Correct |
12 ms |
23764 KB |
n=100 |
23 |
Correct |
13 ms |
23852 KB |
n=100 |
24 |
Correct |
13 ms |
23764 KB |
n=100 |
25 |
Correct |
13 ms |
23748 KB |
n=100 |
26 |
Correct |
13 ms |
23816 KB |
n=12 |
27 |
Correct |
12 ms |
23764 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
n=5 |
2 |
Correct |
12 ms |
23720 KB |
n=100 |
3 |
Correct |
12 ms |
23848 KB |
n=100 |
4 |
Correct |
13 ms |
23832 KB |
n=100 |
5 |
Correct |
12 ms |
23764 KB |
n=100 |
6 |
Correct |
12 ms |
23776 KB |
n=100 |
7 |
Correct |
12 ms |
23764 KB |
n=100 |
8 |
Correct |
12 ms |
23800 KB |
n=100 |
9 |
Correct |
12 ms |
23764 KB |
n=100 |
10 |
Correct |
14 ms |
23844 KB |
n=100 |
11 |
Correct |
12 ms |
23816 KB |
n=100 |
12 |
Correct |
12 ms |
23816 KB |
n=100 |
13 |
Correct |
13 ms |
23764 KB |
n=100 |
14 |
Correct |
13 ms |
23764 KB |
n=100 |
15 |
Correct |
14 ms |
23804 KB |
n=100 |
16 |
Correct |
12 ms |
23764 KB |
n=100 |
17 |
Correct |
12 ms |
23764 KB |
n=100 |
18 |
Correct |
13 ms |
23816 KB |
n=100 |
19 |
Correct |
13 ms |
23816 KB |
n=100 |
20 |
Correct |
13 ms |
23820 KB |
n=100 |
21 |
Correct |
12 ms |
23764 KB |
n=100 |
22 |
Correct |
12 ms |
23764 KB |
n=100 |
23 |
Correct |
13 ms |
23852 KB |
n=100 |
24 |
Correct |
13 ms |
23764 KB |
n=100 |
25 |
Correct |
13 ms |
23748 KB |
n=100 |
26 |
Correct |
13 ms |
23816 KB |
n=12 |
27 |
Correct |
12 ms |
23764 KB |
n=100 |
28 |
Correct |
13 ms |
23892 KB |
n=500 |
29 |
Correct |
14 ms |
23876 KB |
n=500 |
30 |
Correct |
14 ms |
23892 KB |
n=500 |
31 |
Correct |
14 ms |
23892 KB |
n=500 |
32 |
Correct |
14 ms |
23916 KB |
n=500 |
33 |
Correct |
13 ms |
23892 KB |
n=500 |
34 |
Correct |
13 ms |
23892 KB |
n=500 |
35 |
Correct |
13 ms |
23892 KB |
n=500 |
36 |
Correct |
13 ms |
23892 KB |
n=500 |
37 |
Correct |
13 ms |
23908 KB |
n=500 |
38 |
Correct |
12 ms |
23892 KB |
n=500 |
39 |
Correct |
13 ms |
23892 KB |
n=500 |
40 |
Correct |
17 ms |
23844 KB |
n=500 |
41 |
Correct |
15 ms |
23828 KB |
n=500 |
42 |
Correct |
14 ms |
23892 KB |
n=500 |
43 |
Correct |
13 ms |
23892 KB |
n=500 |
44 |
Correct |
13 ms |
23836 KB |
n=500 |
45 |
Correct |
13 ms |
23824 KB |
n=500 |
46 |
Correct |
13 ms |
23892 KB |
n=500 |
47 |
Correct |
14 ms |
23956 KB |
n=500 |
48 |
Correct |
13 ms |
23892 KB |
n=500 |
49 |
Correct |
13 ms |
23892 KB |
n=500 |
50 |
Correct |
13 ms |
23876 KB |
n=500 |
51 |
Correct |
15 ms |
23884 KB |
n=500 |
52 |
Correct |
14 ms |
23840 KB |
n=500 |
53 |
Correct |
13 ms |
23912 KB |
n=500 |
54 |
Correct |
16 ms |
23892 KB |
n=500 |
55 |
Correct |
13 ms |
23824 KB |
n=278 |
56 |
Correct |
13 ms |
23892 KB |
n=500 |
57 |
Correct |
14 ms |
23892 KB |
n=500 |
58 |
Correct |
13 ms |
23892 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
n=5 |
2 |
Correct |
12 ms |
23720 KB |
n=100 |
3 |
Correct |
12 ms |
23848 KB |
n=100 |
4 |
Correct |
13 ms |
23832 KB |
n=100 |
5 |
Correct |
12 ms |
23764 KB |
n=100 |
6 |
Correct |
12 ms |
23776 KB |
n=100 |
7 |
Correct |
12 ms |
23764 KB |
n=100 |
8 |
Correct |
12 ms |
23800 KB |
n=100 |
9 |
Correct |
12 ms |
23764 KB |
n=100 |
10 |
Correct |
14 ms |
23844 KB |
n=100 |
11 |
Correct |
12 ms |
23816 KB |
n=100 |
12 |
Correct |
12 ms |
23816 KB |
n=100 |
13 |
Correct |
13 ms |
23764 KB |
n=100 |
14 |
Correct |
13 ms |
23764 KB |
n=100 |
15 |
Correct |
14 ms |
23804 KB |
n=100 |
16 |
Correct |
12 ms |
23764 KB |
n=100 |
17 |
Correct |
12 ms |
23764 KB |
n=100 |
18 |
Correct |
13 ms |
23816 KB |
n=100 |
19 |
Correct |
13 ms |
23816 KB |
n=100 |
20 |
Correct |
13 ms |
23820 KB |
n=100 |
21 |
Correct |
12 ms |
23764 KB |
n=100 |
22 |
Correct |
12 ms |
23764 KB |
n=100 |
23 |
Correct |
13 ms |
23852 KB |
n=100 |
24 |
Correct |
13 ms |
23764 KB |
n=100 |
25 |
Correct |
13 ms |
23748 KB |
n=100 |
26 |
Correct |
13 ms |
23816 KB |
n=12 |
27 |
Correct |
12 ms |
23764 KB |
n=100 |
28 |
Correct |
13 ms |
23892 KB |
n=500 |
29 |
Correct |
14 ms |
23876 KB |
n=500 |
30 |
Correct |
14 ms |
23892 KB |
n=500 |
31 |
Correct |
14 ms |
23892 KB |
n=500 |
32 |
Correct |
14 ms |
23916 KB |
n=500 |
33 |
Correct |
13 ms |
23892 KB |
n=500 |
34 |
Correct |
13 ms |
23892 KB |
n=500 |
35 |
Correct |
13 ms |
23892 KB |
n=500 |
36 |
Correct |
13 ms |
23892 KB |
n=500 |
37 |
Correct |
13 ms |
23908 KB |
n=500 |
38 |
Correct |
12 ms |
23892 KB |
n=500 |
39 |
Correct |
13 ms |
23892 KB |
n=500 |
40 |
Correct |
17 ms |
23844 KB |
n=500 |
41 |
Correct |
15 ms |
23828 KB |
n=500 |
42 |
Correct |
14 ms |
23892 KB |
n=500 |
43 |
Correct |
13 ms |
23892 KB |
n=500 |
44 |
Correct |
13 ms |
23836 KB |
n=500 |
45 |
Correct |
13 ms |
23824 KB |
n=500 |
46 |
Correct |
13 ms |
23892 KB |
n=500 |
47 |
Correct |
14 ms |
23956 KB |
n=500 |
48 |
Correct |
13 ms |
23892 KB |
n=500 |
49 |
Correct |
13 ms |
23892 KB |
n=500 |
50 |
Correct |
13 ms |
23876 KB |
n=500 |
51 |
Correct |
15 ms |
23884 KB |
n=500 |
52 |
Correct |
14 ms |
23840 KB |
n=500 |
53 |
Correct |
13 ms |
23912 KB |
n=500 |
54 |
Correct |
16 ms |
23892 KB |
n=500 |
55 |
Correct |
13 ms |
23824 KB |
n=278 |
56 |
Correct |
13 ms |
23892 KB |
n=500 |
57 |
Correct |
14 ms |
23892 KB |
n=500 |
58 |
Correct |
13 ms |
23892 KB |
n=500 |
59 |
Correct |
17 ms |
24216 KB |
n=2000 |
60 |
Correct |
15 ms |
24436 KB |
n=2000 |
61 |
Correct |
16 ms |
24344 KB |
n=2000 |
62 |
Correct |
15 ms |
24276 KB |
n=2000 |
63 |
Correct |
19 ms |
24208 KB |
n=2000 |
64 |
Correct |
16 ms |
24276 KB |
n=2000 |
65 |
Correct |
16 ms |
24400 KB |
n=2000 |
66 |
Correct |
16 ms |
24348 KB |
n=2000 |
67 |
Correct |
16 ms |
24216 KB |
n=2000 |
68 |
Correct |
16 ms |
24364 KB |
n=2000 |
69 |
Correct |
15 ms |
24276 KB |
n=2000 |
70 |
Correct |
17 ms |
24212 KB |
n=2000 |
71 |
Correct |
16 ms |
24276 KB |
n=2000 |
72 |
Correct |
16 ms |
24220 KB |
n=2000 |
73 |
Correct |
14 ms |
24216 KB |
n=2000 |
74 |
Correct |
15 ms |
24276 KB |
n=1844 |
75 |
Correct |
15 ms |
24256 KB |
n=2000 |
76 |
Correct |
15 ms |
24216 KB |
n=2000 |
77 |
Correct |
16 ms |
24216 KB |
n=2000 |
78 |
Correct |
15 ms |
24212 KB |
n=2000 |
79 |
Correct |
16 ms |
24292 KB |
n=2000 |
80 |
Correct |
15 ms |
24344 KB |
n=2000 |
81 |
Correct |
16 ms |
24340 KB |
n=2000 |
82 |
Correct |
15 ms |
24216 KB |
n=2000 |
83 |
Correct |
16 ms |
24344 KB |
n=2000 |
84 |
Correct |
16 ms |
24308 KB |
n=2000 |
85 |
Correct |
16 ms |
24276 KB |
n=2000 |
86 |
Correct |
16 ms |
24276 KB |
n=2000 |
87 |
Correct |
17 ms |
24228 KB |
n=2000 |
88 |
Correct |
17 ms |
24396 KB |
n=2000 |
89 |
Correct |
15 ms |
24404 KB |
n=2000 |
90 |
Correct |
15 ms |
24404 KB |
n=2000 |
91 |
Correct |
15 ms |
24300 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
n=5 |
2 |
Correct |
12 ms |
23720 KB |
n=100 |
3 |
Correct |
12 ms |
23848 KB |
n=100 |
4 |
Correct |
13 ms |
23832 KB |
n=100 |
5 |
Correct |
12 ms |
23764 KB |
n=100 |
6 |
Correct |
12 ms |
23776 KB |
n=100 |
7 |
Correct |
12 ms |
23764 KB |
n=100 |
8 |
Correct |
12 ms |
23800 KB |
n=100 |
9 |
Correct |
12 ms |
23764 KB |
n=100 |
10 |
Correct |
14 ms |
23844 KB |
n=100 |
11 |
Correct |
12 ms |
23816 KB |
n=100 |
12 |
Correct |
12 ms |
23816 KB |
n=100 |
13 |
Correct |
13 ms |
23764 KB |
n=100 |
14 |
Correct |
13 ms |
23764 KB |
n=100 |
15 |
Correct |
14 ms |
23804 KB |
n=100 |
16 |
Correct |
12 ms |
23764 KB |
n=100 |
17 |
Correct |
12 ms |
23764 KB |
n=100 |
18 |
Correct |
13 ms |
23816 KB |
n=100 |
19 |
Correct |
13 ms |
23816 KB |
n=100 |
20 |
Correct |
13 ms |
23820 KB |
n=100 |
21 |
Correct |
12 ms |
23764 KB |
n=100 |
22 |
Correct |
12 ms |
23764 KB |
n=100 |
23 |
Correct |
13 ms |
23852 KB |
n=100 |
24 |
Correct |
13 ms |
23764 KB |
n=100 |
25 |
Correct |
13 ms |
23748 KB |
n=100 |
26 |
Correct |
13 ms |
23816 KB |
n=12 |
27 |
Correct |
12 ms |
23764 KB |
n=100 |
28 |
Correct |
13 ms |
23892 KB |
n=500 |
29 |
Correct |
14 ms |
23876 KB |
n=500 |
30 |
Correct |
14 ms |
23892 KB |
n=500 |
31 |
Correct |
14 ms |
23892 KB |
n=500 |
32 |
Correct |
14 ms |
23916 KB |
n=500 |
33 |
Correct |
13 ms |
23892 KB |
n=500 |
34 |
Correct |
13 ms |
23892 KB |
n=500 |
35 |
Correct |
13 ms |
23892 KB |
n=500 |
36 |
Correct |
13 ms |
23892 KB |
n=500 |
37 |
Correct |
13 ms |
23908 KB |
n=500 |
38 |
Correct |
12 ms |
23892 KB |
n=500 |
39 |
Correct |
13 ms |
23892 KB |
n=500 |
40 |
Correct |
17 ms |
23844 KB |
n=500 |
41 |
Correct |
15 ms |
23828 KB |
n=500 |
42 |
Correct |
14 ms |
23892 KB |
n=500 |
43 |
Correct |
13 ms |
23892 KB |
n=500 |
44 |
Correct |
13 ms |
23836 KB |
n=500 |
45 |
Correct |
13 ms |
23824 KB |
n=500 |
46 |
Correct |
13 ms |
23892 KB |
n=500 |
47 |
Correct |
14 ms |
23956 KB |
n=500 |
48 |
Correct |
13 ms |
23892 KB |
n=500 |
49 |
Correct |
13 ms |
23892 KB |
n=500 |
50 |
Correct |
13 ms |
23876 KB |
n=500 |
51 |
Correct |
15 ms |
23884 KB |
n=500 |
52 |
Correct |
14 ms |
23840 KB |
n=500 |
53 |
Correct |
13 ms |
23912 KB |
n=500 |
54 |
Correct |
16 ms |
23892 KB |
n=500 |
55 |
Correct |
13 ms |
23824 KB |
n=278 |
56 |
Correct |
13 ms |
23892 KB |
n=500 |
57 |
Correct |
14 ms |
23892 KB |
n=500 |
58 |
Correct |
13 ms |
23892 KB |
n=500 |
59 |
Correct |
17 ms |
24216 KB |
n=2000 |
60 |
Correct |
15 ms |
24436 KB |
n=2000 |
61 |
Correct |
16 ms |
24344 KB |
n=2000 |
62 |
Correct |
15 ms |
24276 KB |
n=2000 |
63 |
Correct |
19 ms |
24208 KB |
n=2000 |
64 |
Correct |
16 ms |
24276 KB |
n=2000 |
65 |
Correct |
16 ms |
24400 KB |
n=2000 |
66 |
Correct |
16 ms |
24348 KB |
n=2000 |
67 |
Correct |
16 ms |
24216 KB |
n=2000 |
68 |
Correct |
16 ms |
24364 KB |
n=2000 |
69 |
Correct |
15 ms |
24276 KB |
n=2000 |
70 |
Correct |
17 ms |
24212 KB |
n=2000 |
71 |
Correct |
16 ms |
24276 KB |
n=2000 |
72 |
Correct |
16 ms |
24220 KB |
n=2000 |
73 |
Correct |
14 ms |
24216 KB |
n=2000 |
74 |
Correct |
15 ms |
24276 KB |
n=1844 |
75 |
Correct |
15 ms |
24256 KB |
n=2000 |
76 |
Correct |
15 ms |
24216 KB |
n=2000 |
77 |
Correct |
16 ms |
24216 KB |
n=2000 |
78 |
Correct |
15 ms |
24212 KB |
n=2000 |
79 |
Correct |
16 ms |
24292 KB |
n=2000 |
80 |
Correct |
15 ms |
24344 KB |
n=2000 |
81 |
Correct |
16 ms |
24340 KB |
n=2000 |
82 |
Correct |
15 ms |
24216 KB |
n=2000 |
83 |
Correct |
16 ms |
24344 KB |
n=2000 |
84 |
Correct |
16 ms |
24308 KB |
n=2000 |
85 |
Correct |
16 ms |
24276 KB |
n=2000 |
86 |
Correct |
16 ms |
24276 KB |
n=2000 |
87 |
Correct |
17 ms |
24228 KB |
n=2000 |
88 |
Correct |
17 ms |
24396 KB |
n=2000 |
89 |
Correct |
15 ms |
24404 KB |
n=2000 |
90 |
Correct |
15 ms |
24404 KB |
n=2000 |
91 |
Correct |
15 ms |
24300 KB |
n=2000 |
92 |
Correct |
712 ms |
66716 KB |
n=200000 |
93 |
Correct |
911 ms |
73596 KB |
n=200000 |
94 |
Correct |
904 ms |
79064 KB |
n=200000 |
95 |
Correct |
698 ms |
66560 KB |
n=200000 |
96 |
Correct |
674 ms |
66716 KB |
n=200000 |
97 |
Correct |
975 ms |
72076 KB |
n=200000 |
98 |
Correct |
679 ms |
66576 KB |
n=200000 |
99 |
Correct |
872 ms |
66028 KB |
n=200000 |
100 |
Correct |
727 ms |
66828 KB |
n=200000 |
101 |
Correct |
837 ms |
81404 KB |
n=200000 |
102 |
Correct |
437 ms |
67532 KB |
n=200000 |
103 |
Correct |
456 ms |
67576 KB |
n=200000 |
104 |
Correct |
456 ms |
67736 KB |
n=200000 |
105 |
Correct |
437 ms |
67216 KB |
n=200000 |
106 |
Correct |
471 ms |
67240 KB |
n=200000 |
107 |
Correct |
451 ms |
67300 KB |
n=200000 |
108 |
Correct |
786 ms |
66260 KB |
n=200000 |
109 |
Correct |
820 ms |
66192 KB |
n=200000 |
110 |
Correct |
788 ms |
66244 KB |
n=200000 |
111 |
Correct |
707 ms |
66552 KB |
n=200000 |
112 |
Correct |
832 ms |
79472 KB |
n=200000 |
113 |
Correct |
1004 ms |
72068 KB |
n=200000 |
114 |
Correct |
716 ms |
66628 KB |
n=200000 |
115 |
Correct |
1052 ms |
68488 KB |
n=200000 |
116 |
Correct |
662 ms |
66400 KB |
n=200000 |
117 |
Correct |
827 ms |
80212 KB |
n=200000 |
118 |
Correct |
988 ms |
70240 KB |
n=200000 |
119 |
Correct |
677 ms |
66300 KB |
n=200000 |
120 |
Correct |
828 ms |
80992 KB |
n=200000 |
121 |
Correct |
815 ms |
81080 KB |
n=200000 |
122 |
Correct |
830 ms |
81456 KB |
n=200000 |
123 |
Correct |
444 ms |
66868 KB |
n=200000 |
124 |
Correct |
241 ms |
37564 KB |
n=25264 |