#include <bits/stdc++.h>
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
typedef pair<int, int> ii;
const int N = 2e5 + 5;
vector<int> g[N];
int n, m, q, a[N], dep[N], par[N][20], b[N];
void dfs(int u, int p) {
par[u][0] = p;
fa (v, g[u]) if (v != p) {
dep[v] = dep[u] + 1;
dfs(v, u);
}
}
void sparse() {
fw (j, 1, 20) fw (i, 0, n) if (par[i][j - 1] != -1) {
par[i][j] = par[par[i][j - 1]][j - 1];
}
}
int getLCA(int u, int v) {
if (dep[u] < dep[v]) swap(u, v);
int diff = dep[u] - dep[v];
fw (i, 0, 20) if (diff & (1 << i)) u = par[u][i];
if (u == v) return u;
bw (i, 20, 0) if (par[u][i] != par[v][i]) {
u = par[u][i], v = par[v][i];
}
return par[u][0];
}
class SegTree {
private:
int type;
set<ii> t[N << 2];
void build(int l, int r, int x) {
if (l != r) {
int m = (l + r) >> 1;
build(l, m, x << 1), build(m + 1, r, x << 1 | 1);
}
fw (i, l, r + 1) {
if (!type) t[x].insert(ii(a[i], i));
else t[x].insert(ii(b[i], i));
}
}
void rem(int l, int r, int pos, int val, int x) {
if (l != r) {
int m = (l + r) >> 1;
if (pos <= m) rem(l, m, pos, val, x << 1);
else rem(m + 1, r, pos, val, x << 1 | 1);
}
t[x].erase(ii(val, pos));
}
void ins(int l, int r, int pos, int val, int x) {
if (l != r) {
int m = (l + r) >> 1;
if (pos <= m) ins(l, m, pos, val, x << 1);
else ins(m + 1, r, pos, val, x << 1 | 1);
}
t[x].insert(ii(val, pos));
}
int check(int l, int r, int s, int e, int val, int x) {
if (l > e || r < s) return -1;
if (s <= l && r <= e) {
auto tmp = t[x].lower_bound(ii(val, -1));
if (tmp == t[x].end()) return -1;
// cout << "check " << val << " in range " << l << " " << r << "\n";
ii lol = *tmp;
// cout << lol.fi << " " << lol.se << "\n";
if (lol.fi == val) return lol.se;
return -1;
}
int m = (l + r) >> 1;
return max(check(l, m, s, e, val, x << 1), check(m + 1, r, s, e, val, x << 1 | 1));
}
public:
int n;
void init(int _n, int _type) {
n = _n;
type = _type;
build(0, n - 1, 1);
}
void rem(int pos, int val) {
rem(0, n - 1, pos, val, 1);
}
void ins(int pos, int val) {
ins(0, n - 1, pos, val, 1);
}
int check(int l, int r, int val) {
if (l > r) return -1;
return check(0, n - 1, l, r, val, 1);
}
} st, st2;
signed main() {
#ifdef BLU
in("blu.inp");
#endif
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m >> q;
fw (i, 1, n) {
int u, v;
cin >> u >> v;
u--, v--;
g[u].pb(v), g[v].pb(u);
}
fw (i, 0, m) cin >> a[i], a[i]--;
dfs(0, -1);
sparse();
//b[i] = lca(a[i], a[i + 1])
fw (i, 0, m - 1) b[i] = getLCA(a[i], a[i + 1]);
st.init(m, 0);
st2.init(m - 1, 1);
while (q--) {
int type;
cin >> type;
if (type == 1) {
int pos, v;
cin >> pos >> v;
pos--, v--;
st.rem(pos, a[pos]);
if (pos) st2.rem(pos - 1, b[pos - 1]);
if (pos < m - 1) st2.rem(pos, b[pos]);
a[pos] = v;
st.ins(pos, a[pos]);
if (pos) {
b[pos - 1] = getLCA(a[pos - 1], a[pos]);
st2.ins(pos - 1, b[pos - 1]);
}
if (pos < m - 1) {
b[pos] = getLCA(a[pos], a[pos + 1]);
st2.ins(pos, b[pos]);
}
} else {
int l, r, v;
cin >> l >> r >> v;
l--, r--, v--;
int x = st.check(l, r, v);
if (x != -1) {
// cout << "what's cookin'\n";
cout << x + 1 << " " << x + 1 << "\n";
} else {
x = st2.check(l, r - 1, v);
if (x != -1) cout << x + 1 << " " << x + 2 << "\n";
else cout << "-1 -1\n";
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
80248 KB |
n=5 |
2 |
Correct |
77 ms |
80248 KB |
n=100 |
3 |
Correct |
76 ms |
80248 KB |
n=100 |
4 |
Correct |
76 ms |
80268 KB |
n=100 |
5 |
Correct |
75 ms |
80248 KB |
n=100 |
6 |
Correct |
75 ms |
80248 KB |
n=100 |
7 |
Correct |
75 ms |
80248 KB |
n=100 |
8 |
Correct |
76 ms |
80224 KB |
n=100 |
9 |
Correct |
76 ms |
80248 KB |
n=100 |
10 |
Correct |
76 ms |
80248 KB |
n=100 |
11 |
Correct |
76 ms |
80248 KB |
n=100 |
12 |
Correct |
76 ms |
80248 KB |
n=100 |
13 |
Correct |
75 ms |
80248 KB |
n=100 |
14 |
Correct |
76 ms |
80240 KB |
n=100 |
15 |
Correct |
79 ms |
80332 KB |
n=100 |
16 |
Correct |
76 ms |
80248 KB |
n=100 |
17 |
Correct |
75 ms |
80248 KB |
n=100 |
18 |
Correct |
75 ms |
80376 KB |
n=100 |
19 |
Correct |
78 ms |
80248 KB |
n=100 |
20 |
Correct |
76 ms |
80376 KB |
n=100 |
21 |
Correct |
76 ms |
80376 KB |
n=100 |
22 |
Correct |
77 ms |
80248 KB |
n=100 |
23 |
Correct |
76 ms |
80248 KB |
n=100 |
24 |
Correct |
75 ms |
80376 KB |
n=100 |
25 |
Correct |
76 ms |
80376 KB |
n=100 |
26 |
Correct |
74 ms |
80248 KB |
n=12 |
27 |
Correct |
76 ms |
80248 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
80248 KB |
n=5 |
2 |
Correct |
77 ms |
80248 KB |
n=100 |
3 |
Correct |
76 ms |
80248 KB |
n=100 |
4 |
Correct |
76 ms |
80268 KB |
n=100 |
5 |
Correct |
75 ms |
80248 KB |
n=100 |
6 |
Correct |
75 ms |
80248 KB |
n=100 |
7 |
Correct |
75 ms |
80248 KB |
n=100 |
8 |
Correct |
76 ms |
80224 KB |
n=100 |
9 |
Correct |
76 ms |
80248 KB |
n=100 |
10 |
Correct |
76 ms |
80248 KB |
n=100 |
11 |
Correct |
76 ms |
80248 KB |
n=100 |
12 |
Correct |
76 ms |
80248 KB |
n=100 |
13 |
Correct |
75 ms |
80248 KB |
n=100 |
14 |
Correct |
76 ms |
80240 KB |
n=100 |
15 |
Correct |
79 ms |
80332 KB |
n=100 |
16 |
Correct |
76 ms |
80248 KB |
n=100 |
17 |
Correct |
75 ms |
80248 KB |
n=100 |
18 |
Correct |
75 ms |
80376 KB |
n=100 |
19 |
Correct |
78 ms |
80248 KB |
n=100 |
20 |
Correct |
76 ms |
80376 KB |
n=100 |
21 |
Correct |
76 ms |
80376 KB |
n=100 |
22 |
Correct |
77 ms |
80248 KB |
n=100 |
23 |
Correct |
76 ms |
80248 KB |
n=100 |
24 |
Correct |
75 ms |
80376 KB |
n=100 |
25 |
Correct |
76 ms |
80376 KB |
n=100 |
26 |
Correct |
74 ms |
80248 KB |
n=12 |
27 |
Correct |
76 ms |
80248 KB |
n=100 |
28 |
Correct |
80 ms |
80732 KB |
n=500 |
29 |
Correct |
94 ms |
80760 KB |
n=500 |
30 |
Correct |
82 ms |
80760 KB |
n=500 |
31 |
Correct |
80 ms |
80760 KB |
n=500 |
32 |
Correct |
84 ms |
80888 KB |
n=500 |
33 |
Correct |
81 ms |
80760 KB |
n=500 |
34 |
Correct |
88 ms |
80760 KB |
n=500 |
35 |
Correct |
80 ms |
80760 KB |
n=500 |
36 |
Correct |
78 ms |
80680 KB |
n=500 |
37 |
Correct |
77 ms |
80788 KB |
n=500 |
38 |
Correct |
77 ms |
80760 KB |
n=500 |
39 |
Correct |
77 ms |
80696 KB |
n=500 |
40 |
Correct |
77 ms |
80760 KB |
n=500 |
41 |
Correct |
78 ms |
80740 KB |
n=500 |
42 |
Correct |
80 ms |
80760 KB |
n=500 |
43 |
Correct |
80 ms |
80760 KB |
n=500 |
44 |
Correct |
80 ms |
80760 KB |
n=500 |
45 |
Correct |
81 ms |
80752 KB |
n=500 |
46 |
Correct |
80 ms |
80760 KB |
n=500 |
47 |
Correct |
81 ms |
80760 KB |
n=500 |
48 |
Correct |
79 ms |
80760 KB |
n=500 |
49 |
Correct |
80 ms |
80744 KB |
n=500 |
50 |
Correct |
80 ms |
80760 KB |
n=500 |
51 |
Correct |
79 ms |
80760 KB |
n=500 |
52 |
Correct |
80 ms |
80760 KB |
n=500 |
53 |
Correct |
81 ms |
80760 KB |
n=500 |
54 |
Correct |
80 ms |
80760 KB |
n=500 |
55 |
Correct |
78 ms |
80732 KB |
n=278 |
56 |
Correct |
80 ms |
80788 KB |
n=500 |
57 |
Correct |
80 ms |
80760 KB |
n=500 |
58 |
Correct |
77 ms |
80856 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
80248 KB |
n=5 |
2 |
Correct |
77 ms |
80248 KB |
n=100 |
3 |
Correct |
76 ms |
80248 KB |
n=100 |
4 |
Correct |
76 ms |
80268 KB |
n=100 |
5 |
Correct |
75 ms |
80248 KB |
n=100 |
6 |
Correct |
75 ms |
80248 KB |
n=100 |
7 |
Correct |
75 ms |
80248 KB |
n=100 |
8 |
Correct |
76 ms |
80224 KB |
n=100 |
9 |
Correct |
76 ms |
80248 KB |
n=100 |
10 |
Correct |
76 ms |
80248 KB |
n=100 |
11 |
Correct |
76 ms |
80248 KB |
n=100 |
12 |
Correct |
76 ms |
80248 KB |
n=100 |
13 |
Correct |
75 ms |
80248 KB |
n=100 |
14 |
Correct |
76 ms |
80240 KB |
n=100 |
15 |
Correct |
79 ms |
80332 KB |
n=100 |
16 |
Correct |
76 ms |
80248 KB |
n=100 |
17 |
Correct |
75 ms |
80248 KB |
n=100 |
18 |
Correct |
75 ms |
80376 KB |
n=100 |
19 |
Correct |
78 ms |
80248 KB |
n=100 |
20 |
Correct |
76 ms |
80376 KB |
n=100 |
21 |
Correct |
76 ms |
80376 KB |
n=100 |
22 |
Correct |
77 ms |
80248 KB |
n=100 |
23 |
Correct |
76 ms |
80248 KB |
n=100 |
24 |
Correct |
75 ms |
80376 KB |
n=100 |
25 |
Correct |
76 ms |
80376 KB |
n=100 |
26 |
Correct |
74 ms |
80248 KB |
n=12 |
27 |
Correct |
76 ms |
80248 KB |
n=100 |
28 |
Correct |
80 ms |
80732 KB |
n=500 |
29 |
Correct |
94 ms |
80760 KB |
n=500 |
30 |
Correct |
82 ms |
80760 KB |
n=500 |
31 |
Correct |
80 ms |
80760 KB |
n=500 |
32 |
Correct |
84 ms |
80888 KB |
n=500 |
33 |
Correct |
81 ms |
80760 KB |
n=500 |
34 |
Correct |
88 ms |
80760 KB |
n=500 |
35 |
Correct |
80 ms |
80760 KB |
n=500 |
36 |
Correct |
78 ms |
80680 KB |
n=500 |
37 |
Correct |
77 ms |
80788 KB |
n=500 |
38 |
Correct |
77 ms |
80760 KB |
n=500 |
39 |
Correct |
77 ms |
80696 KB |
n=500 |
40 |
Correct |
77 ms |
80760 KB |
n=500 |
41 |
Correct |
78 ms |
80740 KB |
n=500 |
42 |
Correct |
80 ms |
80760 KB |
n=500 |
43 |
Correct |
80 ms |
80760 KB |
n=500 |
44 |
Correct |
80 ms |
80760 KB |
n=500 |
45 |
Correct |
81 ms |
80752 KB |
n=500 |
46 |
Correct |
80 ms |
80760 KB |
n=500 |
47 |
Correct |
81 ms |
80760 KB |
n=500 |
48 |
Correct |
79 ms |
80760 KB |
n=500 |
49 |
Correct |
80 ms |
80744 KB |
n=500 |
50 |
Correct |
80 ms |
80760 KB |
n=500 |
51 |
Correct |
79 ms |
80760 KB |
n=500 |
52 |
Correct |
80 ms |
80760 KB |
n=500 |
53 |
Correct |
81 ms |
80760 KB |
n=500 |
54 |
Correct |
80 ms |
80760 KB |
n=500 |
55 |
Correct |
78 ms |
80732 KB |
n=278 |
56 |
Correct |
80 ms |
80788 KB |
n=500 |
57 |
Correct |
80 ms |
80760 KB |
n=500 |
58 |
Correct |
77 ms |
80856 KB |
n=500 |
59 |
Correct |
100 ms |
82808 KB |
n=2000 |
60 |
Correct |
102 ms |
82932 KB |
n=2000 |
61 |
Correct |
104 ms |
82852 KB |
n=2000 |
62 |
Correct |
103 ms |
82816 KB |
n=2000 |
63 |
Correct |
101 ms |
82804 KB |
n=2000 |
64 |
Correct |
121 ms |
82844 KB |
n=2000 |
65 |
Correct |
119 ms |
82808 KB |
n=2000 |
66 |
Correct |
102 ms |
82808 KB |
n=2000 |
67 |
Correct |
105 ms |
82800 KB |
n=2000 |
68 |
Correct |
104 ms |
82808 KB |
n=2000 |
69 |
Correct |
85 ms |
82780 KB |
n=2000 |
70 |
Correct |
85 ms |
82808 KB |
n=2000 |
71 |
Correct |
85 ms |
82808 KB |
n=2000 |
72 |
Correct |
88 ms |
82804 KB |
n=2000 |
73 |
Correct |
87 ms |
82808 KB |
n=2000 |
74 |
Correct |
97 ms |
82620 KB |
n=1844 |
75 |
Correct |
101 ms |
82724 KB |
n=2000 |
76 |
Correct |
100 ms |
82808 KB |
n=2000 |
77 |
Correct |
100 ms |
82808 KB |
n=2000 |
78 |
Correct |
100 ms |
82808 KB |
n=2000 |
79 |
Correct |
100 ms |
82808 KB |
n=2000 |
80 |
Correct |
102 ms |
82808 KB |
n=2000 |
81 |
Correct |
104 ms |
82876 KB |
n=2000 |
82 |
Correct |
100 ms |
82868 KB |
n=2000 |
83 |
Correct |
102 ms |
82808 KB |
n=2000 |
84 |
Correct |
99 ms |
82808 KB |
n=2000 |
85 |
Correct |
103 ms |
82808 KB |
n=2000 |
86 |
Correct |
104 ms |
82820 KB |
n=2000 |
87 |
Correct |
101 ms |
82808 KB |
n=2000 |
88 |
Correct |
102 ms |
82928 KB |
n=2000 |
89 |
Correct |
103 ms |
82936 KB |
n=2000 |
90 |
Correct |
99 ms |
82772 KB |
n=2000 |
91 |
Correct |
86 ms |
82808 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
80248 KB |
n=5 |
2 |
Correct |
77 ms |
80248 KB |
n=100 |
3 |
Correct |
76 ms |
80248 KB |
n=100 |
4 |
Correct |
76 ms |
80268 KB |
n=100 |
5 |
Correct |
75 ms |
80248 KB |
n=100 |
6 |
Correct |
75 ms |
80248 KB |
n=100 |
7 |
Correct |
75 ms |
80248 KB |
n=100 |
8 |
Correct |
76 ms |
80224 KB |
n=100 |
9 |
Correct |
76 ms |
80248 KB |
n=100 |
10 |
Correct |
76 ms |
80248 KB |
n=100 |
11 |
Correct |
76 ms |
80248 KB |
n=100 |
12 |
Correct |
76 ms |
80248 KB |
n=100 |
13 |
Correct |
75 ms |
80248 KB |
n=100 |
14 |
Correct |
76 ms |
80240 KB |
n=100 |
15 |
Correct |
79 ms |
80332 KB |
n=100 |
16 |
Correct |
76 ms |
80248 KB |
n=100 |
17 |
Correct |
75 ms |
80248 KB |
n=100 |
18 |
Correct |
75 ms |
80376 KB |
n=100 |
19 |
Correct |
78 ms |
80248 KB |
n=100 |
20 |
Correct |
76 ms |
80376 KB |
n=100 |
21 |
Correct |
76 ms |
80376 KB |
n=100 |
22 |
Correct |
77 ms |
80248 KB |
n=100 |
23 |
Correct |
76 ms |
80248 KB |
n=100 |
24 |
Correct |
75 ms |
80376 KB |
n=100 |
25 |
Correct |
76 ms |
80376 KB |
n=100 |
26 |
Correct |
74 ms |
80248 KB |
n=12 |
27 |
Correct |
76 ms |
80248 KB |
n=100 |
28 |
Correct |
80 ms |
80732 KB |
n=500 |
29 |
Correct |
94 ms |
80760 KB |
n=500 |
30 |
Correct |
82 ms |
80760 KB |
n=500 |
31 |
Correct |
80 ms |
80760 KB |
n=500 |
32 |
Correct |
84 ms |
80888 KB |
n=500 |
33 |
Correct |
81 ms |
80760 KB |
n=500 |
34 |
Correct |
88 ms |
80760 KB |
n=500 |
35 |
Correct |
80 ms |
80760 KB |
n=500 |
36 |
Correct |
78 ms |
80680 KB |
n=500 |
37 |
Correct |
77 ms |
80788 KB |
n=500 |
38 |
Correct |
77 ms |
80760 KB |
n=500 |
39 |
Correct |
77 ms |
80696 KB |
n=500 |
40 |
Correct |
77 ms |
80760 KB |
n=500 |
41 |
Correct |
78 ms |
80740 KB |
n=500 |
42 |
Correct |
80 ms |
80760 KB |
n=500 |
43 |
Correct |
80 ms |
80760 KB |
n=500 |
44 |
Correct |
80 ms |
80760 KB |
n=500 |
45 |
Correct |
81 ms |
80752 KB |
n=500 |
46 |
Correct |
80 ms |
80760 KB |
n=500 |
47 |
Correct |
81 ms |
80760 KB |
n=500 |
48 |
Correct |
79 ms |
80760 KB |
n=500 |
49 |
Correct |
80 ms |
80744 KB |
n=500 |
50 |
Correct |
80 ms |
80760 KB |
n=500 |
51 |
Correct |
79 ms |
80760 KB |
n=500 |
52 |
Correct |
80 ms |
80760 KB |
n=500 |
53 |
Correct |
81 ms |
80760 KB |
n=500 |
54 |
Correct |
80 ms |
80760 KB |
n=500 |
55 |
Correct |
78 ms |
80732 KB |
n=278 |
56 |
Correct |
80 ms |
80788 KB |
n=500 |
57 |
Correct |
80 ms |
80760 KB |
n=500 |
58 |
Correct |
77 ms |
80856 KB |
n=500 |
59 |
Correct |
100 ms |
82808 KB |
n=2000 |
60 |
Correct |
102 ms |
82932 KB |
n=2000 |
61 |
Correct |
104 ms |
82852 KB |
n=2000 |
62 |
Correct |
103 ms |
82816 KB |
n=2000 |
63 |
Correct |
101 ms |
82804 KB |
n=2000 |
64 |
Correct |
121 ms |
82844 KB |
n=2000 |
65 |
Correct |
119 ms |
82808 KB |
n=2000 |
66 |
Correct |
102 ms |
82808 KB |
n=2000 |
67 |
Correct |
105 ms |
82800 KB |
n=2000 |
68 |
Correct |
104 ms |
82808 KB |
n=2000 |
69 |
Correct |
85 ms |
82780 KB |
n=2000 |
70 |
Correct |
85 ms |
82808 KB |
n=2000 |
71 |
Correct |
85 ms |
82808 KB |
n=2000 |
72 |
Correct |
88 ms |
82804 KB |
n=2000 |
73 |
Correct |
87 ms |
82808 KB |
n=2000 |
74 |
Correct |
97 ms |
82620 KB |
n=1844 |
75 |
Correct |
101 ms |
82724 KB |
n=2000 |
76 |
Correct |
100 ms |
82808 KB |
n=2000 |
77 |
Correct |
100 ms |
82808 KB |
n=2000 |
78 |
Correct |
100 ms |
82808 KB |
n=2000 |
79 |
Correct |
100 ms |
82808 KB |
n=2000 |
80 |
Correct |
102 ms |
82808 KB |
n=2000 |
81 |
Correct |
104 ms |
82876 KB |
n=2000 |
82 |
Correct |
100 ms |
82868 KB |
n=2000 |
83 |
Correct |
102 ms |
82808 KB |
n=2000 |
84 |
Correct |
99 ms |
82808 KB |
n=2000 |
85 |
Correct |
103 ms |
82808 KB |
n=2000 |
86 |
Correct |
104 ms |
82820 KB |
n=2000 |
87 |
Correct |
101 ms |
82808 KB |
n=2000 |
88 |
Correct |
102 ms |
82928 KB |
n=2000 |
89 |
Correct |
103 ms |
82936 KB |
n=2000 |
90 |
Correct |
99 ms |
82772 KB |
n=2000 |
91 |
Correct |
86 ms |
82808 KB |
n=2000 |
92 |
Runtime error |
787 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
93 |
Halted |
0 ms |
0 KB |
- |