#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define int long long
#define N 400005
#define M 1000000007
#define pii pair<int, int>
#define piii pair<pii, int>
using namespace std;
int n, m, q, t, c[N], h[N], k[N][30], l[N], pos, val, L, R;
vector<int> v[N];
multiset<int> s[N], s1[N];
multiset<int> :: iterator it;
void dfs(int u, int p)
{
h[u] = h[p] + 1;
k[u][0] = p;
for(auto x : v[u])
if(x != p) dfs(x, u);
}
int lca(int a, int b)
{
int i;
if(h[a] < h[b]) swap(a, b);
for(i = 20; i >= 0; i--)
if(h[k[a][i]] >= h[b]) a = k[a][i];
if(a == b) return a;
for(i = 20; i >= 0; i--)
if(k[a][i] != k[b][i]) a = k[a][i], b = k[b][i];
return k[a][0];
}
main()
{
std::ios::sync_with_stdio(0);
cin.tie();
int a, b, i, j;
cin >> n >> m >> q;
for(i = 1; i < n; i++)
{
cin >> a >> b;
v[a].pb(b);
v[b].pb(a);
}
dfs(1, 0);
for(j = 1; j <= 20; j++)
for(i = 1; i <= n; i++)
k[i][j] = k[k[i][j - 1]][j - 1];
for(i = 1; i <= m; i++)
{
cin >> c[i];
s[c[i]].insert(i);
if(i > 1) l[i] = lca(c[i], c[i - 1]);
s1[l[i]].insert(i);
}
while(q--)
{
cin >> t;
if(t == 1)
{
cin >> pos >> val;
it = s[c[pos]].lower_bound(pos);
if(it != s[c[pos]].end()) s[c[pos]].erase(it);
c[pos] = val;
s[val].insert(pos);
it = s1[l[pos]].lower_bound(pos);
if(it != s1[l[pos]].end()) s1[l[pos]].erase(it);
l[pos] = lca(c[pos], c[pos - 1]);
s1[l[pos]].insert(pos);
it = s1[l[pos + 1]].lower_bound(pos + 1);
if(it != s1[l[pos + 1]].end()) s1[l[pos + 1]].erase(it);
l[pos + 1] = lca(c[pos + 1], c[pos]);
s1[l[pos + 1]].insert(pos + 1);
}
else
{
cin >> L >> R >> val;
it = s[val].lower_bound(L);
if(it != s[val].end() && *it <= R) { cout << *it << ' ' << *it << '\n'; continue; }
it = s1[val].lower_bound(L + 1);
if(it != s1[val].end() && *it <= R) cout << *it - 1 << ' ' << *it << '\n';
else cout << "-1 -1\n";
}
}
}
Compilation message
treearray.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
37 | main()
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
47316 KB |
n=5 |
2 |
Correct |
25 ms |
47336 KB |
n=100 |
3 |
Correct |
23 ms |
47288 KB |
n=100 |
4 |
Correct |
23 ms |
47316 KB |
n=100 |
5 |
Correct |
27 ms |
47308 KB |
n=100 |
6 |
Correct |
25 ms |
47332 KB |
n=100 |
7 |
Correct |
23 ms |
47316 KB |
n=100 |
8 |
Correct |
25 ms |
47300 KB |
n=100 |
9 |
Correct |
24 ms |
47316 KB |
n=100 |
10 |
Correct |
22 ms |
47316 KB |
n=100 |
11 |
Correct |
23 ms |
47292 KB |
n=100 |
12 |
Correct |
27 ms |
47276 KB |
n=100 |
13 |
Correct |
25 ms |
47360 KB |
n=100 |
14 |
Correct |
25 ms |
47316 KB |
n=100 |
15 |
Correct |
25 ms |
47256 KB |
n=100 |
16 |
Correct |
26 ms |
47304 KB |
n=100 |
17 |
Correct |
24 ms |
47308 KB |
n=100 |
18 |
Correct |
26 ms |
47244 KB |
n=100 |
19 |
Correct |
27 ms |
47240 KB |
n=100 |
20 |
Correct |
25 ms |
47300 KB |
n=100 |
21 |
Correct |
25 ms |
47316 KB |
n=100 |
22 |
Correct |
22 ms |
47292 KB |
n=100 |
23 |
Correct |
24 ms |
47312 KB |
n=100 |
24 |
Correct |
25 ms |
47292 KB |
n=100 |
25 |
Correct |
30 ms |
47336 KB |
n=100 |
26 |
Correct |
24 ms |
47280 KB |
n=12 |
27 |
Correct |
24 ms |
47304 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
47316 KB |
n=5 |
2 |
Correct |
25 ms |
47336 KB |
n=100 |
3 |
Correct |
23 ms |
47288 KB |
n=100 |
4 |
Correct |
23 ms |
47316 KB |
n=100 |
5 |
Correct |
27 ms |
47308 KB |
n=100 |
6 |
Correct |
25 ms |
47332 KB |
n=100 |
7 |
Correct |
23 ms |
47316 KB |
n=100 |
8 |
Correct |
25 ms |
47300 KB |
n=100 |
9 |
Correct |
24 ms |
47316 KB |
n=100 |
10 |
Correct |
22 ms |
47316 KB |
n=100 |
11 |
Correct |
23 ms |
47292 KB |
n=100 |
12 |
Correct |
27 ms |
47276 KB |
n=100 |
13 |
Correct |
25 ms |
47360 KB |
n=100 |
14 |
Correct |
25 ms |
47316 KB |
n=100 |
15 |
Correct |
25 ms |
47256 KB |
n=100 |
16 |
Correct |
26 ms |
47304 KB |
n=100 |
17 |
Correct |
24 ms |
47308 KB |
n=100 |
18 |
Correct |
26 ms |
47244 KB |
n=100 |
19 |
Correct |
27 ms |
47240 KB |
n=100 |
20 |
Correct |
25 ms |
47300 KB |
n=100 |
21 |
Correct |
25 ms |
47316 KB |
n=100 |
22 |
Correct |
22 ms |
47292 KB |
n=100 |
23 |
Correct |
24 ms |
47312 KB |
n=100 |
24 |
Correct |
25 ms |
47292 KB |
n=100 |
25 |
Correct |
30 ms |
47336 KB |
n=100 |
26 |
Correct |
24 ms |
47280 KB |
n=12 |
27 |
Correct |
24 ms |
47304 KB |
n=100 |
28 |
Correct |
25 ms |
47496 KB |
n=500 |
29 |
Correct |
22 ms |
47444 KB |
n=500 |
30 |
Correct |
25 ms |
47436 KB |
n=500 |
31 |
Correct |
26 ms |
47444 KB |
n=500 |
32 |
Correct |
25 ms |
47424 KB |
n=500 |
33 |
Correct |
25 ms |
47444 KB |
n=500 |
34 |
Correct |
24 ms |
47412 KB |
n=500 |
35 |
Correct |
24 ms |
47424 KB |
n=500 |
36 |
Correct |
25 ms |
47436 KB |
n=500 |
37 |
Correct |
24 ms |
47436 KB |
n=500 |
38 |
Correct |
24 ms |
47452 KB |
n=500 |
39 |
Correct |
24 ms |
47432 KB |
n=500 |
40 |
Correct |
25 ms |
47436 KB |
n=500 |
41 |
Correct |
25 ms |
47428 KB |
n=500 |
42 |
Correct |
26 ms |
47444 KB |
n=500 |
43 |
Correct |
25 ms |
47472 KB |
n=500 |
44 |
Correct |
26 ms |
47396 KB |
n=500 |
45 |
Correct |
24 ms |
47436 KB |
n=500 |
46 |
Correct |
24 ms |
47432 KB |
n=500 |
47 |
Correct |
25 ms |
47476 KB |
n=500 |
48 |
Correct |
26 ms |
47468 KB |
n=500 |
49 |
Correct |
24 ms |
47444 KB |
n=500 |
50 |
Correct |
24 ms |
47428 KB |
n=500 |
51 |
Correct |
24 ms |
47440 KB |
n=500 |
52 |
Correct |
24 ms |
47512 KB |
n=500 |
53 |
Correct |
25 ms |
47444 KB |
n=500 |
54 |
Correct |
29 ms |
47452 KB |
n=500 |
55 |
Correct |
25 ms |
47388 KB |
n=278 |
56 |
Correct |
26 ms |
47444 KB |
n=500 |
57 |
Correct |
25 ms |
47492 KB |
n=500 |
58 |
Correct |
28 ms |
47400 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
47316 KB |
n=5 |
2 |
Correct |
25 ms |
47336 KB |
n=100 |
3 |
Correct |
23 ms |
47288 KB |
n=100 |
4 |
Correct |
23 ms |
47316 KB |
n=100 |
5 |
Correct |
27 ms |
47308 KB |
n=100 |
6 |
Correct |
25 ms |
47332 KB |
n=100 |
7 |
Correct |
23 ms |
47316 KB |
n=100 |
8 |
Correct |
25 ms |
47300 KB |
n=100 |
9 |
Correct |
24 ms |
47316 KB |
n=100 |
10 |
Correct |
22 ms |
47316 KB |
n=100 |
11 |
Correct |
23 ms |
47292 KB |
n=100 |
12 |
Correct |
27 ms |
47276 KB |
n=100 |
13 |
Correct |
25 ms |
47360 KB |
n=100 |
14 |
Correct |
25 ms |
47316 KB |
n=100 |
15 |
Correct |
25 ms |
47256 KB |
n=100 |
16 |
Correct |
26 ms |
47304 KB |
n=100 |
17 |
Correct |
24 ms |
47308 KB |
n=100 |
18 |
Correct |
26 ms |
47244 KB |
n=100 |
19 |
Correct |
27 ms |
47240 KB |
n=100 |
20 |
Correct |
25 ms |
47300 KB |
n=100 |
21 |
Correct |
25 ms |
47316 KB |
n=100 |
22 |
Correct |
22 ms |
47292 KB |
n=100 |
23 |
Correct |
24 ms |
47312 KB |
n=100 |
24 |
Correct |
25 ms |
47292 KB |
n=100 |
25 |
Correct |
30 ms |
47336 KB |
n=100 |
26 |
Correct |
24 ms |
47280 KB |
n=12 |
27 |
Correct |
24 ms |
47304 KB |
n=100 |
28 |
Correct |
25 ms |
47496 KB |
n=500 |
29 |
Correct |
22 ms |
47444 KB |
n=500 |
30 |
Correct |
25 ms |
47436 KB |
n=500 |
31 |
Correct |
26 ms |
47444 KB |
n=500 |
32 |
Correct |
25 ms |
47424 KB |
n=500 |
33 |
Correct |
25 ms |
47444 KB |
n=500 |
34 |
Correct |
24 ms |
47412 KB |
n=500 |
35 |
Correct |
24 ms |
47424 KB |
n=500 |
36 |
Correct |
25 ms |
47436 KB |
n=500 |
37 |
Correct |
24 ms |
47436 KB |
n=500 |
38 |
Correct |
24 ms |
47452 KB |
n=500 |
39 |
Correct |
24 ms |
47432 KB |
n=500 |
40 |
Correct |
25 ms |
47436 KB |
n=500 |
41 |
Correct |
25 ms |
47428 KB |
n=500 |
42 |
Correct |
26 ms |
47444 KB |
n=500 |
43 |
Correct |
25 ms |
47472 KB |
n=500 |
44 |
Correct |
26 ms |
47396 KB |
n=500 |
45 |
Correct |
24 ms |
47436 KB |
n=500 |
46 |
Correct |
24 ms |
47432 KB |
n=500 |
47 |
Correct |
25 ms |
47476 KB |
n=500 |
48 |
Correct |
26 ms |
47468 KB |
n=500 |
49 |
Correct |
24 ms |
47444 KB |
n=500 |
50 |
Correct |
24 ms |
47428 KB |
n=500 |
51 |
Correct |
24 ms |
47440 KB |
n=500 |
52 |
Correct |
24 ms |
47512 KB |
n=500 |
53 |
Correct |
25 ms |
47444 KB |
n=500 |
54 |
Correct |
29 ms |
47452 KB |
n=500 |
55 |
Correct |
25 ms |
47388 KB |
n=278 |
56 |
Correct |
26 ms |
47444 KB |
n=500 |
57 |
Correct |
25 ms |
47492 KB |
n=500 |
58 |
Correct |
28 ms |
47400 KB |
n=500 |
59 |
Correct |
29 ms |
48064 KB |
n=2000 |
60 |
Correct |
29 ms |
48212 KB |
n=2000 |
61 |
Correct |
27 ms |
48160 KB |
n=2000 |
62 |
Correct |
27 ms |
48172 KB |
n=2000 |
63 |
Correct |
30 ms |
48084 KB |
n=2000 |
64 |
Correct |
33 ms |
48060 KB |
n=2000 |
65 |
Correct |
29 ms |
48076 KB |
n=2000 |
66 |
Correct |
28 ms |
48200 KB |
n=2000 |
67 |
Correct |
29 ms |
48084 KB |
n=2000 |
68 |
Correct |
29 ms |
48060 KB |
n=2000 |
69 |
Correct |
36 ms |
48140 KB |
n=2000 |
70 |
Correct |
31 ms |
48176 KB |
n=2000 |
71 |
Correct |
28 ms |
48076 KB |
n=2000 |
72 |
Correct |
27 ms |
48140 KB |
n=2000 |
73 |
Correct |
28 ms |
48148 KB |
n=2000 |
74 |
Correct |
28 ms |
48080 KB |
n=1844 |
75 |
Correct |
28 ms |
48128 KB |
n=2000 |
76 |
Correct |
29 ms |
48140 KB |
n=2000 |
77 |
Correct |
27 ms |
48168 KB |
n=2000 |
78 |
Correct |
35 ms |
48084 KB |
n=2000 |
79 |
Correct |
29 ms |
48144 KB |
n=2000 |
80 |
Correct |
27 ms |
48160 KB |
n=2000 |
81 |
Correct |
30 ms |
48076 KB |
n=2000 |
82 |
Correct |
29 ms |
48136 KB |
n=2000 |
83 |
Correct |
28 ms |
48212 KB |
n=2000 |
84 |
Correct |
30 ms |
48136 KB |
n=2000 |
85 |
Correct |
31 ms |
48080 KB |
n=2000 |
86 |
Correct |
29 ms |
48204 KB |
n=2000 |
87 |
Correct |
29 ms |
48084 KB |
n=2000 |
88 |
Correct |
27 ms |
48212 KB |
n=2000 |
89 |
Correct |
29 ms |
48228 KB |
n=2000 |
90 |
Correct |
32 ms |
48212 KB |
n=2000 |
91 |
Correct |
30 ms |
48140 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
47316 KB |
n=5 |
2 |
Correct |
25 ms |
47336 KB |
n=100 |
3 |
Correct |
23 ms |
47288 KB |
n=100 |
4 |
Correct |
23 ms |
47316 KB |
n=100 |
5 |
Correct |
27 ms |
47308 KB |
n=100 |
6 |
Correct |
25 ms |
47332 KB |
n=100 |
7 |
Correct |
23 ms |
47316 KB |
n=100 |
8 |
Correct |
25 ms |
47300 KB |
n=100 |
9 |
Correct |
24 ms |
47316 KB |
n=100 |
10 |
Correct |
22 ms |
47316 KB |
n=100 |
11 |
Correct |
23 ms |
47292 KB |
n=100 |
12 |
Correct |
27 ms |
47276 KB |
n=100 |
13 |
Correct |
25 ms |
47360 KB |
n=100 |
14 |
Correct |
25 ms |
47316 KB |
n=100 |
15 |
Correct |
25 ms |
47256 KB |
n=100 |
16 |
Correct |
26 ms |
47304 KB |
n=100 |
17 |
Correct |
24 ms |
47308 KB |
n=100 |
18 |
Correct |
26 ms |
47244 KB |
n=100 |
19 |
Correct |
27 ms |
47240 KB |
n=100 |
20 |
Correct |
25 ms |
47300 KB |
n=100 |
21 |
Correct |
25 ms |
47316 KB |
n=100 |
22 |
Correct |
22 ms |
47292 KB |
n=100 |
23 |
Correct |
24 ms |
47312 KB |
n=100 |
24 |
Correct |
25 ms |
47292 KB |
n=100 |
25 |
Correct |
30 ms |
47336 KB |
n=100 |
26 |
Correct |
24 ms |
47280 KB |
n=12 |
27 |
Correct |
24 ms |
47304 KB |
n=100 |
28 |
Correct |
25 ms |
47496 KB |
n=500 |
29 |
Correct |
22 ms |
47444 KB |
n=500 |
30 |
Correct |
25 ms |
47436 KB |
n=500 |
31 |
Correct |
26 ms |
47444 KB |
n=500 |
32 |
Correct |
25 ms |
47424 KB |
n=500 |
33 |
Correct |
25 ms |
47444 KB |
n=500 |
34 |
Correct |
24 ms |
47412 KB |
n=500 |
35 |
Correct |
24 ms |
47424 KB |
n=500 |
36 |
Correct |
25 ms |
47436 KB |
n=500 |
37 |
Correct |
24 ms |
47436 KB |
n=500 |
38 |
Correct |
24 ms |
47452 KB |
n=500 |
39 |
Correct |
24 ms |
47432 KB |
n=500 |
40 |
Correct |
25 ms |
47436 KB |
n=500 |
41 |
Correct |
25 ms |
47428 KB |
n=500 |
42 |
Correct |
26 ms |
47444 KB |
n=500 |
43 |
Correct |
25 ms |
47472 KB |
n=500 |
44 |
Correct |
26 ms |
47396 KB |
n=500 |
45 |
Correct |
24 ms |
47436 KB |
n=500 |
46 |
Correct |
24 ms |
47432 KB |
n=500 |
47 |
Correct |
25 ms |
47476 KB |
n=500 |
48 |
Correct |
26 ms |
47468 KB |
n=500 |
49 |
Correct |
24 ms |
47444 KB |
n=500 |
50 |
Correct |
24 ms |
47428 KB |
n=500 |
51 |
Correct |
24 ms |
47440 KB |
n=500 |
52 |
Correct |
24 ms |
47512 KB |
n=500 |
53 |
Correct |
25 ms |
47444 KB |
n=500 |
54 |
Correct |
29 ms |
47452 KB |
n=500 |
55 |
Correct |
25 ms |
47388 KB |
n=278 |
56 |
Correct |
26 ms |
47444 KB |
n=500 |
57 |
Correct |
25 ms |
47492 KB |
n=500 |
58 |
Correct |
28 ms |
47400 KB |
n=500 |
59 |
Correct |
29 ms |
48064 KB |
n=2000 |
60 |
Correct |
29 ms |
48212 KB |
n=2000 |
61 |
Correct |
27 ms |
48160 KB |
n=2000 |
62 |
Correct |
27 ms |
48172 KB |
n=2000 |
63 |
Correct |
30 ms |
48084 KB |
n=2000 |
64 |
Correct |
33 ms |
48060 KB |
n=2000 |
65 |
Correct |
29 ms |
48076 KB |
n=2000 |
66 |
Correct |
28 ms |
48200 KB |
n=2000 |
67 |
Correct |
29 ms |
48084 KB |
n=2000 |
68 |
Correct |
29 ms |
48060 KB |
n=2000 |
69 |
Correct |
36 ms |
48140 KB |
n=2000 |
70 |
Correct |
31 ms |
48176 KB |
n=2000 |
71 |
Correct |
28 ms |
48076 KB |
n=2000 |
72 |
Correct |
27 ms |
48140 KB |
n=2000 |
73 |
Correct |
28 ms |
48148 KB |
n=2000 |
74 |
Correct |
28 ms |
48080 KB |
n=1844 |
75 |
Correct |
28 ms |
48128 KB |
n=2000 |
76 |
Correct |
29 ms |
48140 KB |
n=2000 |
77 |
Correct |
27 ms |
48168 KB |
n=2000 |
78 |
Correct |
35 ms |
48084 KB |
n=2000 |
79 |
Correct |
29 ms |
48144 KB |
n=2000 |
80 |
Correct |
27 ms |
48160 KB |
n=2000 |
81 |
Correct |
30 ms |
48076 KB |
n=2000 |
82 |
Correct |
29 ms |
48136 KB |
n=2000 |
83 |
Correct |
28 ms |
48212 KB |
n=2000 |
84 |
Correct |
30 ms |
48136 KB |
n=2000 |
85 |
Correct |
31 ms |
48080 KB |
n=2000 |
86 |
Correct |
29 ms |
48204 KB |
n=2000 |
87 |
Correct |
29 ms |
48084 KB |
n=2000 |
88 |
Correct |
27 ms |
48212 KB |
n=2000 |
89 |
Correct |
29 ms |
48228 KB |
n=2000 |
90 |
Correct |
32 ms |
48212 KB |
n=2000 |
91 |
Correct |
30 ms |
48140 KB |
n=2000 |
92 |
Correct |
880 ms |
133456 KB |
n=200000 |
93 |
Correct |
1401 ms |
138252 KB |
n=200000 |
94 |
Correct |
1263 ms |
141072 KB |
n=200000 |
95 |
Correct |
927 ms |
133040 KB |
n=200000 |
96 |
Correct |
881 ms |
133048 KB |
n=200000 |
97 |
Correct |
1609 ms |
137296 KB |
n=200000 |
98 |
Correct |
967 ms |
133076 KB |
n=200000 |
99 |
Correct |
1347 ms |
133656 KB |
n=200000 |
100 |
Correct |
920 ms |
133088 KB |
n=200000 |
101 |
Correct |
1327 ms |
141968 KB |
n=200000 |
102 |
Correct |
804 ms |
134604 KB |
n=200000 |
103 |
Correct |
760 ms |
134472 KB |
n=200000 |
104 |
Correct |
820 ms |
134628 KB |
n=200000 |
105 |
Correct |
867 ms |
134952 KB |
n=200000 |
106 |
Correct |
801 ms |
134952 KB |
n=200000 |
107 |
Correct |
746 ms |
134884 KB |
n=200000 |
108 |
Correct |
1066 ms |
133364 KB |
n=200000 |
109 |
Correct |
1119 ms |
133500 KB |
n=200000 |
110 |
Correct |
1059 ms |
133368 KB |
n=200000 |
111 |
Correct |
912 ms |
132672 KB |
n=200000 |
112 |
Correct |
1313 ms |
141316 KB |
n=200000 |
113 |
Correct |
1406 ms |
137396 KB |
n=200000 |
114 |
Correct |
931 ms |
132716 KB |
n=200000 |
115 |
Correct |
1548 ms |
135396 KB |
n=200000 |
116 |
Correct |
884 ms |
133256 KB |
n=200000 |
117 |
Correct |
1234 ms |
141496 KB |
n=200000 |
118 |
Correct |
1478 ms |
136256 KB |
n=200000 |
119 |
Correct |
883 ms |
133176 KB |
n=200000 |
120 |
Correct |
1188 ms |
141116 KB |
n=200000 |
121 |
Correct |
1266 ms |
140960 KB |
n=200000 |
122 |
Correct |
1182 ms |
141240 KB |
n=200000 |
123 |
Correct |
806 ms |
134644 KB |
n=200000 |
124 |
Correct |
371 ms |
67404 KB |
n=25264 |