#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <numeric>
#include <queue>
#include <assert.h>
#include <map>
#include <set>
#include <limits.h>
using namespace std;
#define ll long long
#define ld long double
const int MX = 200005;
const int LG = (int)log2(MX) + 2;
const ll mod = 1e9 + 7;
const ll inv2 = (mod + 1) / 2;
#define gc getchar//_unlocked //can't for window server
void cin(int &x){
char c = gc(); bool neg = false;
for(; c < '0'||'9' < c; c = gc())
if(c == '-') neg=true;
x = c - '0'; c = gc();
for(; '0' <= c && c <= '9'; c = gc())
x = (x << 1) + (x << 3) + (c - '0');
if(neg) x = -x;
}
int n, m, q, a[MX];
vector<int> adj[MX];
set<int> ans_1[MX], ans_2[MX];
int anc[MX][LG], depth[MX];
void dfs(int nw, int bf){
anc[nw][0] = bf;
depth[nw] = depth[bf] + 1;
for(int nx : adj[nw]) if(nx != bf)
dfs(nx, nw);
}
void build_lca(){
for(int j = 1; j < LG; j ++)
for(int i = 1; i <= n; i ++)
anc[i][j] = anc[anc[i][j - 1]][j - 1];
}
int lca(int u, int v){
if(depth[u] < depth[v]) swap(u, v);
int diff = depth[u] - depth[v];
for(int i = LG - 1; i >= 0; i --)
if(diff & (1 << i)) u = anc[u][i];
if(u == v) return u;
for(int i = LG - 1; i >= 0; i --)
if(anc[u][i] != anc[v][i])
u = anc[u][i], v = anc[v][i];
return anc[u][0];
}
int main(){
cin(n); cin(m); cin(q);
for(int u, v, i = 1; i < n; i ++){
cin(u); cin(v);
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 1);
build_lca();
for(int i = 1; i <= m; i ++){
cin(a[i]);
ans_1[a[i]].insert(i);
}
for(int i = 1; i < m; i ++){
int lc = lca(a[i], a[i + 1]);
ans_2[lc].insert(i);
}
for(int tp, l, r, ps, v; q --;){
cin(tp);
if(tp == 1){
cin(ps); cin(v);
if(ps > 1){
int get = lca(a[ps - 1], a[ps]);
ans_2[get].erase(ans_2[get].find(ps - 1));
get = lca(a[ps - 1], v);
ans_2[get].insert(ps - 1);
}
if(ps < m){
int get = lca(a[ps], a[ps + 1]);
ans_2[get].erase(ans_2[get].find(ps));
get = lca(v, a[ps + 1]);
ans_2[get].insert(ps);
}
ans_1[a[ps]].erase(ans_1[a[ps]].find(ps));
a[ps] = v;
ans_1[a[ps]].insert(ps);
}else{
cin(l); cin(r); cin(v);
auto it = ans_2[v].lower_bound(l);
if(it != ans_2[v].end() && l <= *it && *it + 1 <= r)
printf("%d %d\n", *it, *it + 1);
else{
it = ans_1[v].lower_bound(l);
if(it != ans_1[v].end() && l <= *it && *it <= r)
printf("%d %d\n", *it, *it);
else
printf("-1 -1\n");
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
n=5 |
2 |
Correct |
16 ms |
23788 KB |
n=100 |
3 |
Correct |
16 ms |
23788 KB |
n=100 |
4 |
Correct |
16 ms |
23788 KB |
n=100 |
5 |
Correct |
16 ms |
23788 KB |
n=100 |
6 |
Correct |
17 ms |
23788 KB |
n=100 |
7 |
Correct |
15 ms |
23788 KB |
n=100 |
8 |
Correct |
16 ms |
23788 KB |
n=100 |
9 |
Correct |
15 ms |
23788 KB |
n=100 |
10 |
Correct |
15 ms |
23788 KB |
n=100 |
11 |
Correct |
16 ms |
23788 KB |
n=100 |
12 |
Correct |
17 ms |
23916 KB |
n=100 |
13 |
Correct |
15 ms |
23788 KB |
n=100 |
14 |
Correct |
16 ms |
23788 KB |
n=100 |
15 |
Correct |
16 ms |
23788 KB |
n=100 |
16 |
Correct |
15 ms |
23788 KB |
n=100 |
17 |
Correct |
15 ms |
23788 KB |
n=100 |
18 |
Correct |
15 ms |
23788 KB |
n=100 |
19 |
Correct |
16 ms |
23788 KB |
n=100 |
20 |
Correct |
16 ms |
23788 KB |
n=100 |
21 |
Correct |
16 ms |
23788 KB |
n=100 |
22 |
Correct |
16 ms |
23788 KB |
n=100 |
23 |
Correct |
15 ms |
23788 KB |
n=100 |
24 |
Correct |
15 ms |
23788 KB |
n=100 |
25 |
Correct |
16 ms |
23788 KB |
n=100 |
26 |
Correct |
16 ms |
23788 KB |
n=12 |
27 |
Correct |
18 ms |
23788 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
n=5 |
2 |
Correct |
16 ms |
23788 KB |
n=100 |
3 |
Correct |
16 ms |
23788 KB |
n=100 |
4 |
Correct |
16 ms |
23788 KB |
n=100 |
5 |
Correct |
16 ms |
23788 KB |
n=100 |
6 |
Correct |
17 ms |
23788 KB |
n=100 |
7 |
Correct |
15 ms |
23788 KB |
n=100 |
8 |
Correct |
16 ms |
23788 KB |
n=100 |
9 |
Correct |
15 ms |
23788 KB |
n=100 |
10 |
Correct |
15 ms |
23788 KB |
n=100 |
11 |
Correct |
16 ms |
23788 KB |
n=100 |
12 |
Correct |
17 ms |
23916 KB |
n=100 |
13 |
Correct |
15 ms |
23788 KB |
n=100 |
14 |
Correct |
16 ms |
23788 KB |
n=100 |
15 |
Correct |
16 ms |
23788 KB |
n=100 |
16 |
Correct |
15 ms |
23788 KB |
n=100 |
17 |
Correct |
15 ms |
23788 KB |
n=100 |
18 |
Correct |
15 ms |
23788 KB |
n=100 |
19 |
Correct |
16 ms |
23788 KB |
n=100 |
20 |
Correct |
16 ms |
23788 KB |
n=100 |
21 |
Correct |
16 ms |
23788 KB |
n=100 |
22 |
Correct |
16 ms |
23788 KB |
n=100 |
23 |
Correct |
15 ms |
23788 KB |
n=100 |
24 |
Correct |
15 ms |
23788 KB |
n=100 |
25 |
Correct |
16 ms |
23788 KB |
n=100 |
26 |
Correct |
16 ms |
23788 KB |
n=12 |
27 |
Correct |
18 ms |
23788 KB |
n=100 |
28 |
Correct |
17 ms |
23916 KB |
n=500 |
29 |
Correct |
16 ms |
23916 KB |
n=500 |
30 |
Correct |
16 ms |
23916 KB |
n=500 |
31 |
Correct |
16 ms |
24044 KB |
n=500 |
32 |
Correct |
16 ms |
23916 KB |
n=500 |
33 |
Correct |
16 ms |
23920 KB |
n=500 |
34 |
Correct |
16 ms |
23916 KB |
n=500 |
35 |
Correct |
16 ms |
23916 KB |
n=500 |
36 |
Correct |
16 ms |
23916 KB |
n=500 |
37 |
Correct |
16 ms |
23916 KB |
n=500 |
38 |
Correct |
16 ms |
23916 KB |
n=500 |
39 |
Correct |
16 ms |
23916 KB |
n=500 |
40 |
Correct |
16 ms |
23916 KB |
n=500 |
41 |
Correct |
18 ms |
23916 KB |
n=500 |
42 |
Correct |
16 ms |
23916 KB |
n=500 |
43 |
Correct |
16 ms |
23936 KB |
n=500 |
44 |
Correct |
16 ms |
23916 KB |
n=500 |
45 |
Correct |
16 ms |
23916 KB |
n=500 |
46 |
Correct |
16 ms |
23916 KB |
n=500 |
47 |
Correct |
16 ms |
23916 KB |
n=500 |
48 |
Correct |
16 ms |
23916 KB |
n=500 |
49 |
Correct |
16 ms |
23916 KB |
n=500 |
50 |
Correct |
16 ms |
23916 KB |
n=500 |
51 |
Correct |
16 ms |
23916 KB |
n=500 |
52 |
Correct |
16 ms |
23916 KB |
n=500 |
53 |
Correct |
16 ms |
23916 KB |
n=500 |
54 |
Correct |
16 ms |
23916 KB |
n=500 |
55 |
Correct |
16 ms |
23916 KB |
n=278 |
56 |
Correct |
17 ms |
23920 KB |
n=500 |
57 |
Correct |
16 ms |
23916 KB |
n=500 |
58 |
Correct |
16 ms |
23916 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
n=5 |
2 |
Correct |
16 ms |
23788 KB |
n=100 |
3 |
Correct |
16 ms |
23788 KB |
n=100 |
4 |
Correct |
16 ms |
23788 KB |
n=100 |
5 |
Correct |
16 ms |
23788 KB |
n=100 |
6 |
Correct |
17 ms |
23788 KB |
n=100 |
7 |
Correct |
15 ms |
23788 KB |
n=100 |
8 |
Correct |
16 ms |
23788 KB |
n=100 |
9 |
Correct |
15 ms |
23788 KB |
n=100 |
10 |
Correct |
15 ms |
23788 KB |
n=100 |
11 |
Correct |
16 ms |
23788 KB |
n=100 |
12 |
Correct |
17 ms |
23916 KB |
n=100 |
13 |
Correct |
15 ms |
23788 KB |
n=100 |
14 |
Correct |
16 ms |
23788 KB |
n=100 |
15 |
Correct |
16 ms |
23788 KB |
n=100 |
16 |
Correct |
15 ms |
23788 KB |
n=100 |
17 |
Correct |
15 ms |
23788 KB |
n=100 |
18 |
Correct |
15 ms |
23788 KB |
n=100 |
19 |
Correct |
16 ms |
23788 KB |
n=100 |
20 |
Correct |
16 ms |
23788 KB |
n=100 |
21 |
Correct |
16 ms |
23788 KB |
n=100 |
22 |
Correct |
16 ms |
23788 KB |
n=100 |
23 |
Correct |
15 ms |
23788 KB |
n=100 |
24 |
Correct |
15 ms |
23788 KB |
n=100 |
25 |
Correct |
16 ms |
23788 KB |
n=100 |
26 |
Correct |
16 ms |
23788 KB |
n=12 |
27 |
Correct |
18 ms |
23788 KB |
n=100 |
28 |
Correct |
17 ms |
23916 KB |
n=500 |
29 |
Correct |
16 ms |
23916 KB |
n=500 |
30 |
Correct |
16 ms |
23916 KB |
n=500 |
31 |
Correct |
16 ms |
24044 KB |
n=500 |
32 |
Correct |
16 ms |
23916 KB |
n=500 |
33 |
Correct |
16 ms |
23920 KB |
n=500 |
34 |
Correct |
16 ms |
23916 KB |
n=500 |
35 |
Correct |
16 ms |
23916 KB |
n=500 |
36 |
Correct |
16 ms |
23916 KB |
n=500 |
37 |
Correct |
16 ms |
23916 KB |
n=500 |
38 |
Correct |
16 ms |
23916 KB |
n=500 |
39 |
Correct |
16 ms |
23916 KB |
n=500 |
40 |
Correct |
16 ms |
23916 KB |
n=500 |
41 |
Correct |
18 ms |
23916 KB |
n=500 |
42 |
Correct |
16 ms |
23916 KB |
n=500 |
43 |
Correct |
16 ms |
23936 KB |
n=500 |
44 |
Correct |
16 ms |
23916 KB |
n=500 |
45 |
Correct |
16 ms |
23916 KB |
n=500 |
46 |
Correct |
16 ms |
23916 KB |
n=500 |
47 |
Correct |
16 ms |
23916 KB |
n=500 |
48 |
Correct |
16 ms |
23916 KB |
n=500 |
49 |
Correct |
16 ms |
23916 KB |
n=500 |
50 |
Correct |
16 ms |
23916 KB |
n=500 |
51 |
Correct |
16 ms |
23916 KB |
n=500 |
52 |
Correct |
16 ms |
23916 KB |
n=500 |
53 |
Correct |
16 ms |
23916 KB |
n=500 |
54 |
Correct |
16 ms |
23916 KB |
n=500 |
55 |
Correct |
16 ms |
23916 KB |
n=278 |
56 |
Correct |
17 ms |
23920 KB |
n=500 |
57 |
Correct |
16 ms |
23916 KB |
n=500 |
58 |
Correct |
16 ms |
23916 KB |
n=500 |
59 |
Correct |
18 ms |
24300 KB |
n=2000 |
60 |
Correct |
18 ms |
24428 KB |
n=2000 |
61 |
Correct |
18 ms |
24300 KB |
n=2000 |
62 |
Correct |
19 ms |
24300 KB |
n=2000 |
63 |
Correct |
19 ms |
24300 KB |
n=2000 |
64 |
Correct |
18 ms |
24300 KB |
n=2000 |
65 |
Correct |
19 ms |
24300 KB |
n=2000 |
66 |
Correct |
18 ms |
24300 KB |
n=2000 |
67 |
Correct |
19 ms |
24300 KB |
n=2000 |
68 |
Correct |
19 ms |
24300 KB |
n=2000 |
69 |
Correct |
18 ms |
24300 KB |
n=2000 |
70 |
Correct |
19 ms |
24300 KB |
n=2000 |
71 |
Correct |
17 ms |
24300 KB |
n=2000 |
72 |
Correct |
18 ms |
24300 KB |
n=2000 |
73 |
Correct |
17 ms |
24300 KB |
n=2000 |
74 |
Correct |
18 ms |
24300 KB |
n=1844 |
75 |
Correct |
19 ms |
24300 KB |
n=2000 |
76 |
Correct |
19 ms |
24300 KB |
n=2000 |
77 |
Correct |
18 ms |
24300 KB |
n=2000 |
78 |
Correct |
19 ms |
24300 KB |
n=2000 |
79 |
Correct |
18 ms |
24300 KB |
n=2000 |
80 |
Correct |
18 ms |
24428 KB |
n=2000 |
81 |
Correct |
18 ms |
24300 KB |
n=2000 |
82 |
Correct |
19 ms |
24300 KB |
n=2000 |
83 |
Correct |
18 ms |
24428 KB |
n=2000 |
84 |
Correct |
18 ms |
24300 KB |
n=2000 |
85 |
Correct |
18 ms |
24300 KB |
n=2000 |
86 |
Correct |
19 ms |
24300 KB |
n=2000 |
87 |
Correct |
19 ms |
24300 KB |
n=2000 |
88 |
Correct |
18 ms |
24428 KB |
n=2000 |
89 |
Correct |
18 ms |
24428 KB |
n=2000 |
90 |
Correct |
18 ms |
24428 KB |
n=2000 |
91 |
Correct |
17 ms |
24300 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
n=5 |
2 |
Correct |
16 ms |
23788 KB |
n=100 |
3 |
Correct |
16 ms |
23788 KB |
n=100 |
4 |
Correct |
16 ms |
23788 KB |
n=100 |
5 |
Correct |
16 ms |
23788 KB |
n=100 |
6 |
Correct |
17 ms |
23788 KB |
n=100 |
7 |
Correct |
15 ms |
23788 KB |
n=100 |
8 |
Correct |
16 ms |
23788 KB |
n=100 |
9 |
Correct |
15 ms |
23788 KB |
n=100 |
10 |
Correct |
15 ms |
23788 KB |
n=100 |
11 |
Correct |
16 ms |
23788 KB |
n=100 |
12 |
Correct |
17 ms |
23916 KB |
n=100 |
13 |
Correct |
15 ms |
23788 KB |
n=100 |
14 |
Correct |
16 ms |
23788 KB |
n=100 |
15 |
Correct |
16 ms |
23788 KB |
n=100 |
16 |
Correct |
15 ms |
23788 KB |
n=100 |
17 |
Correct |
15 ms |
23788 KB |
n=100 |
18 |
Correct |
15 ms |
23788 KB |
n=100 |
19 |
Correct |
16 ms |
23788 KB |
n=100 |
20 |
Correct |
16 ms |
23788 KB |
n=100 |
21 |
Correct |
16 ms |
23788 KB |
n=100 |
22 |
Correct |
16 ms |
23788 KB |
n=100 |
23 |
Correct |
15 ms |
23788 KB |
n=100 |
24 |
Correct |
15 ms |
23788 KB |
n=100 |
25 |
Correct |
16 ms |
23788 KB |
n=100 |
26 |
Correct |
16 ms |
23788 KB |
n=12 |
27 |
Correct |
18 ms |
23788 KB |
n=100 |
28 |
Correct |
17 ms |
23916 KB |
n=500 |
29 |
Correct |
16 ms |
23916 KB |
n=500 |
30 |
Correct |
16 ms |
23916 KB |
n=500 |
31 |
Correct |
16 ms |
24044 KB |
n=500 |
32 |
Correct |
16 ms |
23916 KB |
n=500 |
33 |
Correct |
16 ms |
23920 KB |
n=500 |
34 |
Correct |
16 ms |
23916 KB |
n=500 |
35 |
Correct |
16 ms |
23916 KB |
n=500 |
36 |
Correct |
16 ms |
23916 KB |
n=500 |
37 |
Correct |
16 ms |
23916 KB |
n=500 |
38 |
Correct |
16 ms |
23916 KB |
n=500 |
39 |
Correct |
16 ms |
23916 KB |
n=500 |
40 |
Correct |
16 ms |
23916 KB |
n=500 |
41 |
Correct |
18 ms |
23916 KB |
n=500 |
42 |
Correct |
16 ms |
23916 KB |
n=500 |
43 |
Correct |
16 ms |
23936 KB |
n=500 |
44 |
Correct |
16 ms |
23916 KB |
n=500 |
45 |
Correct |
16 ms |
23916 KB |
n=500 |
46 |
Correct |
16 ms |
23916 KB |
n=500 |
47 |
Correct |
16 ms |
23916 KB |
n=500 |
48 |
Correct |
16 ms |
23916 KB |
n=500 |
49 |
Correct |
16 ms |
23916 KB |
n=500 |
50 |
Correct |
16 ms |
23916 KB |
n=500 |
51 |
Correct |
16 ms |
23916 KB |
n=500 |
52 |
Correct |
16 ms |
23916 KB |
n=500 |
53 |
Correct |
16 ms |
23916 KB |
n=500 |
54 |
Correct |
16 ms |
23916 KB |
n=500 |
55 |
Correct |
16 ms |
23916 KB |
n=278 |
56 |
Correct |
17 ms |
23920 KB |
n=500 |
57 |
Correct |
16 ms |
23916 KB |
n=500 |
58 |
Correct |
16 ms |
23916 KB |
n=500 |
59 |
Correct |
18 ms |
24300 KB |
n=2000 |
60 |
Correct |
18 ms |
24428 KB |
n=2000 |
61 |
Correct |
18 ms |
24300 KB |
n=2000 |
62 |
Correct |
19 ms |
24300 KB |
n=2000 |
63 |
Correct |
19 ms |
24300 KB |
n=2000 |
64 |
Correct |
18 ms |
24300 KB |
n=2000 |
65 |
Correct |
19 ms |
24300 KB |
n=2000 |
66 |
Correct |
18 ms |
24300 KB |
n=2000 |
67 |
Correct |
19 ms |
24300 KB |
n=2000 |
68 |
Correct |
19 ms |
24300 KB |
n=2000 |
69 |
Correct |
18 ms |
24300 KB |
n=2000 |
70 |
Correct |
19 ms |
24300 KB |
n=2000 |
71 |
Correct |
17 ms |
24300 KB |
n=2000 |
72 |
Correct |
18 ms |
24300 KB |
n=2000 |
73 |
Correct |
17 ms |
24300 KB |
n=2000 |
74 |
Correct |
18 ms |
24300 KB |
n=1844 |
75 |
Correct |
19 ms |
24300 KB |
n=2000 |
76 |
Correct |
19 ms |
24300 KB |
n=2000 |
77 |
Correct |
18 ms |
24300 KB |
n=2000 |
78 |
Correct |
19 ms |
24300 KB |
n=2000 |
79 |
Correct |
18 ms |
24300 KB |
n=2000 |
80 |
Correct |
18 ms |
24428 KB |
n=2000 |
81 |
Correct |
18 ms |
24300 KB |
n=2000 |
82 |
Correct |
19 ms |
24300 KB |
n=2000 |
83 |
Correct |
18 ms |
24428 KB |
n=2000 |
84 |
Correct |
18 ms |
24300 KB |
n=2000 |
85 |
Correct |
18 ms |
24300 KB |
n=2000 |
86 |
Correct |
19 ms |
24300 KB |
n=2000 |
87 |
Correct |
19 ms |
24300 KB |
n=2000 |
88 |
Correct |
18 ms |
24428 KB |
n=2000 |
89 |
Correct |
18 ms |
24428 KB |
n=2000 |
90 |
Correct |
18 ms |
24428 KB |
n=2000 |
91 |
Correct |
17 ms |
24300 KB |
n=2000 |
92 |
Correct |
768 ms |
73836 KB |
n=200000 |
93 |
Correct |
1105 ms |
78828 KB |
n=200000 |
94 |
Correct |
1029 ms |
82028 KB |
n=200000 |
95 |
Correct |
735 ms |
73832 KB |
n=200000 |
96 |
Correct |
710 ms |
73644 KB |
n=200000 |
97 |
Correct |
1065 ms |
77792 KB |
n=200000 |
98 |
Correct |
695 ms |
73568 KB |
n=200000 |
99 |
Correct |
896 ms |
73756 KB |
n=200000 |
100 |
Correct |
723 ms |
73572 KB |
n=200000 |
101 |
Correct |
1004 ms |
83436 KB |
n=200000 |
102 |
Correct |
402 ms |
74732 KB |
n=200000 |
103 |
Correct |
395 ms |
74732 KB |
n=200000 |
104 |
Correct |
400 ms |
74732 KB |
n=200000 |
105 |
Correct |
397 ms |
75232 KB |
n=200000 |
106 |
Correct |
432 ms |
75244 KB |
n=200000 |
107 |
Correct |
414 ms |
75244 KB |
n=200000 |
108 |
Correct |
846 ms |
73908 KB |
n=200000 |
109 |
Correct |
824 ms |
73836 KB |
n=200000 |
110 |
Correct |
838 ms |
73836 KB |
n=200000 |
111 |
Correct |
800 ms |
73056 KB |
n=200000 |
112 |
Correct |
1022 ms |
82284 KB |
n=200000 |
113 |
Correct |
1087 ms |
77676 KB |
n=200000 |
114 |
Correct |
761 ms |
73312 KB |
n=200000 |
115 |
Correct |
1145 ms |
75684 KB |
n=200000 |
116 |
Correct |
676 ms |
73800 KB |
n=200000 |
117 |
Correct |
999 ms |
82656 KB |
n=200000 |
118 |
Correct |
1074 ms |
76780 KB |
n=200000 |
119 |
Correct |
667 ms |
73696 KB |
n=200000 |
120 |
Correct |
974 ms |
82316 KB |
n=200000 |
121 |
Correct |
936 ms |
82284 KB |
n=200000 |
122 |
Correct |
956 ms |
82668 KB |
n=200000 |
123 |
Correct |
399 ms |
74988 KB |
n=200000 |
124 |
Correct |
237 ms |
38764 KB |
n=25264 |