// eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee //
// 271828___182845__904523__53602__ //
// 87___47____13______52____66__24_ //
// 97___75____72______47____09___36 //
// 999595_____74______96____69___67 //
// 62___77____24______07____66__30_ //
// 35___35____47______59____45713__ //
// eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee //
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_map>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
const ll mod = 1e9 + 7, inf = 1e18;
vector<int> a, tin, tout;
vector<vector<int>> gp, up;
vector<set<pair<int, int>>> vst;
int n, m, q, timer = 0;
void dfs(int u, int p) {
tin[u] = timer++;
up[u][0] = p;
for (int i = 1; i < 20; ++i) up[u][i] = up[up[u][i - 1]][i - 1];
for (int& v : gp[u]) {
if (v != p) dfs(v, u);
}
tout[u] = timer++;
}
bool isok(int u, int v) {
return tin[u] <= tin[v] && tout[u] >= tout[v];
}
int lca(int u, int v) {
if (isok(u, v)) return u;
if (isok(v, u)) return v;
for (int i = 19; i >= 0; --i) {
if (!isok(up[u][i], v)) u = up[u][i];
}
return up[u][0];
}
void solve() {
cin >> n >> m >> q;
tin = tout = vector<int>(n);
a = vector<int>(m);
gp = vector<vector<int>>(n);
up = vector<vector<int>>(n, vector<int>(20));
vst = vector<set<pair<int, int>>>(n);
for (int i = 1; i < n; ++i) {
int u, v; cin >> u >> v;
gp[--u].push_back(--v);
gp[v].push_back(u);
}
for (int i = 0; i < m; ++i) cin >> a[i], --a[i], vst[a[i]].insert({ i, i });
dfs(0, 0);
for (int i = 0; i < m - 1; ++i) vst[lca(a[i], a[i + 1])].insert({ i, i + 1 });
while (q--) {
int type; cin >> type;
if (type == 2) {
int l, r, v; cin >> l >> r >> v;
--l, --r, --v;
auto it = vst[v].lower_bound({ l, l });
if (it == vst[v].end()) {
cout << "-1 -1\n";
continue;
}
pair<int, int> p = *it;
if (p.second <= r) cout << p.first + 1 << ' ' << p.second + 1 << "\n";
else cout << "-1 -1\n";
}
else {
int i, val; cin >> i >> val;
--i, --val;
int v = a[i];
vst[v].erase({ i, i });
if (i) {
vst[lca(a[i], a[i - 1])].erase({ i - 1, i });
vst[lca(val, a[i - 1])].insert({ i - 1, i });
}
if (i < m - 1) {
vst[lca(a[i], a[i + 1])].erase({ i, i + 1 });
vst[lca(val, a[i + 1])].insert({ i, i + 1 });
}
vst[val].insert({ i, i });
a[i] = val;
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
//int _; cin >> _; while (_--)
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=5 |
2 |
Correct |
1 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
340 KB |
n=100 |
4 |
Correct |
1 ms |
296 KB |
n=100 |
5 |
Correct |
1 ms |
340 KB |
n=100 |
6 |
Correct |
1 ms |
340 KB |
n=100 |
7 |
Correct |
1 ms |
324 KB |
n=100 |
8 |
Correct |
1 ms |
340 KB |
n=100 |
9 |
Correct |
1 ms |
340 KB |
n=100 |
10 |
Correct |
1 ms |
320 KB |
n=100 |
11 |
Correct |
1 ms |
340 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
1 ms |
340 KB |
n=100 |
14 |
Correct |
1 ms |
340 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
1 ms |
340 KB |
n=100 |
17 |
Correct |
1 ms |
316 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
1 ms |
340 KB |
n=100 |
20 |
Correct |
1 ms |
320 KB |
n=100 |
21 |
Correct |
1 ms |
320 KB |
n=100 |
22 |
Correct |
1 ms |
340 KB |
n=100 |
23 |
Correct |
1 ms |
340 KB |
n=100 |
24 |
Correct |
1 ms |
340 KB |
n=100 |
25 |
Correct |
1 ms |
340 KB |
n=100 |
26 |
Correct |
1 ms |
212 KB |
n=12 |
27 |
Correct |
0 ms |
320 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=5 |
2 |
Correct |
1 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
340 KB |
n=100 |
4 |
Correct |
1 ms |
296 KB |
n=100 |
5 |
Correct |
1 ms |
340 KB |
n=100 |
6 |
Correct |
1 ms |
340 KB |
n=100 |
7 |
Correct |
1 ms |
324 KB |
n=100 |
8 |
Correct |
1 ms |
340 KB |
n=100 |
9 |
Correct |
1 ms |
340 KB |
n=100 |
10 |
Correct |
1 ms |
320 KB |
n=100 |
11 |
Correct |
1 ms |
340 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
1 ms |
340 KB |
n=100 |
14 |
Correct |
1 ms |
340 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
1 ms |
340 KB |
n=100 |
17 |
Correct |
1 ms |
316 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
1 ms |
340 KB |
n=100 |
20 |
Correct |
1 ms |
320 KB |
n=100 |
21 |
Correct |
1 ms |
320 KB |
n=100 |
22 |
Correct |
1 ms |
340 KB |
n=100 |
23 |
Correct |
1 ms |
340 KB |
n=100 |
24 |
Correct |
1 ms |
340 KB |
n=100 |
25 |
Correct |
1 ms |
340 KB |
n=100 |
26 |
Correct |
1 ms |
212 KB |
n=12 |
27 |
Correct |
0 ms |
320 KB |
n=100 |
28 |
Correct |
1 ms |
468 KB |
n=500 |
29 |
Correct |
1 ms |
468 KB |
n=500 |
30 |
Correct |
1 ms |
416 KB |
n=500 |
31 |
Correct |
1 ms |
468 KB |
n=500 |
32 |
Correct |
1 ms |
468 KB |
n=500 |
33 |
Correct |
1 ms |
456 KB |
n=500 |
34 |
Correct |
1 ms |
452 KB |
n=500 |
35 |
Correct |
1 ms |
468 KB |
n=500 |
36 |
Correct |
1 ms |
468 KB |
n=500 |
37 |
Correct |
1 ms |
468 KB |
n=500 |
38 |
Correct |
1 ms |
468 KB |
n=500 |
39 |
Correct |
1 ms |
468 KB |
n=500 |
40 |
Correct |
1 ms |
468 KB |
n=500 |
41 |
Correct |
1 ms |
468 KB |
n=500 |
42 |
Correct |
1 ms |
468 KB |
n=500 |
43 |
Correct |
2 ms |
468 KB |
n=500 |
44 |
Correct |
1 ms |
452 KB |
n=500 |
45 |
Correct |
1 ms |
468 KB |
n=500 |
46 |
Correct |
1 ms |
468 KB |
n=500 |
47 |
Correct |
1 ms |
468 KB |
n=500 |
48 |
Correct |
1 ms |
468 KB |
n=500 |
49 |
Correct |
1 ms |
468 KB |
n=500 |
50 |
Correct |
1 ms |
456 KB |
n=500 |
51 |
Correct |
1 ms |
468 KB |
n=500 |
52 |
Correct |
1 ms |
468 KB |
n=500 |
53 |
Correct |
2 ms |
468 KB |
n=500 |
54 |
Correct |
1 ms |
468 KB |
n=500 |
55 |
Correct |
1 ms |
340 KB |
n=278 |
56 |
Correct |
1 ms |
468 KB |
n=500 |
57 |
Correct |
1 ms |
468 KB |
n=500 |
58 |
Correct |
1 ms |
468 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=5 |
2 |
Correct |
1 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
340 KB |
n=100 |
4 |
Correct |
1 ms |
296 KB |
n=100 |
5 |
Correct |
1 ms |
340 KB |
n=100 |
6 |
Correct |
1 ms |
340 KB |
n=100 |
7 |
Correct |
1 ms |
324 KB |
n=100 |
8 |
Correct |
1 ms |
340 KB |
n=100 |
9 |
Correct |
1 ms |
340 KB |
n=100 |
10 |
Correct |
1 ms |
320 KB |
n=100 |
11 |
Correct |
1 ms |
340 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
1 ms |
340 KB |
n=100 |
14 |
Correct |
1 ms |
340 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
1 ms |
340 KB |
n=100 |
17 |
Correct |
1 ms |
316 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
1 ms |
340 KB |
n=100 |
20 |
Correct |
1 ms |
320 KB |
n=100 |
21 |
Correct |
1 ms |
320 KB |
n=100 |
22 |
Correct |
1 ms |
340 KB |
n=100 |
23 |
Correct |
1 ms |
340 KB |
n=100 |
24 |
Correct |
1 ms |
340 KB |
n=100 |
25 |
Correct |
1 ms |
340 KB |
n=100 |
26 |
Correct |
1 ms |
212 KB |
n=12 |
27 |
Correct |
0 ms |
320 KB |
n=100 |
28 |
Correct |
1 ms |
468 KB |
n=500 |
29 |
Correct |
1 ms |
468 KB |
n=500 |
30 |
Correct |
1 ms |
416 KB |
n=500 |
31 |
Correct |
1 ms |
468 KB |
n=500 |
32 |
Correct |
1 ms |
468 KB |
n=500 |
33 |
Correct |
1 ms |
456 KB |
n=500 |
34 |
Correct |
1 ms |
452 KB |
n=500 |
35 |
Correct |
1 ms |
468 KB |
n=500 |
36 |
Correct |
1 ms |
468 KB |
n=500 |
37 |
Correct |
1 ms |
468 KB |
n=500 |
38 |
Correct |
1 ms |
468 KB |
n=500 |
39 |
Correct |
1 ms |
468 KB |
n=500 |
40 |
Correct |
1 ms |
468 KB |
n=500 |
41 |
Correct |
1 ms |
468 KB |
n=500 |
42 |
Correct |
1 ms |
468 KB |
n=500 |
43 |
Correct |
2 ms |
468 KB |
n=500 |
44 |
Correct |
1 ms |
452 KB |
n=500 |
45 |
Correct |
1 ms |
468 KB |
n=500 |
46 |
Correct |
1 ms |
468 KB |
n=500 |
47 |
Correct |
1 ms |
468 KB |
n=500 |
48 |
Correct |
1 ms |
468 KB |
n=500 |
49 |
Correct |
1 ms |
468 KB |
n=500 |
50 |
Correct |
1 ms |
456 KB |
n=500 |
51 |
Correct |
1 ms |
468 KB |
n=500 |
52 |
Correct |
1 ms |
468 KB |
n=500 |
53 |
Correct |
2 ms |
468 KB |
n=500 |
54 |
Correct |
1 ms |
468 KB |
n=500 |
55 |
Correct |
1 ms |
340 KB |
n=278 |
56 |
Correct |
1 ms |
468 KB |
n=500 |
57 |
Correct |
1 ms |
468 KB |
n=500 |
58 |
Correct |
1 ms |
468 KB |
n=500 |
59 |
Correct |
3 ms |
980 KB |
n=2000 |
60 |
Correct |
3 ms |
1108 KB |
n=2000 |
61 |
Correct |
3 ms |
980 KB |
n=2000 |
62 |
Correct |
4 ms |
980 KB |
n=2000 |
63 |
Correct |
4 ms |
980 KB |
n=2000 |
64 |
Correct |
4 ms |
968 KB |
n=2000 |
65 |
Correct |
4 ms |
980 KB |
n=2000 |
66 |
Correct |
3 ms |
1072 KB |
n=2000 |
67 |
Correct |
4 ms |
980 KB |
n=2000 |
68 |
Correct |
3 ms |
972 KB |
n=2000 |
69 |
Correct |
3 ms |
980 KB |
n=2000 |
70 |
Correct |
4 ms |
980 KB |
n=2000 |
71 |
Correct |
3 ms |
968 KB |
n=2000 |
72 |
Correct |
3 ms |
976 KB |
n=2000 |
73 |
Correct |
3 ms |
940 KB |
n=2000 |
74 |
Correct |
3 ms |
904 KB |
n=1844 |
75 |
Correct |
3 ms |
980 KB |
n=2000 |
76 |
Correct |
4 ms |
980 KB |
n=2000 |
77 |
Correct |
5 ms |
980 KB |
n=2000 |
78 |
Correct |
3 ms |
980 KB |
n=2000 |
79 |
Correct |
3 ms |
972 KB |
n=2000 |
80 |
Correct |
4 ms |
1108 KB |
n=2000 |
81 |
Correct |
4 ms |
980 KB |
n=2000 |
82 |
Correct |
4 ms |
936 KB |
n=2000 |
83 |
Correct |
3 ms |
1096 KB |
n=2000 |
84 |
Correct |
3 ms |
1052 KB |
n=2000 |
85 |
Correct |
4 ms |
980 KB |
n=2000 |
86 |
Correct |
3 ms |
980 KB |
n=2000 |
87 |
Correct |
3 ms |
980 KB |
n=2000 |
88 |
Correct |
3 ms |
1108 KB |
n=2000 |
89 |
Correct |
3 ms |
1068 KB |
n=2000 |
90 |
Correct |
3 ms |
1108 KB |
n=2000 |
91 |
Correct |
3 ms |
980 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=5 |
2 |
Correct |
1 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
340 KB |
n=100 |
4 |
Correct |
1 ms |
296 KB |
n=100 |
5 |
Correct |
1 ms |
340 KB |
n=100 |
6 |
Correct |
1 ms |
340 KB |
n=100 |
7 |
Correct |
1 ms |
324 KB |
n=100 |
8 |
Correct |
1 ms |
340 KB |
n=100 |
9 |
Correct |
1 ms |
340 KB |
n=100 |
10 |
Correct |
1 ms |
320 KB |
n=100 |
11 |
Correct |
1 ms |
340 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
1 ms |
340 KB |
n=100 |
14 |
Correct |
1 ms |
340 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
1 ms |
340 KB |
n=100 |
17 |
Correct |
1 ms |
316 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
1 ms |
340 KB |
n=100 |
20 |
Correct |
1 ms |
320 KB |
n=100 |
21 |
Correct |
1 ms |
320 KB |
n=100 |
22 |
Correct |
1 ms |
340 KB |
n=100 |
23 |
Correct |
1 ms |
340 KB |
n=100 |
24 |
Correct |
1 ms |
340 KB |
n=100 |
25 |
Correct |
1 ms |
340 KB |
n=100 |
26 |
Correct |
1 ms |
212 KB |
n=12 |
27 |
Correct |
0 ms |
320 KB |
n=100 |
28 |
Correct |
1 ms |
468 KB |
n=500 |
29 |
Correct |
1 ms |
468 KB |
n=500 |
30 |
Correct |
1 ms |
416 KB |
n=500 |
31 |
Correct |
1 ms |
468 KB |
n=500 |
32 |
Correct |
1 ms |
468 KB |
n=500 |
33 |
Correct |
1 ms |
456 KB |
n=500 |
34 |
Correct |
1 ms |
452 KB |
n=500 |
35 |
Correct |
1 ms |
468 KB |
n=500 |
36 |
Correct |
1 ms |
468 KB |
n=500 |
37 |
Correct |
1 ms |
468 KB |
n=500 |
38 |
Correct |
1 ms |
468 KB |
n=500 |
39 |
Correct |
1 ms |
468 KB |
n=500 |
40 |
Correct |
1 ms |
468 KB |
n=500 |
41 |
Correct |
1 ms |
468 KB |
n=500 |
42 |
Correct |
1 ms |
468 KB |
n=500 |
43 |
Correct |
2 ms |
468 KB |
n=500 |
44 |
Correct |
1 ms |
452 KB |
n=500 |
45 |
Correct |
1 ms |
468 KB |
n=500 |
46 |
Correct |
1 ms |
468 KB |
n=500 |
47 |
Correct |
1 ms |
468 KB |
n=500 |
48 |
Correct |
1 ms |
468 KB |
n=500 |
49 |
Correct |
1 ms |
468 KB |
n=500 |
50 |
Correct |
1 ms |
456 KB |
n=500 |
51 |
Correct |
1 ms |
468 KB |
n=500 |
52 |
Correct |
1 ms |
468 KB |
n=500 |
53 |
Correct |
2 ms |
468 KB |
n=500 |
54 |
Correct |
1 ms |
468 KB |
n=500 |
55 |
Correct |
1 ms |
340 KB |
n=278 |
56 |
Correct |
1 ms |
468 KB |
n=500 |
57 |
Correct |
1 ms |
468 KB |
n=500 |
58 |
Correct |
1 ms |
468 KB |
n=500 |
59 |
Correct |
3 ms |
980 KB |
n=2000 |
60 |
Correct |
3 ms |
1108 KB |
n=2000 |
61 |
Correct |
3 ms |
980 KB |
n=2000 |
62 |
Correct |
4 ms |
980 KB |
n=2000 |
63 |
Correct |
4 ms |
980 KB |
n=2000 |
64 |
Correct |
4 ms |
968 KB |
n=2000 |
65 |
Correct |
4 ms |
980 KB |
n=2000 |
66 |
Correct |
3 ms |
1072 KB |
n=2000 |
67 |
Correct |
4 ms |
980 KB |
n=2000 |
68 |
Correct |
3 ms |
972 KB |
n=2000 |
69 |
Correct |
3 ms |
980 KB |
n=2000 |
70 |
Correct |
4 ms |
980 KB |
n=2000 |
71 |
Correct |
3 ms |
968 KB |
n=2000 |
72 |
Correct |
3 ms |
976 KB |
n=2000 |
73 |
Correct |
3 ms |
940 KB |
n=2000 |
74 |
Correct |
3 ms |
904 KB |
n=1844 |
75 |
Correct |
3 ms |
980 KB |
n=2000 |
76 |
Correct |
4 ms |
980 KB |
n=2000 |
77 |
Correct |
5 ms |
980 KB |
n=2000 |
78 |
Correct |
3 ms |
980 KB |
n=2000 |
79 |
Correct |
3 ms |
972 KB |
n=2000 |
80 |
Correct |
4 ms |
1108 KB |
n=2000 |
81 |
Correct |
4 ms |
980 KB |
n=2000 |
82 |
Correct |
4 ms |
936 KB |
n=2000 |
83 |
Correct |
3 ms |
1096 KB |
n=2000 |
84 |
Correct |
3 ms |
1052 KB |
n=2000 |
85 |
Correct |
4 ms |
980 KB |
n=2000 |
86 |
Correct |
3 ms |
980 KB |
n=2000 |
87 |
Correct |
3 ms |
980 KB |
n=2000 |
88 |
Correct |
3 ms |
1108 KB |
n=2000 |
89 |
Correct |
3 ms |
1068 KB |
n=2000 |
90 |
Correct |
3 ms |
1108 KB |
n=2000 |
91 |
Correct |
3 ms |
980 KB |
n=2000 |
92 |
Correct |
682 ms |
67644 KB |
n=200000 |
93 |
Correct |
795 ms |
71284 KB |
n=200000 |
94 |
Correct |
574 ms |
74896 KB |
n=200000 |
95 |
Correct |
639 ms |
67440 KB |
n=200000 |
96 |
Correct |
682 ms |
67424 KB |
n=200000 |
97 |
Correct |
877 ms |
70528 KB |
n=200000 |
98 |
Correct |
715 ms |
67512 KB |
n=200000 |
99 |
Correct |
867 ms |
67144 KB |
n=200000 |
100 |
Correct |
810 ms |
67788 KB |
n=200000 |
101 |
Correct |
545 ms |
76324 KB |
n=200000 |
102 |
Correct |
491 ms |
68760 KB |
n=200000 |
103 |
Correct |
491 ms |
68728 KB |
n=200000 |
104 |
Correct |
460 ms |
68548 KB |
n=200000 |
105 |
Correct |
449 ms |
68320 KB |
n=200000 |
106 |
Correct |
479 ms |
68404 KB |
n=200000 |
107 |
Correct |
463 ms |
68368 KB |
n=200000 |
108 |
Correct |
753 ms |
67380 KB |
n=200000 |
109 |
Correct |
755 ms |
67240 KB |
n=200000 |
110 |
Correct |
732 ms |
67372 KB |
n=200000 |
111 |
Correct |
717 ms |
67648 KB |
n=200000 |
112 |
Correct |
570 ms |
75088 KB |
n=200000 |
113 |
Correct |
905 ms |
70736 KB |
n=200000 |
114 |
Correct |
740 ms |
67620 KB |
n=200000 |
115 |
Correct |
1110 ms |
68428 KB |
n=200000 |
116 |
Correct |
695 ms |
67340 KB |
n=200000 |
117 |
Correct |
575 ms |
75252 KB |
n=200000 |
118 |
Correct |
964 ms |
69160 KB |
n=200000 |
119 |
Correct |
647 ms |
67244 KB |
n=200000 |
120 |
Correct |
503 ms |
75700 KB |
n=200000 |
121 |
Correct |
519 ms |
75544 KB |
n=200000 |
122 |
Correct |
582 ms |
75892 KB |
n=200000 |
123 |
Correct |
486 ms |
67732 KB |
n=200000 |
124 |
Correct |
164 ms |
16332 KB |
n=25264 |