//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
//------------------KarginDefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
//-------------------KarginConstants------------------\\
const ll mod = 1000000007;
const ll inf = 1e9 + 15;
//-------------------KarginCode------------------------\\
const int N = 200005;
int a[N];
vector<int> g[N];
int tin[N], tout[N], tim = 0;
int up[N][20];
void dfs(int u, int p) {
tin[u] = tim++;
up[u][0] = p;
for (int v : g[u]) {
if (v != p) dfs(v, u);
}
tout[u] = tim;
}
bool anc(int u, int v) {
return tin[u] <= tin[v] && tout[u] >= tout[v];
}
int lca(int x, int y) {
if (anc(x, y)) return x;
if (anc(y, x)) return y;
for (int i = 19;i >= 0;i--) {
if (!anc(up[x][i], y)) x = up[x][i];
}
return up[x][0];
}
multiset<int> st[N];
void KarginSolve() {
int n, m, q;
cin >> n >> m >> q;
for (int i = 0;i < n - 1;i++) {
int u, v;
cin >> u >> v;
g[u].pb(v), g[v].pb(u);
}
for (int i = 1;i <= m;i++) cin >> a[i];
dfs(1, 1);
for (int j = 1;j < 20;j++) {
for (int i = 1;i <= n;i++) {
up[i][j] = up[up[i][j - 1]][j - 1];
}
}
for (int i = 1;i < m;i++) {
st[lca(a[i], a[i + 1])].insert(i);
st[a[i]].insert(i);
}
st[a[m]].insert(m);
while (q--) {
int t; cin >> t;
if (t == 1) {
int pos, v;
cin >> pos >> v;
st[a[pos]].erase(st[a[pos]].find(pos));
st[v].insert(pos);
if (pos != 1) {
st[lca(a[pos - 1], a[pos])].erase(st[lca(a[pos - 1], a[pos])].find(pos - 1));
st[lca(a[pos - 1], v)].insert(pos - 1);
}
if (pos != m) {
st[lca(a[pos], a[pos + 1])].erase(st[lca(a[pos], a[pos + 1])].find(pos));
st[lca(v, a[pos + 1])].insert(pos);
}
a[pos] = v;
}
else {
int l, r, v;
cin >> l >> r >> v;
auto it = st[v].lower(l);
if (it == st[v].end()) {
cout << "-1 -1\n";
}
else if (*it <= r) {
if (a[*it] == v) cout << *it << ' ' << *it << '\n';
else if (*it + 1 <= r) cout << *it << ' ' << *it + 1 << '\n';
else cout << "-1 -1\n";
}
else cout << "-1 -1\n";
}
}
}
int main() {
Kargin;
int test = 1;
//cin >> test;
while (test--) {
KarginSolve();
}
return 0;
}
Compilation message
treearray.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //-------------dilanyan------------\\
| ^
treearray.cpp:8:1: warning: multi-line comment [-Wcomment]
8 | //------------------KarginDefines--------------------\\
| ^
treearray.cpp:22:1: warning: multi-line comment [-Wcomment]
22 | //-------------------KarginConstants------------------\\
| ^
treearray.cpp:27:1: warning: multi-line comment [-Wcomment]
27 | //-------------------KarginCode------------------------\\
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
17240 KB |
n=5 |
2 |
Correct |
4 ms |
17244 KB |
n=100 |
3 |
Correct |
4 ms |
17336 KB |
n=100 |
4 |
Correct |
4 ms |
17240 KB |
n=100 |
5 |
Correct |
3 ms |
17244 KB |
n=100 |
6 |
Correct |
3 ms |
17240 KB |
n=100 |
7 |
Correct |
4 ms |
17244 KB |
n=100 |
8 |
Correct |
3 ms |
17240 KB |
n=100 |
9 |
Correct |
4 ms |
17244 KB |
n=100 |
10 |
Correct |
3 ms |
17240 KB |
n=100 |
11 |
Correct |
3 ms |
17496 KB |
n=100 |
12 |
Correct |
4 ms |
17340 KB |
n=100 |
13 |
Correct |
4 ms |
17240 KB |
n=100 |
14 |
Correct |
3 ms |
17244 KB |
n=100 |
15 |
Correct |
4 ms |
17244 KB |
n=100 |
16 |
Correct |
3 ms |
17244 KB |
n=100 |
17 |
Correct |
4 ms |
17244 KB |
n=100 |
18 |
Correct |
3 ms |
17244 KB |
n=100 |
19 |
Correct |
3 ms |
17244 KB |
n=100 |
20 |
Correct |
4 ms |
17244 KB |
n=100 |
21 |
Correct |
4 ms |
17240 KB |
n=100 |
22 |
Correct |
4 ms |
17496 KB |
n=100 |
23 |
Correct |
3 ms |
17496 KB |
n=100 |
24 |
Correct |
3 ms |
17244 KB |
n=100 |
25 |
Correct |
3 ms |
17240 KB |
n=100 |
26 |
Correct |
4 ms |
17244 KB |
n=12 |
27 |
Correct |
4 ms |
17440 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
17240 KB |
n=5 |
2 |
Correct |
4 ms |
17244 KB |
n=100 |
3 |
Correct |
4 ms |
17336 KB |
n=100 |
4 |
Correct |
4 ms |
17240 KB |
n=100 |
5 |
Correct |
3 ms |
17244 KB |
n=100 |
6 |
Correct |
3 ms |
17240 KB |
n=100 |
7 |
Correct |
4 ms |
17244 KB |
n=100 |
8 |
Correct |
3 ms |
17240 KB |
n=100 |
9 |
Correct |
4 ms |
17244 KB |
n=100 |
10 |
Correct |
3 ms |
17240 KB |
n=100 |
11 |
Correct |
3 ms |
17496 KB |
n=100 |
12 |
Correct |
4 ms |
17340 KB |
n=100 |
13 |
Correct |
4 ms |
17240 KB |
n=100 |
14 |
Correct |
3 ms |
17244 KB |
n=100 |
15 |
Correct |
4 ms |
17244 KB |
n=100 |
16 |
Correct |
3 ms |
17244 KB |
n=100 |
17 |
Correct |
4 ms |
17244 KB |
n=100 |
18 |
Correct |
3 ms |
17244 KB |
n=100 |
19 |
Correct |
3 ms |
17244 KB |
n=100 |
20 |
Correct |
4 ms |
17244 KB |
n=100 |
21 |
Correct |
4 ms |
17240 KB |
n=100 |
22 |
Correct |
4 ms |
17496 KB |
n=100 |
23 |
Correct |
3 ms |
17496 KB |
n=100 |
24 |
Correct |
3 ms |
17244 KB |
n=100 |
25 |
Correct |
3 ms |
17240 KB |
n=100 |
26 |
Correct |
4 ms |
17244 KB |
n=12 |
27 |
Correct |
4 ms |
17440 KB |
n=100 |
28 |
Correct |
4 ms |
17240 KB |
n=500 |
29 |
Correct |
4 ms |
17496 KB |
n=500 |
30 |
Correct |
5 ms |
17240 KB |
n=500 |
31 |
Correct |
4 ms |
17500 KB |
n=500 |
32 |
Correct |
4 ms |
17240 KB |
n=500 |
33 |
Correct |
4 ms |
17240 KB |
n=500 |
34 |
Correct |
4 ms |
17500 KB |
n=500 |
35 |
Correct |
4 ms |
17500 KB |
n=500 |
36 |
Correct |
5 ms |
17244 KB |
n=500 |
37 |
Correct |
4 ms |
17244 KB |
n=500 |
38 |
Correct |
4 ms |
17244 KB |
n=500 |
39 |
Correct |
5 ms |
17240 KB |
n=500 |
40 |
Correct |
4 ms |
17496 KB |
n=500 |
41 |
Correct |
4 ms |
17244 KB |
n=500 |
42 |
Correct |
4 ms |
17244 KB |
n=500 |
43 |
Correct |
4 ms |
17240 KB |
n=500 |
44 |
Correct |
5 ms |
17244 KB |
n=500 |
45 |
Correct |
4 ms |
17496 KB |
n=500 |
46 |
Correct |
4 ms |
17500 KB |
n=500 |
47 |
Correct |
4 ms |
17496 KB |
n=500 |
48 |
Correct |
4 ms |
17244 KB |
n=500 |
49 |
Correct |
4 ms |
17256 KB |
n=500 |
50 |
Correct |
4 ms |
17244 KB |
n=500 |
51 |
Correct |
4 ms |
17240 KB |
n=500 |
52 |
Correct |
4 ms |
17500 KB |
n=500 |
53 |
Correct |
4 ms |
17324 KB |
n=500 |
54 |
Correct |
4 ms |
17496 KB |
n=500 |
55 |
Correct |
4 ms |
17244 KB |
n=278 |
56 |
Correct |
4 ms |
17500 KB |
n=500 |
57 |
Correct |
4 ms |
17500 KB |
n=500 |
58 |
Correct |
4 ms |
17244 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
17240 KB |
n=5 |
2 |
Correct |
4 ms |
17244 KB |
n=100 |
3 |
Correct |
4 ms |
17336 KB |
n=100 |
4 |
Correct |
4 ms |
17240 KB |
n=100 |
5 |
Correct |
3 ms |
17244 KB |
n=100 |
6 |
Correct |
3 ms |
17240 KB |
n=100 |
7 |
Correct |
4 ms |
17244 KB |
n=100 |
8 |
Correct |
3 ms |
17240 KB |
n=100 |
9 |
Correct |
4 ms |
17244 KB |
n=100 |
10 |
Correct |
3 ms |
17240 KB |
n=100 |
11 |
Correct |
3 ms |
17496 KB |
n=100 |
12 |
Correct |
4 ms |
17340 KB |
n=100 |
13 |
Correct |
4 ms |
17240 KB |
n=100 |
14 |
Correct |
3 ms |
17244 KB |
n=100 |
15 |
Correct |
4 ms |
17244 KB |
n=100 |
16 |
Correct |
3 ms |
17244 KB |
n=100 |
17 |
Correct |
4 ms |
17244 KB |
n=100 |
18 |
Correct |
3 ms |
17244 KB |
n=100 |
19 |
Correct |
3 ms |
17244 KB |
n=100 |
20 |
Correct |
4 ms |
17244 KB |
n=100 |
21 |
Correct |
4 ms |
17240 KB |
n=100 |
22 |
Correct |
4 ms |
17496 KB |
n=100 |
23 |
Correct |
3 ms |
17496 KB |
n=100 |
24 |
Correct |
3 ms |
17244 KB |
n=100 |
25 |
Correct |
3 ms |
17240 KB |
n=100 |
26 |
Correct |
4 ms |
17244 KB |
n=12 |
27 |
Correct |
4 ms |
17440 KB |
n=100 |
28 |
Correct |
4 ms |
17240 KB |
n=500 |
29 |
Correct |
4 ms |
17496 KB |
n=500 |
30 |
Correct |
5 ms |
17240 KB |
n=500 |
31 |
Correct |
4 ms |
17500 KB |
n=500 |
32 |
Correct |
4 ms |
17240 KB |
n=500 |
33 |
Correct |
4 ms |
17240 KB |
n=500 |
34 |
Correct |
4 ms |
17500 KB |
n=500 |
35 |
Correct |
4 ms |
17500 KB |
n=500 |
36 |
Correct |
5 ms |
17244 KB |
n=500 |
37 |
Correct |
4 ms |
17244 KB |
n=500 |
38 |
Correct |
4 ms |
17244 KB |
n=500 |
39 |
Correct |
5 ms |
17240 KB |
n=500 |
40 |
Correct |
4 ms |
17496 KB |
n=500 |
41 |
Correct |
4 ms |
17244 KB |
n=500 |
42 |
Correct |
4 ms |
17244 KB |
n=500 |
43 |
Correct |
4 ms |
17240 KB |
n=500 |
44 |
Correct |
5 ms |
17244 KB |
n=500 |
45 |
Correct |
4 ms |
17496 KB |
n=500 |
46 |
Correct |
4 ms |
17500 KB |
n=500 |
47 |
Correct |
4 ms |
17496 KB |
n=500 |
48 |
Correct |
4 ms |
17244 KB |
n=500 |
49 |
Correct |
4 ms |
17256 KB |
n=500 |
50 |
Correct |
4 ms |
17244 KB |
n=500 |
51 |
Correct |
4 ms |
17240 KB |
n=500 |
52 |
Correct |
4 ms |
17500 KB |
n=500 |
53 |
Correct |
4 ms |
17324 KB |
n=500 |
54 |
Correct |
4 ms |
17496 KB |
n=500 |
55 |
Correct |
4 ms |
17244 KB |
n=278 |
56 |
Correct |
4 ms |
17500 KB |
n=500 |
57 |
Correct |
4 ms |
17500 KB |
n=500 |
58 |
Correct |
4 ms |
17244 KB |
n=500 |
59 |
Correct |
6 ms |
17496 KB |
n=2000 |
60 |
Correct |
5 ms |
17756 KB |
n=2000 |
61 |
Correct |
6 ms |
17756 KB |
n=2000 |
62 |
Correct |
6 ms |
17756 KB |
n=2000 |
63 |
Correct |
6 ms |
17500 KB |
n=2000 |
64 |
Correct |
6 ms |
17756 KB |
n=2000 |
65 |
Correct |
6 ms |
17500 KB |
n=2000 |
66 |
Correct |
6 ms |
17756 KB |
n=2000 |
67 |
Correct |
6 ms |
17500 KB |
n=2000 |
68 |
Correct |
6 ms |
17596 KB |
n=2000 |
69 |
Correct |
5 ms |
17500 KB |
n=2000 |
70 |
Correct |
5 ms |
17500 KB |
n=2000 |
71 |
Correct |
5 ms |
17496 KB |
n=2000 |
72 |
Correct |
5 ms |
17500 KB |
n=2000 |
73 |
Correct |
6 ms |
17756 KB |
n=2000 |
74 |
Correct |
6 ms |
17500 KB |
n=1844 |
75 |
Correct |
5 ms |
17676 KB |
n=2000 |
76 |
Correct |
6 ms |
17500 KB |
n=2000 |
77 |
Correct |
6 ms |
17500 KB |
n=2000 |
78 |
Correct |
6 ms |
17500 KB |
n=2000 |
79 |
Correct |
6 ms |
17500 KB |
n=2000 |
80 |
Correct |
7 ms |
17756 KB |
n=2000 |
81 |
Correct |
6 ms |
17752 KB |
n=2000 |
82 |
Correct |
6 ms |
17752 KB |
n=2000 |
83 |
Correct |
5 ms |
17752 KB |
n=2000 |
84 |
Correct |
6 ms |
17500 KB |
n=2000 |
85 |
Correct |
5 ms |
17756 KB |
n=2000 |
86 |
Correct |
6 ms |
17628 KB |
n=2000 |
87 |
Correct |
6 ms |
17500 KB |
n=2000 |
88 |
Correct |
5 ms |
17756 KB |
n=2000 |
89 |
Correct |
5 ms |
17756 KB |
n=2000 |
90 |
Correct |
5 ms |
17756 KB |
n=2000 |
91 |
Correct |
5 ms |
17500 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
17240 KB |
n=5 |
2 |
Correct |
4 ms |
17244 KB |
n=100 |
3 |
Correct |
4 ms |
17336 KB |
n=100 |
4 |
Correct |
4 ms |
17240 KB |
n=100 |
5 |
Correct |
3 ms |
17244 KB |
n=100 |
6 |
Correct |
3 ms |
17240 KB |
n=100 |
7 |
Correct |
4 ms |
17244 KB |
n=100 |
8 |
Correct |
3 ms |
17240 KB |
n=100 |
9 |
Correct |
4 ms |
17244 KB |
n=100 |
10 |
Correct |
3 ms |
17240 KB |
n=100 |
11 |
Correct |
3 ms |
17496 KB |
n=100 |
12 |
Correct |
4 ms |
17340 KB |
n=100 |
13 |
Correct |
4 ms |
17240 KB |
n=100 |
14 |
Correct |
3 ms |
17244 KB |
n=100 |
15 |
Correct |
4 ms |
17244 KB |
n=100 |
16 |
Correct |
3 ms |
17244 KB |
n=100 |
17 |
Correct |
4 ms |
17244 KB |
n=100 |
18 |
Correct |
3 ms |
17244 KB |
n=100 |
19 |
Correct |
3 ms |
17244 KB |
n=100 |
20 |
Correct |
4 ms |
17244 KB |
n=100 |
21 |
Correct |
4 ms |
17240 KB |
n=100 |
22 |
Correct |
4 ms |
17496 KB |
n=100 |
23 |
Correct |
3 ms |
17496 KB |
n=100 |
24 |
Correct |
3 ms |
17244 KB |
n=100 |
25 |
Correct |
3 ms |
17240 KB |
n=100 |
26 |
Correct |
4 ms |
17244 KB |
n=12 |
27 |
Correct |
4 ms |
17440 KB |
n=100 |
28 |
Correct |
4 ms |
17240 KB |
n=500 |
29 |
Correct |
4 ms |
17496 KB |
n=500 |
30 |
Correct |
5 ms |
17240 KB |
n=500 |
31 |
Correct |
4 ms |
17500 KB |
n=500 |
32 |
Correct |
4 ms |
17240 KB |
n=500 |
33 |
Correct |
4 ms |
17240 KB |
n=500 |
34 |
Correct |
4 ms |
17500 KB |
n=500 |
35 |
Correct |
4 ms |
17500 KB |
n=500 |
36 |
Correct |
5 ms |
17244 KB |
n=500 |
37 |
Correct |
4 ms |
17244 KB |
n=500 |
38 |
Correct |
4 ms |
17244 KB |
n=500 |
39 |
Correct |
5 ms |
17240 KB |
n=500 |
40 |
Correct |
4 ms |
17496 KB |
n=500 |
41 |
Correct |
4 ms |
17244 KB |
n=500 |
42 |
Correct |
4 ms |
17244 KB |
n=500 |
43 |
Correct |
4 ms |
17240 KB |
n=500 |
44 |
Correct |
5 ms |
17244 KB |
n=500 |
45 |
Correct |
4 ms |
17496 KB |
n=500 |
46 |
Correct |
4 ms |
17500 KB |
n=500 |
47 |
Correct |
4 ms |
17496 KB |
n=500 |
48 |
Correct |
4 ms |
17244 KB |
n=500 |
49 |
Correct |
4 ms |
17256 KB |
n=500 |
50 |
Correct |
4 ms |
17244 KB |
n=500 |
51 |
Correct |
4 ms |
17240 KB |
n=500 |
52 |
Correct |
4 ms |
17500 KB |
n=500 |
53 |
Correct |
4 ms |
17324 KB |
n=500 |
54 |
Correct |
4 ms |
17496 KB |
n=500 |
55 |
Correct |
4 ms |
17244 KB |
n=278 |
56 |
Correct |
4 ms |
17500 KB |
n=500 |
57 |
Correct |
4 ms |
17500 KB |
n=500 |
58 |
Correct |
4 ms |
17244 KB |
n=500 |
59 |
Correct |
6 ms |
17496 KB |
n=2000 |
60 |
Correct |
5 ms |
17756 KB |
n=2000 |
61 |
Correct |
6 ms |
17756 KB |
n=2000 |
62 |
Correct |
6 ms |
17756 KB |
n=2000 |
63 |
Correct |
6 ms |
17500 KB |
n=2000 |
64 |
Correct |
6 ms |
17756 KB |
n=2000 |
65 |
Correct |
6 ms |
17500 KB |
n=2000 |
66 |
Correct |
6 ms |
17756 KB |
n=2000 |
67 |
Correct |
6 ms |
17500 KB |
n=2000 |
68 |
Correct |
6 ms |
17596 KB |
n=2000 |
69 |
Correct |
5 ms |
17500 KB |
n=2000 |
70 |
Correct |
5 ms |
17500 KB |
n=2000 |
71 |
Correct |
5 ms |
17496 KB |
n=2000 |
72 |
Correct |
5 ms |
17500 KB |
n=2000 |
73 |
Correct |
6 ms |
17756 KB |
n=2000 |
74 |
Correct |
6 ms |
17500 KB |
n=1844 |
75 |
Correct |
5 ms |
17676 KB |
n=2000 |
76 |
Correct |
6 ms |
17500 KB |
n=2000 |
77 |
Correct |
6 ms |
17500 KB |
n=2000 |
78 |
Correct |
6 ms |
17500 KB |
n=2000 |
79 |
Correct |
6 ms |
17500 KB |
n=2000 |
80 |
Correct |
7 ms |
17756 KB |
n=2000 |
81 |
Correct |
6 ms |
17752 KB |
n=2000 |
82 |
Correct |
6 ms |
17752 KB |
n=2000 |
83 |
Correct |
5 ms |
17752 KB |
n=2000 |
84 |
Correct |
6 ms |
17500 KB |
n=2000 |
85 |
Correct |
5 ms |
17756 KB |
n=2000 |
86 |
Correct |
6 ms |
17628 KB |
n=2000 |
87 |
Correct |
6 ms |
17500 KB |
n=2000 |
88 |
Correct |
5 ms |
17756 KB |
n=2000 |
89 |
Correct |
5 ms |
17756 KB |
n=2000 |
90 |
Correct |
5 ms |
17756 KB |
n=2000 |
91 |
Correct |
5 ms |
17500 KB |
n=2000 |
92 |
Correct |
553 ms |
65856 KB |
n=200000 |
93 |
Correct |
543 ms |
70924 KB |
n=200000 |
94 |
Correct |
381 ms |
74068 KB |
n=200000 |
95 |
Correct |
595 ms |
65680 KB |
n=200000 |
96 |
Correct |
542 ms |
65628 KB |
n=200000 |
97 |
Correct |
637 ms |
70120 KB |
n=200000 |
98 |
Correct |
538 ms |
65828 KB |
n=200000 |
99 |
Correct |
617 ms |
66288 KB |
n=200000 |
100 |
Correct |
576 ms |
65976 KB |
n=200000 |
101 |
Correct |
343 ms |
75576 KB |
n=200000 |
102 |
Correct |
291 ms |
66940 KB |
n=200000 |
103 |
Correct |
297 ms |
66900 KB |
n=200000 |
104 |
Correct |
281 ms |
66860 KB |
n=200000 |
105 |
Correct |
335 ms |
67360 KB |
n=200000 |
106 |
Correct |
298 ms |
67396 KB |
n=200000 |
107 |
Correct |
350 ms |
67520 KB |
n=200000 |
108 |
Correct |
599 ms |
65952 KB |
n=200000 |
109 |
Correct |
568 ms |
65872 KB |
n=200000 |
110 |
Correct |
553 ms |
65768 KB |
n=200000 |
111 |
Correct |
542 ms |
65352 KB |
n=200000 |
112 |
Correct |
465 ms |
74392 KB |
n=200000 |
113 |
Correct |
655 ms |
70032 KB |
n=200000 |
114 |
Correct |
635 ms |
65432 KB |
n=200000 |
115 |
Correct |
824 ms |
67700 KB |
n=200000 |
116 |
Correct |
601 ms |
66076 KB |
n=200000 |
117 |
Correct |
390 ms |
74676 KB |
n=200000 |
118 |
Correct |
824 ms |
68736 KB |
n=200000 |
119 |
Correct |
588 ms |
66288 KB |
n=200000 |
120 |
Correct |
333 ms |
74552 KB |
n=200000 |
121 |
Correct |
378 ms |
74368 KB |
n=200000 |
122 |
Correct |
332 ms |
74836 KB |
n=200000 |
123 |
Correct |
334 ms |
67140 KB |
n=200000 |
124 |
Correct |
116 ms |
32056 KB |
n=25264 |