#include <bits/stdc++.h>
#define speed \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define precision \
cout.precision(30); \
cerr.precision(10);
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) for (int i = l; i != r; (l > r ? i-- : i++))
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define mp(x, y) make_pair(x, y)
#define all(x) x.begin(), x.end()
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define F first
#define S second
using namespace std;
void ioi(string name) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
int n, m, q, T, a[200005], tin[200005], tout[200005], up[200005][20];
set<int> s[200005], acl[200005];
vector<int> g[200005];
void calc(int v = 1, int p = 1) {
tin[v] = ++T;
up[v][0] = p;
for (int i = 1; i <= 19; i++) up[v][i] = up[up[v][i - 1]][i - 1];
for (auto to : g[v])
if (to != p) calc(to, v);
tout[v] = ++T;
}
bool pred(int u, int v) { return (tin[u] <= tin[v] && tout[v] <= tout[u]); }
int lca(int u, int v) {
if (pred(u, v)) return u;
if (pred(v, u)) return v;
for (int i = 19; i >= 0; i--)
if (!pred(up[u][i], v)) u = up[u][i];
return (pred(u, v) ? u : up[u][0]);
}
int main() {
speed;
precision;
// code
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);
}
calc();
for (int i = 1; i <= m; i++) {
cin >> a[i];
s[a[i]].insert(i);
if (i > 1) acl[lca(a[i - 1], a[i])].insert(i - 1);
}
while (q--) {
int type, l, r, v;
cin >> type;
if (type == 1) {
cin >> l >> r;
s[a[l]].erase(l);
if (l > 1) acl[lca(a[l - 1], a[l])].erase(l - 1);
if (l < m) acl[lca(a[l], a[l + 1])].erase(l);
a[l] = r;
s[a[l]].insert(l);
if (l > 1) acl[lca(a[l - 1], a[l])].insert(l - 1);
if (l < m) acl[lca(a[l], a[l + 1])].insert(l);
}
if (type == 2) {
cin >> l >> r >> v;
auto it = s[v].lower_bound(l);
if (it != s[v].end() && *it <= r) {
cout << *it << " " << *it << "\n";
continue;
}
auto ti = acl[v].lower_bound(l);
if (ti != acl[v].end() && *ti + 1 <= r) {
cout << *ti << " " << *ti + 1 << "\n";
continue;
}
cout << -1 << " " << -1 << "\n";
}
}
// endl
#ifndef ONLINE_JUDGE
cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
Compilation message
treearray.cpp: In function 'void ioi(std::string)':
treearray.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
25 | freopen((name + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:26:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
26 | freopen((name + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23916 KB |
n=5 |
2 |
Correct |
17 ms |
23916 KB |
n=100 |
3 |
Correct |
17 ms |
23916 KB |
n=100 |
4 |
Correct |
17 ms |
23916 KB |
n=100 |
5 |
Correct |
20 ms |
23916 KB |
n=100 |
6 |
Correct |
17 ms |
23916 KB |
n=100 |
7 |
Correct |
17 ms |
23916 KB |
n=100 |
8 |
Correct |
18 ms |
23916 KB |
n=100 |
9 |
Correct |
18 ms |
23916 KB |
n=100 |
10 |
Correct |
17 ms |
23916 KB |
n=100 |
11 |
Correct |
17 ms |
23916 KB |
n=100 |
12 |
Correct |
17 ms |
23916 KB |
n=100 |
13 |
Correct |
17 ms |
23916 KB |
n=100 |
14 |
Correct |
17 ms |
23916 KB |
n=100 |
15 |
Correct |
20 ms |
23916 KB |
n=100 |
16 |
Correct |
17 ms |
23916 KB |
n=100 |
17 |
Correct |
17 ms |
23916 KB |
n=100 |
18 |
Correct |
17 ms |
23916 KB |
n=100 |
19 |
Correct |
17 ms |
23916 KB |
n=100 |
20 |
Correct |
17 ms |
23916 KB |
n=100 |
21 |
Correct |
17 ms |
23916 KB |
n=100 |
22 |
Correct |
17 ms |
23884 KB |
n=100 |
23 |
Correct |
17 ms |
23916 KB |
n=100 |
24 |
Correct |
17 ms |
23916 KB |
n=100 |
25 |
Correct |
17 ms |
23916 KB |
n=100 |
26 |
Correct |
17 ms |
23916 KB |
n=12 |
27 |
Correct |
17 ms |
23916 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23916 KB |
n=5 |
2 |
Correct |
17 ms |
23916 KB |
n=100 |
3 |
Correct |
17 ms |
23916 KB |
n=100 |
4 |
Correct |
17 ms |
23916 KB |
n=100 |
5 |
Correct |
20 ms |
23916 KB |
n=100 |
6 |
Correct |
17 ms |
23916 KB |
n=100 |
7 |
Correct |
17 ms |
23916 KB |
n=100 |
8 |
Correct |
18 ms |
23916 KB |
n=100 |
9 |
Correct |
18 ms |
23916 KB |
n=100 |
10 |
Correct |
17 ms |
23916 KB |
n=100 |
11 |
Correct |
17 ms |
23916 KB |
n=100 |
12 |
Correct |
17 ms |
23916 KB |
n=100 |
13 |
Correct |
17 ms |
23916 KB |
n=100 |
14 |
Correct |
17 ms |
23916 KB |
n=100 |
15 |
Correct |
20 ms |
23916 KB |
n=100 |
16 |
Correct |
17 ms |
23916 KB |
n=100 |
17 |
Correct |
17 ms |
23916 KB |
n=100 |
18 |
Correct |
17 ms |
23916 KB |
n=100 |
19 |
Correct |
17 ms |
23916 KB |
n=100 |
20 |
Correct |
17 ms |
23916 KB |
n=100 |
21 |
Correct |
17 ms |
23916 KB |
n=100 |
22 |
Correct |
17 ms |
23884 KB |
n=100 |
23 |
Correct |
17 ms |
23916 KB |
n=100 |
24 |
Correct |
17 ms |
23916 KB |
n=100 |
25 |
Correct |
17 ms |
23916 KB |
n=100 |
26 |
Correct |
17 ms |
23916 KB |
n=12 |
27 |
Correct |
17 ms |
23916 KB |
n=100 |
28 |
Correct |
18 ms |
23916 KB |
n=500 |
29 |
Correct |
18 ms |
24044 KB |
n=500 |
30 |
Correct |
18 ms |
24044 KB |
n=500 |
31 |
Correct |
18 ms |
24044 KB |
n=500 |
32 |
Correct |
18 ms |
23936 KB |
n=500 |
33 |
Correct |
24 ms |
24044 KB |
n=500 |
34 |
Correct |
18 ms |
24044 KB |
n=500 |
35 |
Correct |
18 ms |
24044 KB |
n=500 |
36 |
Correct |
20 ms |
23916 KB |
n=500 |
37 |
Correct |
18 ms |
24064 KB |
n=500 |
38 |
Correct |
18 ms |
23916 KB |
n=500 |
39 |
Correct |
17 ms |
24044 KB |
n=500 |
40 |
Correct |
18 ms |
24044 KB |
n=500 |
41 |
Correct |
18 ms |
24044 KB |
n=500 |
42 |
Correct |
18 ms |
23916 KB |
n=500 |
43 |
Correct |
18 ms |
23916 KB |
n=500 |
44 |
Correct |
18 ms |
23916 KB |
n=500 |
45 |
Correct |
18 ms |
23916 KB |
n=500 |
46 |
Correct |
17 ms |
24044 KB |
n=500 |
47 |
Correct |
20 ms |
24044 KB |
n=500 |
48 |
Correct |
18 ms |
23916 KB |
n=500 |
49 |
Correct |
18 ms |
24044 KB |
n=500 |
50 |
Correct |
18 ms |
23916 KB |
n=500 |
51 |
Correct |
18 ms |
24044 KB |
n=500 |
52 |
Correct |
18 ms |
24044 KB |
n=500 |
53 |
Correct |
18 ms |
24044 KB |
n=500 |
54 |
Correct |
17 ms |
24044 KB |
n=500 |
55 |
Correct |
18 ms |
23916 KB |
n=278 |
56 |
Correct |
18 ms |
24044 KB |
n=500 |
57 |
Correct |
17 ms |
24172 KB |
n=500 |
58 |
Correct |
18 ms |
24044 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23916 KB |
n=5 |
2 |
Correct |
17 ms |
23916 KB |
n=100 |
3 |
Correct |
17 ms |
23916 KB |
n=100 |
4 |
Correct |
17 ms |
23916 KB |
n=100 |
5 |
Correct |
20 ms |
23916 KB |
n=100 |
6 |
Correct |
17 ms |
23916 KB |
n=100 |
7 |
Correct |
17 ms |
23916 KB |
n=100 |
8 |
Correct |
18 ms |
23916 KB |
n=100 |
9 |
Correct |
18 ms |
23916 KB |
n=100 |
10 |
Correct |
17 ms |
23916 KB |
n=100 |
11 |
Correct |
17 ms |
23916 KB |
n=100 |
12 |
Correct |
17 ms |
23916 KB |
n=100 |
13 |
Correct |
17 ms |
23916 KB |
n=100 |
14 |
Correct |
17 ms |
23916 KB |
n=100 |
15 |
Correct |
20 ms |
23916 KB |
n=100 |
16 |
Correct |
17 ms |
23916 KB |
n=100 |
17 |
Correct |
17 ms |
23916 KB |
n=100 |
18 |
Correct |
17 ms |
23916 KB |
n=100 |
19 |
Correct |
17 ms |
23916 KB |
n=100 |
20 |
Correct |
17 ms |
23916 KB |
n=100 |
21 |
Correct |
17 ms |
23916 KB |
n=100 |
22 |
Correct |
17 ms |
23884 KB |
n=100 |
23 |
Correct |
17 ms |
23916 KB |
n=100 |
24 |
Correct |
17 ms |
23916 KB |
n=100 |
25 |
Correct |
17 ms |
23916 KB |
n=100 |
26 |
Correct |
17 ms |
23916 KB |
n=12 |
27 |
Correct |
17 ms |
23916 KB |
n=100 |
28 |
Correct |
18 ms |
23916 KB |
n=500 |
29 |
Correct |
18 ms |
24044 KB |
n=500 |
30 |
Correct |
18 ms |
24044 KB |
n=500 |
31 |
Correct |
18 ms |
24044 KB |
n=500 |
32 |
Correct |
18 ms |
23936 KB |
n=500 |
33 |
Correct |
24 ms |
24044 KB |
n=500 |
34 |
Correct |
18 ms |
24044 KB |
n=500 |
35 |
Correct |
18 ms |
24044 KB |
n=500 |
36 |
Correct |
20 ms |
23916 KB |
n=500 |
37 |
Correct |
18 ms |
24064 KB |
n=500 |
38 |
Correct |
18 ms |
23916 KB |
n=500 |
39 |
Correct |
17 ms |
24044 KB |
n=500 |
40 |
Correct |
18 ms |
24044 KB |
n=500 |
41 |
Correct |
18 ms |
24044 KB |
n=500 |
42 |
Correct |
18 ms |
23916 KB |
n=500 |
43 |
Correct |
18 ms |
23916 KB |
n=500 |
44 |
Correct |
18 ms |
23916 KB |
n=500 |
45 |
Correct |
18 ms |
23916 KB |
n=500 |
46 |
Correct |
17 ms |
24044 KB |
n=500 |
47 |
Correct |
20 ms |
24044 KB |
n=500 |
48 |
Correct |
18 ms |
23916 KB |
n=500 |
49 |
Correct |
18 ms |
24044 KB |
n=500 |
50 |
Correct |
18 ms |
23916 KB |
n=500 |
51 |
Correct |
18 ms |
24044 KB |
n=500 |
52 |
Correct |
18 ms |
24044 KB |
n=500 |
53 |
Correct |
18 ms |
24044 KB |
n=500 |
54 |
Correct |
17 ms |
24044 KB |
n=500 |
55 |
Correct |
18 ms |
23916 KB |
n=278 |
56 |
Correct |
18 ms |
24044 KB |
n=500 |
57 |
Correct |
17 ms |
24172 KB |
n=500 |
58 |
Correct |
18 ms |
24044 KB |
n=500 |
59 |
Correct |
21 ms |
24300 KB |
n=2000 |
60 |
Correct |
20 ms |
24428 KB |
n=2000 |
61 |
Correct |
20 ms |
24428 KB |
n=2000 |
62 |
Correct |
22 ms |
24428 KB |
n=2000 |
63 |
Correct |
21 ms |
24300 KB |
n=2000 |
64 |
Correct |
21 ms |
24428 KB |
n=2000 |
65 |
Correct |
21 ms |
24300 KB |
n=2000 |
66 |
Correct |
20 ms |
24428 KB |
n=2000 |
67 |
Correct |
21 ms |
24300 KB |
n=2000 |
68 |
Correct |
20 ms |
24428 KB |
n=2000 |
69 |
Correct |
20 ms |
24300 KB |
n=2000 |
70 |
Correct |
20 ms |
24300 KB |
n=2000 |
71 |
Correct |
21 ms |
24300 KB |
n=2000 |
72 |
Correct |
22 ms |
24320 KB |
n=2000 |
73 |
Correct |
20 ms |
24300 KB |
n=2000 |
74 |
Correct |
20 ms |
24300 KB |
n=1844 |
75 |
Correct |
20 ms |
24300 KB |
n=2000 |
76 |
Correct |
21 ms |
24428 KB |
n=2000 |
77 |
Correct |
21 ms |
24328 KB |
n=2000 |
78 |
Correct |
21 ms |
24300 KB |
n=2000 |
79 |
Correct |
21 ms |
24300 KB |
n=2000 |
80 |
Correct |
20 ms |
24428 KB |
n=2000 |
81 |
Correct |
21 ms |
24428 KB |
n=2000 |
82 |
Correct |
22 ms |
24300 KB |
n=2000 |
83 |
Correct |
20 ms |
24428 KB |
n=2000 |
84 |
Correct |
21 ms |
24300 KB |
n=2000 |
85 |
Correct |
21 ms |
24428 KB |
n=2000 |
86 |
Correct |
21 ms |
24428 KB |
n=2000 |
87 |
Correct |
21 ms |
24300 KB |
n=2000 |
88 |
Correct |
20 ms |
24428 KB |
n=2000 |
89 |
Correct |
20 ms |
24428 KB |
n=2000 |
90 |
Correct |
21 ms |
24428 KB |
n=2000 |
91 |
Correct |
20 ms |
24300 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23916 KB |
n=5 |
2 |
Correct |
17 ms |
23916 KB |
n=100 |
3 |
Correct |
17 ms |
23916 KB |
n=100 |
4 |
Correct |
17 ms |
23916 KB |
n=100 |
5 |
Correct |
20 ms |
23916 KB |
n=100 |
6 |
Correct |
17 ms |
23916 KB |
n=100 |
7 |
Correct |
17 ms |
23916 KB |
n=100 |
8 |
Correct |
18 ms |
23916 KB |
n=100 |
9 |
Correct |
18 ms |
23916 KB |
n=100 |
10 |
Correct |
17 ms |
23916 KB |
n=100 |
11 |
Correct |
17 ms |
23916 KB |
n=100 |
12 |
Correct |
17 ms |
23916 KB |
n=100 |
13 |
Correct |
17 ms |
23916 KB |
n=100 |
14 |
Correct |
17 ms |
23916 KB |
n=100 |
15 |
Correct |
20 ms |
23916 KB |
n=100 |
16 |
Correct |
17 ms |
23916 KB |
n=100 |
17 |
Correct |
17 ms |
23916 KB |
n=100 |
18 |
Correct |
17 ms |
23916 KB |
n=100 |
19 |
Correct |
17 ms |
23916 KB |
n=100 |
20 |
Correct |
17 ms |
23916 KB |
n=100 |
21 |
Correct |
17 ms |
23916 KB |
n=100 |
22 |
Correct |
17 ms |
23884 KB |
n=100 |
23 |
Correct |
17 ms |
23916 KB |
n=100 |
24 |
Correct |
17 ms |
23916 KB |
n=100 |
25 |
Correct |
17 ms |
23916 KB |
n=100 |
26 |
Correct |
17 ms |
23916 KB |
n=12 |
27 |
Correct |
17 ms |
23916 KB |
n=100 |
28 |
Correct |
18 ms |
23916 KB |
n=500 |
29 |
Correct |
18 ms |
24044 KB |
n=500 |
30 |
Correct |
18 ms |
24044 KB |
n=500 |
31 |
Correct |
18 ms |
24044 KB |
n=500 |
32 |
Correct |
18 ms |
23936 KB |
n=500 |
33 |
Correct |
24 ms |
24044 KB |
n=500 |
34 |
Correct |
18 ms |
24044 KB |
n=500 |
35 |
Correct |
18 ms |
24044 KB |
n=500 |
36 |
Correct |
20 ms |
23916 KB |
n=500 |
37 |
Correct |
18 ms |
24064 KB |
n=500 |
38 |
Correct |
18 ms |
23916 KB |
n=500 |
39 |
Correct |
17 ms |
24044 KB |
n=500 |
40 |
Correct |
18 ms |
24044 KB |
n=500 |
41 |
Correct |
18 ms |
24044 KB |
n=500 |
42 |
Correct |
18 ms |
23916 KB |
n=500 |
43 |
Correct |
18 ms |
23916 KB |
n=500 |
44 |
Correct |
18 ms |
23916 KB |
n=500 |
45 |
Correct |
18 ms |
23916 KB |
n=500 |
46 |
Correct |
17 ms |
24044 KB |
n=500 |
47 |
Correct |
20 ms |
24044 KB |
n=500 |
48 |
Correct |
18 ms |
23916 KB |
n=500 |
49 |
Correct |
18 ms |
24044 KB |
n=500 |
50 |
Correct |
18 ms |
23916 KB |
n=500 |
51 |
Correct |
18 ms |
24044 KB |
n=500 |
52 |
Correct |
18 ms |
24044 KB |
n=500 |
53 |
Correct |
18 ms |
24044 KB |
n=500 |
54 |
Correct |
17 ms |
24044 KB |
n=500 |
55 |
Correct |
18 ms |
23916 KB |
n=278 |
56 |
Correct |
18 ms |
24044 KB |
n=500 |
57 |
Correct |
17 ms |
24172 KB |
n=500 |
58 |
Correct |
18 ms |
24044 KB |
n=500 |
59 |
Correct |
21 ms |
24300 KB |
n=2000 |
60 |
Correct |
20 ms |
24428 KB |
n=2000 |
61 |
Correct |
20 ms |
24428 KB |
n=2000 |
62 |
Correct |
22 ms |
24428 KB |
n=2000 |
63 |
Correct |
21 ms |
24300 KB |
n=2000 |
64 |
Correct |
21 ms |
24428 KB |
n=2000 |
65 |
Correct |
21 ms |
24300 KB |
n=2000 |
66 |
Correct |
20 ms |
24428 KB |
n=2000 |
67 |
Correct |
21 ms |
24300 KB |
n=2000 |
68 |
Correct |
20 ms |
24428 KB |
n=2000 |
69 |
Correct |
20 ms |
24300 KB |
n=2000 |
70 |
Correct |
20 ms |
24300 KB |
n=2000 |
71 |
Correct |
21 ms |
24300 KB |
n=2000 |
72 |
Correct |
22 ms |
24320 KB |
n=2000 |
73 |
Correct |
20 ms |
24300 KB |
n=2000 |
74 |
Correct |
20 ms |
24300 KB |
n=1844 |
75 |
Correct |
20 ms |
24300 KB |
n=2000 |
76 |
Correct |
21 ms |
24428 KB |
n=2000 |
77 |
Correct |
21 ms |
24328 KB |
n=2000 |
78 |
Correct |
21 ms |
24300 KB |
n=2000 |
79 |
Correct |
21 ms |
24300 KB |
n=2000 |
80 |
Correct |
20 ms |
24428 KB |
n=2000 |
81 |
Correct |
21 ms |
24428 KB |
n=2000 |
82 |
Correct |
22 ms |
24300 KB |
n=2000 |
83 |
Correct |
20 ms |
24428 KB |
n=2000 |
84 |
Correct |
21 ms |
24300 KB |
n=2000 |
85 |
Correct |
21 ms |
24428 KB |
n=2000 |
86 |
Correct |
21 ms |
24428 KB |
n=2000 |
87 |
Correct |
21 ms |
24300 KB |
n=2000 |
88 |
Correct |
20 ms |
24428 KB |
n=2000 |
89 |
Correct |
20 ms |
24428 KB |
n=2000 |
90 |
Correct |
21 ms |
24428 KB |
n=2000 |
91 |
Correct |
20 ms |
24300 KB |
n=2000 |
92 |
Correct |
844 ms |
69652 KB |
n=200000 |
93 |
Correct |
939 ms |
73196 KB |
n=200000 |
94 |
Correct |
703 ms |
76652 KB |
n=200000 |
95 |
Correct |
830 ms |
69328 KB |
n=200000 |
96 |
Correct |
789 ms |
69728 KB |
n=200000 |
97 |
Correct |
1048 ms |
72484 KB |
n=200000 |
98 |
Correct |
817 ms |
69400 KB |
n=200000 |
99 |
Correct |
1014 ms |
68972 KB |
n=200000 |
100 |
Correct |
824 ms |
69584 KB |
n=200000 |
101 |
Correct |
626 ms |
77804 KB |
n=200000 |
102 |
Correct |
526 ms |
70508 KB |
n=200000 |
103 |
Correct |
522 ms |
70380 KB |
n=200000 |
104 |
Correct |
520 ms |
70636 KB |
n=200000 |
105 |
Correct |
526 ms |
70124 KB |
n=200000 |
106 |
Correct |
525 ms |
70124 KB |
n=200000 |
107 |
Correct |
549 ms |
70124 KB |
n=200000 |
108 |
Correct |
947 ms |
69228 KB |
n=200000 |
109 |
Correct |
947 ms |
69228 KB |
n=200000 |
110 |
Correct |
928 ms |
69100 KB |
n=200000 |
111 |
Correct |
858 ms |
69548 KB |
n=200000 |
112 |
Correct |
673 ms |
76832 KB |
n=200000 |
113 |
Correct |
982 ms |
72300 KB |
n=200000 |
114 |
Correct |
862 ms |
69380 KB |
n=200000 |
115 |
Correct |
1243 ms |
70252 KB |
n=200000 |
116 |
Correct |
790 ms |
69220 KB |
n=200000 |
117 |
Correct |
642 ms |
77164 KB |
n=200000 |
118 |
Correct |
1120 ms |
71404 KB |
n=200000 |
119 |
Correct |
787 ms |
69224 KB |
n=200000 |
120 |
Correct |
569 ms |
77600 KB |
n=200000 |
121 |
Correct |
588 ms |
77676 KB |
n=200000 |
122 |
Correct |
581 ms |
78084 KB |
n=200000 |
123 |
Correct |
556 ms |
69792 KB |
n=200000 |
124 |
Correct |
200 ms |
37612 KB |
n=25264 |