#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 2000 + 10;
const int mod = 1e9 + 7;
const int inf = 1e9;
const int LOG = 17;
vector<int>g[N];
int up[N][LOG],in[N],out[N],timer = 0,a[N],st[N * 4];
void dfs(int x,int par) {
in[x] = ++timer;
up[x][0] = par;
for(int j = 1; j < LOG; j++) up[x][j] = up[up[x][j - 1]][j - 1];
for(auto X : g[x]) {
if(X != par) {
dfs(X,x);
}
}
out[x] = timer;
}
bool inn(int u,int v) {
return in[u] <= in[v] && out[u] >= out[v];
}
int lca(int u,int v) {
if(u == inf) return v;
if(v == inf) return u;
if(inn(u,v)) return u;
if(inn(v,u)) return v;
for(int j = LOG - 1; j >= 0; j--) {
if(up[u][j] > 0 && !inn(up[u][j],v)) u = up[u][j];
}
return up[u][0];
}
void build(int node,int tl,int tr) {
if(tl == tr) {
st[node] = a[tl];
return;
}
int mid = (tl + tr) / 2;
build(node * 2,tl,mid);
build(node * 2 + 1,mid + 1,tr);
st[node] = lca(st[node * 2],st[node * 2 + 1]);
}
void modify(int node,int tl,int tr,int i,int v) {
if(tl > i || tr < i) return;
if(tl == tr) {
st[node] = v;
return;
}
int mid = (tl + tr) / 2;
modify(node * 2,tl,mid,i,v);
modify(node * 2 + 1,mid + 1,tr,i,v);
st[node] = lca(st[node * 2],st[node * 2 + 1]);
}
int get(int node,int tl,int tr,int l,int r) {
if(tl > r || tr < l) return inf;
if(tl >= l && tr <= r) return st[node];
int mid = (tl + tr) / 2;
return lca(get(node * 2,tl,mid,l,r),get(node * 2 + 1,mid + 1,tr,l,r));
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m,q;
cin >> n >> m >> q;
for(int i = 1; i <= n - 1; i++) {
int u,v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
dfs(1,0);
for(int i = 1; i <= m; i++) cin >> a[i];
build(1,1,m);
while(q--) {
int type;
cin >> type;
if(type == 1) {
int i,v;
cin >> i >> v;
modify(1,1,m,i,v);
a[i] = v;
}else {
int l,r,v;
cin >> l >> r >> v;
int L = -1,R = -1;
for(int i = l; i + 1 <= r; i++) {
if(get(1,1,m,i,i + 1) == v) {
L = i;
R = i + 1;
break;
}
}
for(int i = l; i <= r; i++) if(a[i] == v) L = i,R = i;
cout << L << " " << R << "\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n=5 |
2 |
Correct |
1 ms |
344 KB |
n=100 |
3 |
Correct |
0 ms |
512 KB |
n=100 |
4 |
Correct |
1 ms |
348 KB |
n=100 |
5 |
Correct |
1 ms |
348 KB |
n=100 |
6 |
Correct |
1 ms |
348 KB |
n=100 |
7 |
Correct |
1 ms |
348 KB |
n=100 |
8 |
Correct |
1 ms |
348 KB |
n=100 |
9 |
Correct |
1 ms |
348 KB |
n=100 |
10 |
Correct |
0 ms |
348 KB |
n=100 |
11 |
Correct |
0 ms |
348 KB |
n=100 |
12 |
Correct |
0 ms |
348 KB |
n=100 |
13 |
Correct |
0 ms |
344 KB |
n=100 |
14 |
Correct |
1 ms |
348 KB |
n=100 |
15 |
Correct |
1 ms |
348 KB |
n=100 |
16 |
Correct |
0 ms |
348 KB |
n=100 |
17 |
Correct |
1 ms |
508 KB |
n=100 |
18 |
Correct |
1 ms |
348 KB |
n=100 |
19 |
Correct |
0 ms |
348 KB |
n=100 |
20 |
Correct |
1 ms |
348 KB |
n=100 |
21 |
Correct |
0 ms |
344 KB |
n=100 |
22 |
Correct |
1 ms |
348 KB |
n=100 |
23 |
Correct |
1 ms |
348 KB |
n=100 |
24 |
Correct |
1 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
348 KB |
n=100 |
26 |
Correct |
1 ms |
348 KB |
n=12 |
27 |
Correct |
1 ms |
348 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n=5 |
2 |
Correct |
1 ms |
344 KB |
n=100 |
3 |
Correct |
0 ms |
512 KB |
n=100 |
4 |
Correct |
1 ms |
348 KB |
n=100 |
5 |
Correct |
1 ms |
348 KB |
n=100 |
6 |
Correct |
1 ms |
348 KB |
n=100 |
7 |
Correct |
1 ms |
348 KB |
n=100 |
8 |
Correct |
1 ms |
348 KB |
n=100 |
9 |
Correct |
1 ms |
348 KB |
n=100 |
10 |
Correct |
0 ms |
348 KB |
n=100 |
11 |
Correct |
0 ms |
348 KB |
n=100 |
12 |
Correct |
0 ms |
348 KB |
n=100 |
13 |
Correct |
0 ms |
344 KB |
n=100 |
14 |
Correct |
1 ms |
348 KB |
n=100 |
15 |
Correct |
1 ms |
348 KB |
n=100 |
16 |
Correct |
0 ms |
348 KB |
n=100 |
17 |
Correct |
1 ms |
508 KB |
n=100 |
18 |
Correct |
1 ms |
348 KB |
n=100 |
19 |
Correct |
0 ms |
348 KB |
n=100 |
20 |
Correct |
1 ms |
348 KB |
n=100 |
21 |
Correct |
0 ms |
344 KB |
n=100 |
22 |
Correct |
1 ms |
348 KB |
n=100 |
23 |
Correct |
1 ms |
348 KB |
n=100 |
24 |
Correct |
1 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
348 KB |
n=100 |
26 |
Correct |
1 ms |
348 KB |
n=12 |
27 |
Correct |
1 ms |
348 KB |
n=100 |
28 |
Correct |
1 ms |
600 KB |
n=500 |
29 |
Correct |
2 ms |
604 KB |
n=500 |
30 |
Correct |
2 ms |
604 KB |
n=500 |
31 |
Correct |
2 ms |
604 KB |
n=500 |
32 |
Correct |
1 ms |
604 KB |
n=500 |
33 |
Correct |
2 ms |
604 KB |
n=500 |
34 |
Correct |
1 ms |
604 KB |
n=500 |
35 |
Correct |
2 ms |
604 KB |
n=500 |
36 |
Correct |
9 ms |
604 KB |
n=500 |
37 |
Correct |
9 ms |
604 KB |
n=500 |
38 |
Correct |
8 ms |
604 KB |
n=500 |
39 |
Correct |
5 ms |
604 KB |
n=500 |
40 |
Correct |
5 ms |
604 KB |
n=500 |
41 |
Correct |
5 ms |
600 KB |
n=500 |
42 |
Correct |
7 ms |
600 KB |
n=500 |
43 |
Correct |
5 ms |
520 KB |
n=500 |
44 |
Correct |
4 ms |
604 KB |
n=500 |
45 |
Correct |
1 ms |
520 KB |
n=500 |
46 |
Correct |
2 ms |
604 KB |
n=500 |
47 |
Correct |
2 ms |
600 KB |
n=500 |
48 |
Correct |
1 ms |
604 KB |
n=500 |
49 |
Correct |
2 ms |
604 KB |
n=500 |
50 |
Correct |
4 ms |
648 KB |
n=500 |
51 |
Correct |
4 ms |
604 KB |
n=500 |
52 |
Correct |
3 ms |
604 KB |
n=500 |
53 |
Correct |
3 ms |
604 KB |
n=500 |
54 |
Correct |
4 ms |
604 KB |
n=500 |
55 |
Correct |
1 ms |
348 KB |
n=278 |
56 |
Correct |
7 ms |
604 KB |
n=500 |
57 |
Correct |
9 ms |
604 KB |
n=500 |
58 |
Correct |
7 ms |
604 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n=5 |
2 |
Correct |
1 ms |
344 KB |
n=100 |
3 |
Correct |
0 ms |
512 KB |
n=100 |
4 |
Correct |
1 ms |
348 KB |
n=100 |
5 |
Correct |
1 ms |
348 KB |
n=100 |
6 |
Correct |
1 ms |
348 KB |
n=100 |
7 |
Correct |
1 ms |
348 KB |
n=100 |
8 |
Correct |
1 ms |
348 KB |
n=100 |
9 |
Correct |
1 ms |
348 KB |
n=100 |
10 |
Correct |
0 ms |
348 KB |
n=100 |
11 |
Correct |
0 ms |
348 KB |
n=100 |
12 |
Correct |
0 ms |
348 KB |
n=100 |
13 |
Correct |
0 ms |
344 KB |
n=100 |
14 |
Correct |
1 ms |
348 KB |
n=100 |
15 |
Correct |
1 ms |
348 KB |
n=100 |
16 |
Correct |
0 ms |
348 KB |
n=100 |
17 |
Correct |
1 ms |
508 KB |
n=100 |
18 |
Correct |
1 ms |
348 KB |
n=100 |
19 |
Correct |
0 ms |
348 KB |
n=100 |
20 |
Correct |
1 ms |
348 KB |
n=100 |
21 |
Correct |
0 ms |
344 KB |
n=100 |
22 |
Correct |
1 ms |
348 KB |
n=100 |
23 |
Correct |
1 ms |
348 KB |
n=100 |
24 |
Correct |
1 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
348 KB |
n=100 |
26 |
Correct |
1 ms |
348 KB |
n=12 |
27 |
Correct |
1 ms |
348 KB |
n=100 |
28 |
Correct |
1 ms |
600 KB |
n=500 |
29 |
Correct |
2 ms |
604 KB |
n=500 |
30 |
Correct |
2 ms |
604 KB |
n=500 |
31 |
Correct |
2 ms |
604 KB |
n=500 |
32 |
Correct |
1 ms |
604 KB |
n=500 |
33 |
Correct |
2 ms |
604 KB |
n=500 |
34 |
Correct |
1 ms |
604 KB |
n=500 |
35 |
Correct |
2 ms |
604 KB |
n=500 |
36 |
Correct |
9 ms |
604 KB |
n=500 |
37 |
Correct |
9 ms |
604 KB |
n=500 |
38 |
Correct |
8 ms |
604 KB |
n=500 |
39 |
Correct |
5 ms |
604 KB |
n=500 |
40 |
Correct |
5 ms |
604 KB |
n=500 |
41 |
Correct |
5 ms |
600 KB |
n=500 |
42 |
Correct |
7 ms |
600 KB |
n=500 |
43 |
Correct |
5 ms |
520 KB |
n=500 |
44 |
Correct |
4 ms |
604 KB |
n=500 |
45 |
Correct |
1 ms |
520 KB |
n=500 |
46 |
Correct |
2 ms |
604 KB |
n=500 |
47 |
Correct |
2 ms |
600 KB |
n=500 |
48 |
Correct |
1 ms |
604 KB |
n=500 |
49 |
Correct |
2 ms |
604 KB |
n=500 |
50 |
Correct |
4 ms |
648 KB |
n=500 |
51 |
Correct |
4 ms |
604 KB |
n=500 |
52 |
Correct |
3 ms |
604 KB |
n=500 |
53 |
Correct |
3 ms |
604 KB |
n=500 |
54 |
Correct |
4 ms |
604 KB |
n=500 |
55 |
Correct |
1 ms |
348 KB |
n=278 |
56 |
Correct |
7 ms |
604 KB |
n=500 |
57 |
Correct |
9 ms |
604 KB |
n=500 |
58 |
Correct |
7 ms |
604 KB |
n=500 |
59 |
Correct |
3 ms |
856 KB |
n=2000 |
60 |
Correct |
29 ms |
1072 KB |
n=2000 |
61 |
Correct |
30 ms |
1040 KB |
n=2000 |
62 |
Correct |
22 ms |
860 KB |
n=2000 |
63 |
Correct |
3 ms |
860 KB |
n=2000 |
64 |
Correct |
28 ms |
856 KB |
n=2000 |
65 |
Correct |
2 ms |
856 KB |
n=2000 |
66 |
Correct |
33 ms |
860 KB |
n=2000 |
67 |
Correct |
4 ms |
856 KB |
n=2000 |
68 |
Correct |
28 ms |
860 KB |
n=2000 |
69 |
Correct |
222 ms |
980 KB |
n=2000 |
70 |
Correct |
181 ms |
1108 KB |
n=2000 |
71 |
Correct |
162 ms |
860 KB |
n=2000 |
72 |
Correct |
82 ms |
860 KB |
n=2000 |
73 |
Correct |
87 ms |
860 KB |
n=2000 |
74 |
Correct |
2 ms |
860 KB |
n=1844 |
75 |
Correct |
95 ms |
964 KB |
n=2000 |
76 |
Correct |
82 ms |
856 KB |
n=2000 |
77 |
Correct |
82 ms |
856 KB |
n=2000 |
78 |
Correct |
87 ms |
860 KB |
n=2000 |
79 |
Correct |
4 ms |
860 KB |
n=2000 |
80 |
Correct |
27 ms |
860 KB |
n=2000 |
81 |
Correct |
26 ms |
856 KB |
n=2000 |
82 |
Correct |
2 ms |
860 KB |
n=2000 |
83 |
Correct |
26 ms |
860 KB |
n=2000 |
84 |
Correct |
74 ms |
860 KB |
n=2000 |
85 |
Correct |
64 ms |
860 KB |
n=2000 |
86 |
Correct |
69 ms |
860 KB |
n=2000 |
87 |
Correct |
65 ms |
856 KB |
n=2000 |
88 |
Correct |
154 ms |
860 KB |
n=2000 |
89 |
Correct |
153 ms |
860 KB |
n=2000 |
90 |
Correct |
71 ms |
860 KB |
n=2000 |
91 |
Correct |
120 ms |
856 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n=5 |
2 |
Correct |
1 ms |
344 KB |
n=100 |
3 |
Correct |
0 ms |
512 KB |
n=100 |
4 |
Correct |
1 ms |
348 KB |
n=100 |
5 |
Correct |
1 ms |
348 KB |
n=100 |
6 |
Correct |
1 ms |
348 KB |
n=100 |
7 |
Correct |
1 ms |
348 KB |
n=100 |
8 |
Correct |
1 ms |
348 KB |
n=100 |
9 |
Correct |
1 ms |
348 KB |
n=100 |
10 |
Correct |
0 ms |
348 KB |
n=100 |
11 |
Correct |
0 ms |
348 KB |
n=100 |
12 |
Correct |
0 ms |
348 KB |
n=100 |
13 |
Correct |
0 ms |
344 KB |
n=100 |
14 |
Correct |
1 ms |
348 KB |
n=100 |
15 |
Correct |
1 ms |
348 KB |
n=100 |
16 |
Correct |
0 ms |
348 KB |
n=100 |
17 |
Correct |
1 ms |
508 KB |
n=100 |
18 |
Correct |
1 ms |
348 KB |
n=100 |
19 |
Correct |
0 ms |
348 KB |
n=100 |
20 |
Correct |
1 ms |
348 KB |
n=100 |
21 |
Correct |
0 ms |
344 KB |
n=100 |
22 |
Correct |
1 ms |
348 KB |
n=100 |
23 |
Correct |
1 ms |
348 KB |
n=100 |
24 |
Correct |
1 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
348 KB |
n=100 |
26 |
Correct |
1 ms |
348 KB |
n=12 |
27 |
Correct |
1 ms |
348 KB |
n=100 |
28 |
Correct |
1 ms |
600 KB |
n=500 |
29 |
Correct |
2 ms |
604 KB |
n=500 |
30 |
Correct |
2 ms |
604 KB |
n=500 |
31 |
Correct |
2 ms |
604 KB |
n=500 |
32 |
Correct |
1 ms |
604 KB |
n=500 |
33 |
Correct |
2 ms |
604 KB |
n=500 |
34 |
Correct |
1 ms |
604 KB |
n=500 |
35 |
Correct |
2 ms |
604 KB |
n=500 |
36 |
Correct |
9 ms |
604 KB |
n=500 |
37 |
Correct |
9 ms |
604 KB |
n=500 |
38 |
Correct |
8 ms |
604 KB |
n=500 |
39 |
Correct |
5 ms |
604 KB |
n=500 |
40 |
Correct |
5 ms |
604 KB |
n=500 |
41 |
Correct |
5 ms |
600 KB |
n=500 |
42 |
Correct |
7 ms |
600 KB |
n=500 |
43 |
Correct |
5 ms |
520 KB |
n=500 |
44 |
Correct |
4 ms |
604 KB |
n=500 |
45 |
Correct |
1 ms |
520 KB |
n=500 |
46 |
Correct |
2 ms |
604 KB |
n=500 |
47 |
Correct |
2 ms |
600 KB |
n=500 |
48 |
Correct |
1 ms |
604 KB |
n=500 |
49 |
Correct |
2 ms |
604 KB |
n=500 |
50 |
Correct |
4 ms |
648 KB |
n=500 |
51 |
Correct |
4 ms |
604 KB |
n=500 |
52 |
Correct |
3 ms |
604 KB |
n=500 |
53 |
Correct |
3 ms |
604 KB |
n=500 |
54 |
Correct |
4 ms |
604 KB |
n=500 |
55 |
Correct |
1 ms |
348 KB |
n=278 |
56 |
Correct |
7 ms |
604 KB |
n=500 |
57 |
Correct |
9 ms |
604 KB |
n=500 |
58 |
Correct |
7 ms |
604 KB |
n=500 |
59 |
Correct |
3 ms |
856 KB |
n=2000 |
60 |
Correct |
29 ms |
1072 KB |
n=2000 |
61 |
Correct |
30 ms |
1040 KB |
n=2000 |
62 |
Correct |
22 ms |
860 KB |
n=2000 |
63 |
Correct |
3 ms |
860 KB |
n=2000 |
64 |
Correct |
28 ms |
856 KB |
n=2000 |
65 |
Correct |
2 ms |
856 KB |
n=2000 |
66 |
Correct |
33 ms |
860 KB |
n=2000 |
67 |
Correct |
4 ms |
856 KB |
n=2000 |
68 |
Correct |
28 ms |
860 KB |
n=2000 |
69 |
Correct |
222 ms |
980 KB |
n=2000 |
70 |
Correct |
181 ms |
1108 KB |
n=2000 |
71 |
Correct |
162 ms |
860 KB |
n=2000 |
72 |
Correct |
82 ms |
860 KB |
n=2000 |
73 |
Correct |
87 ms |
860 KB |
n=2000 |
74 |
Correct |
2 ms |
860 KB |
n=1844 |
75 |
Correct |
95 ms |
964 KB |
n=2000 |
76 |
Correct |
82 ms |
856 KB |
n=2000 |
77 |
Correct |
82 ms |
856 KB |
n=2000 |
78 |
Correct |
87 ms |
860 KB |
n=2000 |
79 |
Correct |
4 ms |
860 KB |
n=2000 |
80 |
Correct |
27 ms |
860 KB |
n=2000 |
81 |
Correct |
26 ms |
856 KB |
n=2000 |
82 |
Correct |
2 ms |
860 KB |
n=2000 |
83 |
Correct |
26 ms |
860 KB |
n=2000 |
84 |
Correct |
74 ms |
860 KB |
n=2000 |
85 |
Correct |
64 ms |
860 KB |
n=2000 |
86 |
Correct |
69 ms |
860 KB |
n=2000 |
87 |
Correct |
65 ms |
856 KB |
n=2000 |
88 |
Correct |
154 ms |
860 KB |
n=2000 |
89 |
Correct |
153 ms |
860 KB |
n=2000 |
90 |
Correct |
71 ms |
860 KB |
n=2000 |
91 |
Correct |
120 ms |
856 KB |
n=2000 |
92 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
93 |
Halted |
0 ms |
0 KB |
- |