/// adil sultanov | vonat1us
#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:36777216")
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
#define all(z) (z).begin(), (z).end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;
void fin() {
#ifdef AM
freopen(".in", "r", stdin);
#endif
}
const bool flag = 0;
const int N = 2e5+10;
const int K = 18;
set<int> s[N], one[N];
vector<int> adj[N];
int up[K][N], tin[N], tout[N], tmr;
void dfs(int x = 0, int p = 0) {
up[0][x] = p;
for (int i = 1; i < K; ++i) {
up[i][x] = up[i-1][up[i-1][x]];
}
tin[x] = ++tmr;
for (int to : adj[x]) {
if (to != p) {
dfs(to, x);
}
}
tout[x] = tmr;
}
bool upper(int a, int b) {
return tin[a] <= tin[b] && tout[a] >= tout[b];
}
int lca(int a, int b) {
if (upper(a, b)) return a;
if (upper(b, a)) return b;
for (int i = K-1; ~i; --i) {
if (!upper(up[i][a], b)) {
a = up[i][a];
}
}
return up[0][a];
}
void ma1n() {
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
u--, v--;
adj[u].pb(v);
adj[v].pb(u);
}
vector<int> a(m);
for (int& x : a) cin >> x, x--;
dfs();
for (int i = 0; i < m; ++i) {
one[a[i]].insert(i);
}
for (int i = 0; i < m-1; ++i) {
int l = lca(a[i+1], a[i]);
s[l].insert(i);
}
for (int i = 0; i < q; ++i) {
int t;
cin >> t;
if (t == 1) {
int pos, v;
cin >> pos >> v;
pos--, v--;
one[a[pos]].erase(pos);
if (pos+1 < n) s[lca(a[pos], a[pos+1])].erase(pos);
if (pos > 0) s[lca(a[pos-1], a[pos])].erase(pos-1);
a[pos] = v;
one[a[pos]].insert(pos);
if (pos+1 < n) s[lca(a[pos], a[pos+1])].insert(pos);
if (pos > 0) s[lca(a[pos-1], a[pos])].insert(pos-1);
} else {
int l, r, v;
cin >> l >> r >> v;
l--, r--, v--;
auto it = one[v].lower_bound(l);
if (it != one[v].end() && *it <= r) {
cout << *it+1 << " " << *it+1 << "\n";
continue;
}
it = s[v].lower_bound(l);
if (it != s[v].end() && *it < r) {
cout << *it+1 << " " << *it +2 << "\n";
} else {
cout << "-1 -1\n";
}
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr), fin();
int ts = 1;
if (flag) {
cin >> ts;
}
while (ts--) {
ma1n();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23784 KB |
n=5 |
2 |
Correct |
12 ms |
23932 KB |
n=100 |
3 |
Correct |
15 ms |
23792 KB |
n=100 |
4 |
Correct |
14 ms |
23884 KB |
n=100 |
5 |
Correct |
13 ms |
23884 KB |
n=100 |
6 |
Correct |
13 ms |
23928 KB |
n=100 |
7 |
Correct |
13 ms |
23920 KB |
n=100 |
8 |
Correct |
14 ms |
23884 KB |
n=100 |
9 |
Correct |
13 ms |
23892 KB |
n=100 |
10 |
Correct |
13 ms |
23876 KB |
n=100 |
11 |
Correct |
14 ms |
23884 KB |
n=100 |
12 |
Correct |
13 ms |
23884 KB |
n=100 |
13 |
Correct |
14 ms |
23884 KB |
n=100 |
14 |
Correct |
14 ms |
23800 KB |
n=100 |
15 |
Correct |
13 ms |
23884 KB |
n=100 |
16 |
Correct |
13 ms |
23816 KB |
n=100 |
17 |
Correct |
13 ms |
23932 KB |
n=100 |
18 |
Correct |
13 ms |
23928 KB |
n=100 |
19 |
Correct |
13 ms |
23884 KB |
n=100 |
20 |
Correct |
13 ms |
23884 KB |
n=100 |
21 |
Correct |
13 ms |
23884 KB |
n=100 |
22 |
Correct |
13 ms |
23884 KB |
n=100 |
23 |
Correct |
13 ms |
23940 KB |
n=100 |
24 |
Correct |
14 ms |
23900 KB |
n=100 |
25 |
Correct |
13 ms |
23884 KB |
n=100 |
26 |
Correct |
13 ms |
23884 KB |
n=12 |
27 |
Correct |
13 ms |
23928 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23784 KB |
n=5 |
2 |
Correct |
12 ms |
23932 KB |
n=100 |
3 |
Correct |
15 ms |
23792 KB |
n=100 |
4 |
Correct |
14 ms |
23884 KB |
n=100 |
5 |
Correct |
13 ms |
23884 KB |
n=100 |
6 |
Correct |
13 ms |
23928 KB |
n=100 |
7 |
Correct |
13 ms |
23920 KB |
n=100 |
8 |
Correct |
14 ms |
23884 KB |
n=100 |
9 |
Correct |
13 ms |
23892 KB |
n=100 |
10 |
Correct |
13 ms |
23876 KB |
n=100 |
11 |
Correct |
14 ms |
23884 KB |
n=100 |
12 |
Correct |
13 ms |
23884 KB |
n=100 |
13 |
Correct |
14 ms |
23884 KB |
n=100 |
14 |
Correct |
14 ms |
23800 KB |
n=100 |
15 |
Correct |
13 ms |
23884 KB |
n=100 |
16 |
Correct |
13 ms |
23816 KB |
n=100 |
17 |
Correct |
13 ms |
23932 KB |
n=100 |
18 |
Correct |
13 ms |
23928 KB |
n=100 |
19 |
Correct |
13 ms |
23884 KB |
n=100 |
20 |
Correct |
13 ms |
23884 KB |
n=100 |
21 |
Correct |
13 ms |
23884 KB |
n=100 |
22 |
Correct |
13 ms |
23884 KB |
n=100 |
23 |
Correct |
13 ms |
23940 KB |
n=100 |
24 |
Correct |
14 ms |
23900 KB |
n=100 |
25 |
Correct |
13 ms |
23884 KB |
n=100 |
26 |
Correct |
13 ms |
23884 KB |
n=12 |
27 |
Correct |
13 ms |
23928 KB |
n=100 |
28 |
Correct |
13 ms |
24032 KB |
n=500 |
29 |
Correct |
13 ms |
23936 KB |
n=500 |
30 |
Correct |
14 ms |
23944 KB |
n=500 |
31 |
Correct |
14 ms |
24016 KB |
n=500 |
32 |
Correct |
13 ms |
23944 KB |
n=500 |
33 |
Correct |
19 ms |
24004 KB |
n=500 |
34 |
Correct |
14 ms |
24012 KB |
n=500 |
35 |
Correct |
14 ms |
24012 KB |
n=500 |
36 |
Correct |
13 ms |
24012 KB |
n=500 |
37 |
Correct |
14 ms |
24008 KB |
n=500 |
38 |
Correct |
13 ms |
23940 KB |
n=500 |
39 |
Correct |
13 ms |
24012 KB |
n=500 |
40 |
Correct |
14 ms |
24012 KB |
n=500 |
41 |
Correct |
14 ms |
24012 KB |
n=500 |
42 |
Correct |
15 ms |
23940 KB |
n=500 |
43 |
Correct |
15 ms |
24012 KB |
n=500 |
44 |
Correct |
14 ms |
24012 KB |
n=500 |
45 |
Correct |
14 ms |
24012 KB |
n=500 |
46 |
Correct |
14 ms |
24012 KB |
n=500 |
47 |
Correct |
13 ms |
23992 KB |
n=500 |
48 |
Correct |
14 ms |
23944 KB |
n=500 |
49 |
Correct |
14 ms |
24012 KB |
n=500 |
50 |
Correct |
14 ms |
24012 KB |
n=500 |
51 |
Correct |
14 ms |
23940 KB |
n=500 |
52 |
Correct |
14 ms |
24012 KB |
n=500 |
53 |
Correct |
14 ms |
24012 KB |
n=500 |
54 |
Correct |
13 ms |
24012 KB |
n=500 |
55 |
Correct |
13 ms |
23948 KB |
n=278 |
56 |
Correct |
14 ms |
24012 KB |
n=500 |
57 |
Correct |
14 ms |
24012 KB |
n=500 |
58 |
Correct |
13 ms |
24012 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23784 KB |
n=5 |
2 |
Correct |
12 ms |
23932 KB |
n=100 |
3 |
Correct |
15 ms |
23792 KB |
n=100 |
4 |
Correct |
14 ms |
23884 KB |
n=100 |
5 |
Correct |
13 ms |
23884 KB |
n=100 |
6 |
Correct |
13 ms |
23928 KB |
n=100 |
7 |
Correct |
13 ms |
23920 KB |
n=100 |
8 |
Correct |
14 ms |
23884 KB |
n=100 |
9 |
Correct |
13 ms |
23892 KB |
n=100 |
10 |
Correct |
13 ms |
23876 KB |
n=100 |
11 |
Correct |
14 ms |
23884 KB |
n=100 |
12 |
Correct |
13 ms |
23884 KB |
n=100 |
13 |
Correct |
14 ms |
23884 KB |
n=100 |
14 |
Correct |
14 ms |
23800 KB |
n=100 |
15 |
Correct |
13 ms |
23884 KB |
n=100 |
16 |
Correct |
13 ms |
23816 KB |
n=100 |
17 |
Correct |
13 ms |
23932 KB |
n=100 |
18 |
Correct |
13 ms |
23928 KB |
n=100 |
19 |
Correct |
13 ms |
23884 KB |
n=100 |
20 |
Correct |
13 ms |
23884 KB |
n=100 |
21 |
Correct |
13 ms |
23884 KB |
n=100 |
22 |
Correct |
13 ms |
23884 KB |
n=100 |
23 |
Correct |
13 ms |
23940 KB |
n=100 |
24 |
Correct |
14 ms |
23900 KB |
n=100 |
25 |
Correct |
13 ms |
23884 KB |
n=100 |
26 |
Correct |
13 ms |
23884 KB |
n=12 |
27 |
Correct |
13 ms |
23928 KB |
n=100 |
28 |
Correct |
13 ms |
24032 KB |
n=500 |
29 |
Correct |
13 ms |
23936 KB |
n=500 |
30 |
Correct |
14 ms |
23944 KB |
n=500 |
31 |
Correct |
14 ms |
24016 KB |
n=500 |
32 |
Correct |
13 ms |
23944 KB |
n=500 |
33 |
Correct |
19 ms |
24004 KB |
n=500 |
34 |
Correct |
14 ms |
24012 KB |
n=500 |
35 |
Correct |
14 ms |
24012 KB |
n=500 |
36 |
Correct |
13 ms |
24012 KB |
n=500 |
37 |
Correct |
14 ms |
24008 KB |
n=500 |
38 |
Correct |
13 ms |
23940 KB |
n=500 |
39 |
Correct |
13 ms |
24012 KB |
n=500 |
40 |
Correct |
14 ms |
24012 KB |
n=500 |
41 |
Correct |
14 ms |
24012 KB |
n=500 |
42 |
Correct |
15 ms |
23940 KB |
n=500 |
43 |
Correct |
15 ms |
24012 KB |
n=500 |
44 |
Correct |
14 ms |
24012 KB |
n=500 |
45 |
Correct |
14 ms |
24012 KB |
n=500 |
46 |
Correct |
14 ms |
24012 KB |
n=500 |
47 |
Correct |
13 ms |
23992 KB |
n=500 |
48 |
Correct |
14 ms |
23944 KB |
n=500 |
49 |
Correct |
14 ms |
24012 KB |
n=500 |
50 |
Correct |
14 ms |
24012 KB |
n=500 |
51 |
Correct |
14 ms |
23940 KB |
n=500 |
52 |
Correct |
14 ms |
24012 KB |
n=500 |
53 |
Correct |
14 ms |
24012 KB |
n=500 |
54 |
Correct |
13 ms |
24012 KB |
n=500 |
55 |
Correct |
13 ms |
23948 KB |
n=278 |
56 |
Correct |
14 ms |
24012 KB |
n=500 |
57 |
Correct |
14 ms |
24012 KB |
n=500 |
58 |
Correct |
13 ms |
24012 KB |
n=500 |
59 |
Correct |
18 ms |
24260 KB |
n=2000 |
60 |
Correct |
17 ms |
24396 KB |
n=2000 |
61 |
Correct |
18 ms |
24396 KB |
n=2000 |
62 |
Correct |
17 ms |
24396 KB |
n=2000 |
63 |
Correct |
16 ms |
24396 KB |
n=2000 |
64 |
Correct |
17 ms |
24408 KB |
n=2000 |
65 |
Correct |
17 ms |
24320 KB |
n=2000 |
66 |
Correct |
17 ms |
24396 KB |
n=2000 |
67 |
Correct |
17 ms |
24268 KB |
n=2000 |
68 |
Correct |
18 ms |
24312 KB |
n=2000 |
69 |
Correct |
16 ms |
24332 KB |
n=2000 |
70 |
Correct |
15 ms |
24364 KB |
n=2000 |
71 |
Correct |
16 ms |
24328 KB |
n=2000 |
72 |
Correct |
15 ms |
24396 KB |
n=2000 |
73 |
Correct |
15 ms |
24324 KB |
n=2000 |
74 |
Correct |
17 ms |
24320 KB |
n=1844 |
75 |
Correct |
15 ms |
24360 KB |
n=2000 |
76 |
Correct |
17 ms |
24352 KB |
n=2000 |
77 |
Correct |
16 ms |
24268 KB |
n=2000 |
78 |
Correct |
17 ms |
24396 KB |
n=2000 |
79 |
Correct |
16 ms |
24380 KB |
n=2000 |
80 |
Correct |
16 ms |
24320 KB |
n=2000 |
81 |
Correct |
16 ms |
24396 KB |
n=2000 |
82 |
Correct |
17 ms |
24268 KB |
n=2000 |
83 |
Correct |
16 ms |
24388 KB |
n=2000 |
84 |
Correct |
17 ms |
24388 KB |
n=2000 |
85 |
Correct |
16 ms |
24396 KB |
n=2000 |
86 |
Correct |
16 ms |
24308 KB |
n=2000 |
87 |
Correct |
16 ms |
24256 KB |
n=2000 |
88 |
Correct |
15 ms |
24524 KB |
n=2000 |
89 |
Correct |
15 ms |
24452 KB |
n=2000 |
90 |
Correct |
15 ms |
24444 KB |
n=2000 |
91 |
Correct |
17 ms |
24396 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23784 KB |
n=5 |
2 |
Correct |
12 ms |
23932 KB |
n=100 |
3 |
Correct |
15 ms |
23792 KB |
n=100 |
4 |
Correct |
14 ms |
23884 KB |
n=100 |
5 |
Correct |
13 ms |
23884 KB |
n=100 |
6 |
Correct |
13 ms |
23928 KB |
n=100 |
7 |
Correct |
13 ms |
23920 KB |
n=100 |
8 |
Correct |
14 ms |
23884 KB |
n=100 |
9 |
Correct |
13 ms |
23892 KB |
n=100 |
10 |
Correct |
13 ms |
23876 KB |
n=100 |
11 |
Correct |
14 ms |
23884 KB |
n=100 |
12 |
Correct |
13 ms |
23884 KB |
n=100 |
13 |
Correct |
14 ms |
23884 KB |
n=100 |
14 |
Correct |
14 ms |
23800 KB |
n=100 |
15 |
Correct |
13 ms |
23884 KB |
n=100 |
16 |
Correct |
13 ms |
23816 KB |
n=100 |
17 |
Correct |
13 ms |
23932 KB |
n=100 |
18 |
Correct |
13 ms |
23928 KB |
n=100 |
19 |
Correct |
13 ms |
23884 KB |
n=100 |
20 |
Correct |
13 ms |
23884 KB |
n=100 |
21 |
Correct |
13 ms |
23884 KB |
n=100 |
22 |
Correct |
13 ms |
23884 KB |
n=100 |
23 |
Correct |
13 ms |
23940 KB |
n=100 |
24 |
Correct |
14 ms |
23900 KB |
n=100 |
25 |
Correct |
13 ms |
23884 KB |
n=100 |
26 |
Correct |
13 ms |
23884 KB |
n=12 |
27 |
Correct |
13 ms |
23928 KB |
n=100 |
28 |
Correct |
13 ms |
24032 KB |
n=500 |
29 |
Correct |
13 ms |
23936 KB |
n=500 |
30 |
Correct |
14 ms |
23944 KB |
n=500 |
31 |
Correct |
14 ms |
24016 KB |
n=500 |
32 |
Correct |
13 ms |
23944 KB |
n=500 |
33 |
Correct |
19 ms |
24004 KB |
n=500 |
34 |
Correct |
14 ms |
24012 KB |
n=500 |
35 |
Correct |
14 ms |
24012 KB |
n=500 |
36 |
Correct |
13 ms |
24012 KB |
n=500 |
37 |
Correct |
14 ms |
24008 KB |
n=500 |
38 |
Correct |
13 ms |
23940 KB |
n=500 |
39 |
Correct |
13 ms |
24012 KB |
n=500 |
40 |
Correct |
14 ms |
24012 KB |
n=500 |
41 |
Correct |
14 ms |
24012 KB |
n=500 |
42 |
Correct |
15 ms |
23940 KB |
n=500 |
43 |
Correct |
15 ms |
24012 KB |
n=500 |
44 |
Correct |
14 ms |
24012 KB |
n=500 |
45 |
Correct |
14 ms |
24012 KB |
n=500 |
46 |
Correct |
14 ms |
24012 KB |
n=500 |
47 |
Correct |
13 ms |
23992 KB |
n=500 |
48 |
Correct |
14 ms |
23944 KB |
n=500 |
49 |
Correct |
14 ms |
24012 KB |
n=500 |
50 |
Correct |
14 ms |
24012 KB |
n=500 |
51 |
Correct |
14 ms |
23940 KB |
n=500 |
52 |
Correct |
14 ms |
24012 KB |
n=500 |
53 |
Correct |
14 ms |
24012 KB |
n=500 |
54 |
Correct |
13 ms |
24012 KB |
n=500 |
55 |
Correct |
13 ms |
23948 KB |
n=278 |
56 |
Correct |
14 ms |
24012 KB |
n=500 |
57 |
Correct |
14 ms |
24012 KB |
n=500 |
58 |
Correct |
13 ms |
24012 KB |
n=500 |
59 |
Correct |
18 ms |
24260 KB |
n=2000 |
60 |
Correct |
17 ms |
24396 KB |
n=2000 |
61 |
Correct |
18 ms |
24396 KB |
n=2000 |
62 |
Correct |
17 ms |
24396 KB |
n=2000 |
63 |
Correct |
16 ms |
24396 KB |
n=2000 |
64 |
Correct |
17 ms |
24408 KB |
n=2000 |
65 |
Correct |
17 ms |
24320 KB |
n=2000 |
66 |
Correct |
17 ms |
24396 KB |
n=2000 |
67 |
Correct |
17 ms |
24268 KB |
n=2000 |
68 |
Correct |
18 ms |
24312 KB |
n=2000 |
69 |
Correct |
16 ms |
24332 KB |
n=2000 |
70 |
Correct |
15 ms |
24364 KB |
n=2000 |
71 |
Correct |
16 ms |
24328 KB |
n=2000 |
72 |
Correct |
15 ms |
24396 KB |
n=2000 |
73 |
Correct |
15 ms |
24324 KB |
n=2000 |
74 |
Correct |
17 ms |
24320 KB |
n=1844 |
75 |
Correct |
15 ms |
24360 KB |
n=2000 |
76 |
Correct |
17 ms |
24352 KB |
n=2000 |
77 |
Correct |
16 ms |
24268 KB |
n=2000 |
78 |
Correct |
17 ms |
24396 KB |
n=2000 |
79 |
Correct |
16 ms |
24380 KB |
n=2000 |
80 |
Correct |
16 ms |
24320 KB |
n=2000 |
81 |
Correct |
16 ms |
24396 KB |
n=2000 |
82 |
Correct |
17 ms |
24268 KB |
n=2000 |
83 |
Correct |
16 ms |
24388 KB |
n=2000 |
84 |
Correct |
17 ms |
24388 KB |
n=2000 |
85 |
Correct |
16 ms |
24396 KB |
n=2000 |
86 |
Correct |
16 ms |
24308 KB |
n=2000 |
87 |
Correct |
16 ms |
24256 KB |
n=2000 |
88 |
Correct |
15 ms |
24524 KB |
n=2000 |
89 |
Correct |
15 ms |
24452 KB |
n=2000 |
90 |
Correct |
15 ms |
24444 KB |
n=2000 |
91 |
Correct |
17 ms |
24396 KB |
n=2000 |
92 |
Correct |
1339 ms |
73752 KB |
n=200000 |
93 |
Correct |
915 ms |
78776 KB |
n=200000 |
94 |
Correct |
573 ms |
82116 KB |
n=200000 |
95 |
Correct |
1328 ms |
73612 KB |
n=200000 |
96 |
Correct |
1265 ms |
73560 KB |
n=200000 |
97 |
Correct |
1022 ms |
77680 KB |
n=200000 |
98 |
Correct |
1393 ms |
73608 KB |
n=200000 |
99 |
Correct |
1355 ms |
73776 KB |
n=200000 |
100 |
Correct |
1335 ms |
73536 KB |
n=200000 |
101 |
Correct |
474 ms |
83176 KB |
n=200000 |
102 |
Correct |
558 ms |
74764 KB |
n=200000 |
103 |
Correct |
527 ms |
74760 KB |
n=200000 |
104 |
Correct |
542 ms |
74724 KB |
n=200000 |
105 |
Correct |
559 ms |
75196 KB |
n=200000 |
106 |
Correct |
539 ms |
75172 KB |
n=200000 |
107 |
Correct |
549 ms |
75256 KB |
n=200000 |
108 |
Correct |
1205 ms |
73664 KB |
n=200000 |
109 |
Correct |
1268 ms |
73596 KB |
n=200000 |
110 |
Correct |
1200 ms |
73772 KB |
n=200000 |
111 |
Correct |
1137 ms |
73276 KB |
n=200000 |
112 |
Correct |
528 ms |
82328 KB |
n=200000 |
113 |
Correct |
1020 ms |
77884 KB |
n=200000 |
114 |
Correct |
1131 ms |
73116 KB |
n=200000 |
115 |
Correct |
1313 ms |
75660 KB |
n=200000 |
116 |
Correct |
1271 ms |
73824 KB |
n=200000 |
117 |
Correct |
509 ms |
82544 KB |
n=200000 |
118 |
Correct |
1196 ms |
76528 KB |
n=200000 |
119 |
Correct |
1309 ms |
73668 KB |
n=200000 |
120 |
Correct |
414 ms |
82164 KB |
n=200000 |
121 |
Correct |
415 ms |
82120 KB |
n=200000 |
122 |
Correct |
440 ms |
82540 KB |
n=200000 |
123 |
Correct |
589 ms |
74952 KB |
n=200000 |
124 |
Incorrect |
145 ms |
38712 KB |
Wrong range. |
125 |
Halted |
0 ms |
0 KB |
- |