#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define pb push_back
#define mp make_pair
#define taskname "A"
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
const int logn = log2(maxn) + 1;
int n , m , q;
vector<int> adj[maxn];
int a[maxn];
int P[maxn][logn] , dep[maxn];
void dfs(int u , int par){
for(auto c : adj[u]){
if(c == par)continue;
dep[c] = dep[u] + 1;
P[c][0] = u;
for(int i = 1 ; i < logn ; ++i)P[c][i] = P[P[c][i - 1]][i - 1];
dfs(c , u);
}
}
int lca(int u , int v){
if(dep[u] < dep[v])swap(u ,v);
for(int i = 0 ; i < logn ; ++i)if((dep[u] - dep[v]) & (1 << i))u = P[u][i];
if(u == v)return u;
for(int i = logn - 1 ; i >= 0 ; --i){
if(P[u][i] != P[v][i]){
u = P[u][i];
v = P[v][i];
}
}
return P[u][0];
}
set<int> s[maxn] , s1[maxn];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(taskname".INP","r")){
freopen(taskname".INP", "r",stdin);
freopen(taskname".OUT", "w",stdout);
}
cin >> n >> m >> q;
for(int i = 1 ; i < n ; ++i){
int u , v;cin >> u >> v;
adj[u].pb(v);adj[v].pb(u);
}
for(int i = 1 ; i <= m ; ++i)cin >> a[i];
dfs(1 , 0);
for(int i = 1 ; i < m ; ++i){
s1[lca(a[i] , a[i + 1])].insert(i);
}
for(int i = 1 ; i <= m ; ++i){
s[a[i]].insert(i);
}
while(q--){
int type;cin >> type;
if(type == 1){
int i , v;cin >> i >> v;
if(a[i] == v)continue;
s[a[i]].erase(i);
if(i > 1)s1[lca(a[i],a[i - 1])].erase(i - 1);
if(i + 1 <= m)s1[lca(a[i] , a[i + 1])].erase(i);
a[i] = v;
s[a[i]].insert(i);
if(i > 1)s1[lca(a[i],a[i - 1])].insert(i - 1);
if(i + 1 <= m)s1[lca(a[i] , a[i + 1])].insert(i);
}else{
int l , r , v;cin >> l >> r >> v;
auto it = s[v].lower_bound(l);
if(it == s[v].end() || *it > r){
auto it1 = s1[v].lower_bound(l);
if(it1 == s1[v].end() || *it1 + 1 > r){
cout << -1 << " " << -1 << '\n';
}else{
cout << *it1 << " " << *it1 + 1 << '\n';
}
}else{
cout << *it << " " << *it << '\n';
}
}
}
}
Compilation message
treearray.cpp: In function 'int main()':
treearray.cpp:54:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(taskname".INP", "r",stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:55:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(taskname".OUT", "w",stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
n=5 |
2 |
Correct |
19 ms |
23808 KB |
n=100 |
3 |
Correct |
19 ms |
23936 KB |
n=100 |
4 |
Correct |
18 ms |
23936 KB |
n=100 |
5 |
Correct |
18 ms |
23936 KB |
n=100 |
6 |
Correct |
18 ms |
23808 KB |
n=100 |
7 |
Correct |
18 ms |
23808 KB |
n=100 |
8 |
Correct |
21 ms |
23808 KB |
n=100 |
9 |
Correct |
21 ms |
23808 KB |
n=100 |
10 |
Correct |
18 ms |
23936 KB |
n=100 |
11 |
Correct |
18 ms |
23808 KB |
n=100 |
12 |
Correct |
18 ms |
23808 KB |
n=100 |
13 |
Correct |
19 ms |
23808 KB |
n=100 |
14 |
Correct |
18 ms |
23808 KB |
n=100 |
15 |
Correct |
18 ms |
23808 KB |
n=100 |
16 |
Correct |
18 ms |
23808 KB |
n=100 |
17 |
Correct |
20 ms |
23808 KB |
n=100 |
18 |
Correct |
18 ms |
23808 KB |
n=100 |
19 |
Correct |
18 ms |
23808 KB |
n=100 |
20 |
Correct |
18 ms |
23808 KB |
n=100 |
21 |
Correct |
18 ms |
23936 KB |
n=100 |
22 |
Correct |
18 ms |
23808 KB |
n=100 |
23 |
Correct |
18 ms |
23832 KB |
n=100 |
24 |
Correct |
18 ms |
23808 KB |
n=100 |
25 |
Correct |
19 ms |
23808 KB |
n=100 |
26 |
Correct |
18 ms |
23808 KB |
n=12 |
27 |
Correct |
18 ms |
23936 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
n=5 |
2 |
Correct |
19 ms |
23808 KB |
n=100 |
3 |
Correct |
19 ms |
23936 KB |
n=100 |
4 |
Correct |
18 ms |
23936 KB |
n=100 |
5 |
Correct |
18 ms |
23936 KB |
n=100 |
6 |
Correct |
18 ms |
23808 KB |
n=100 |
7 |
Correct |
18 ms |
23808 KB |
n=100 |
8 |
Correct |
21 ms |
23808 KB |
n=100 |
9 |
Correct |
21 ms |
23808 KB |
n=100 |
10 |
Correct |
18 ms |
23936 KB |
n=100 |
11 |
Correct |
18 ms |
23808 KB |
n=100 |
12 |
Correct |
18 ms |
23808 KB |
n=100 |
13 |
Correct |
19 ms |
23808 KB |
n=100 |
14 |
Correct |
18 ms |
23808 KB |
n=100 |
15 |
Correct |
18 ms |
23808 KB |
n=100 |
16 |
Correct |
18 ms |
23808 KB |
n=100 |
17 |
Correct |
20 ms |
23808 KB |
n=100 |
18 |
Correct |
18 ms |
23808 KB |
n=100 |
19 |
Correct |
18 ms |
23808 KB |
n=100 |
20 |
Correct |
18 ms |
23808 KB |
n=100 |
21 |
Correct |
18 ms |
23936 KB |
n=100 |
22 |
Correct |
18 ms |
23808 KB |
n=100 |
23 |
Correct |
18 ms |
23832 KB |
n=100 |
24 |
Correct |
18 ms |
23808 KB |
n=100 |
25 |
Correct |
19 ms |
23808 KB |
n=100 |
26 |
Correct |
18 ms |
23808 KB |
n=12 |
27 |
Correct |
18 ms |
23936 KB |
n=100 |
28 |
Correct |
19 ms |
23936 KB |
n=500 |
29 |
Correct |
19 ms |
23936 KB |
n=500 |
30 |
Correct |
20 ms |
23936 KB |
n=500 |
31 |
Correct |
21 ms |
23936 KB |
n=500 |
32 |
Correct |
21 ms |
23936 KB |
n=500 |
33 |
Correct |
19 ms |
23936 KB |
n=500 |
34 |
Correct |
19 ms |
23936 KB |
n=500 |
35 |
Correct |
19 ms |
23936 KB |
n=500 |
36 |
Correct |
19 ms |
23936 KB |
n=500 |
37 |
Correct |
19 ms |
23936 KB |
n=500 |
38 |
Correct |
22 ms |
23936 KB |
n=500 |
39 |
Correct |
19 ms |
23936 KB |
n=500 |
40 |
Correct |
18 ms |
23936 KB |
n=500 |
41 |
Correct |
19 ms |
23936 KB |
n=500 |
42 |
Correct |
19 ms |
23936 KB |
n=500 |
43 |
Correct |
19 ms |
23936 KB |
n=500 |
44 |
Correct |
21 ms |
24064 KB |
n=500 |
45 |
Correct |
19 ms |
23936 KB |
n=500 |
46 |
Correct |
19 ms |
23936 KB |
n=500 |
47 |
Correct |
19 ms |
24064 KB |
n=500 |
48 |
Correct |
19 ms |
23936 KB |
n=500 |
49 |
Correct |
19 ms |
24064 KB |
n=500 |
50 |
Correct |
19 ms |
23936 KB |
n=500 |
51 |
Correct |
19 ms |
24064 KB |
n=500 |
52 |
Correct |
22 ms |
23936 KB |
n=500 |
53 |
Correct |
19 ms |
23936 KB |
n=500 |
54 |
Correct |
19 ms |
23936 KB |
n=500 |
55 |
Correct |
18 ms |
23936 KB |
n=278 |
56 |
Correct |
21 ms |
24064 KB |
n=500 |
57 |
Correct |
18 ms |
23936 KB |
n=500 |
58 |
Correct |
21 ms |
23936 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
n=5 |
2 |
Correct |
19 ms |
23808 KB |
n=100 |
3 |
Correct |
19 ms |
23936 KB |
n=100 |
4 |
Correct |
18 ms |
23936 KB |
n=100 |
5 |
Correct |
18 ms |
23936 KB |
n=100 |
6 |
Correct |
18 ms |
23808 KB |
n=100 |
7 |
Correct |
18 ms |
23808 KB |
n=100 |
8 |
Correct |
21 ms |
23808 KB |
n=100 |
9 |
Correct |
21 ms |
23808 KB |
n=100 |
10 |
Correct |
18 ms |
23936 KB |
n=100 |
11 |
Correct |
18 ms |
23808 KB |
n=100 |
12 |
Correct |
18 ms |
23808 KB |
n=100 |
13 |
Correct |
19 ms |
23808 KB |
n=100 |
14 |
Correct |
18 ms |
23808 KB |
n=100 |
15 |
Correct |
18 ms |
23808 KB |
n=100 |
16 |
Correct |
18 ms |
23808 KB |
n=100 |
17 |
Correct |
20 ms |
23808 KB |
n=100 |
18 |
Correct |
18 ms |
23808 KB |
n=100 |
19 |
Correct |
18 ms |
23808 KB |
n=100 |
20 |
Correct |
18 ms |
23808 KB |
n=100 |
21 |
Correct |
18 ms |
23936 KB |
n=100 |
22 |
Correct |
18 ms |
23808 KB |
n=100 |
23 |
Correct |
18 ms |
23832 KB |
n=100 |
24 |
Correct |
18 ms |
23808 KB |
n=100 |
25 |
Correct |
19 ms |
23808 KB |
n=100 |
26 |
Correct |
18 ms |
23808 KB |
n=12 |
27 |
Correct |
18 ms |
23936 KB |
n=100 |
28 |
Correct |
19 ms |
23936 KB |
n=500 |
29 |
Correct |
19 ms |
23936 KB |
n=500 |
30 |
Correct |
20 ms |
23936 KB |
n=500 |
31 |
Correct |
21 ms |
23936 KB |
n=500 |
32 |
Correct |
21 ms |
23936 KB |
n=500 |
33 |
Correct |
19 ms |
23936 KB |
n=500 |
34 |
Correct |
19 ms |
23936 KB |
n=500 |
35 |
Correct |
19 ms |
23936 KB |
n=500 |
36 |
Correct |
19 ms |
23936 KB |
n=500 |
37 |
Correct |
19 ms |
23936 KB |
n=500 |
38 |
Correct |
22 ms |
23936 KB |
n=500 |
39 |
Correct |
19 ms |
23936 KB |
n=500 |
40 |
Correct |
18 ms |
23936 KB |
n=500 |
41 |
Correct |
19 ms |
23936 KB |
n=500 |
42 |
Correct |
19 ms |
23936 KB |
n=500 |
43 |
Correct |
19 ms |
23936 KB |
n=500 |
44 |
Correct |
21 ms |
24064 KB |
n=500 |
45 |
Correct |
19 ms |
23936 KB |
n=500 |
46 |
Correct |
19 ms |
23936 KB |
n=500 |
47 |
Correct |
19 ms |
24064 KB |
n=500 |
48 |
Correct |
19 ms |
23936 KB |
n=500 |
49 |
Correct |
19 ms |
24064 KB |
n=500 |
50 |
Correct |
19 ms |
23936 KB |
n=500 |
51 |
Correct |
19 ms |
24064 KB |
n=500 |
52 |
Correct |
22 ms |
23936 KB |
n=500 |
53 |
Correct |
19 ms |
23936 KB |
n=500 |
54 |
Correct |
19 ms |
23936 KB |
n=500 |
55 |
Correct |
18 ms |
23936 KB |
n=278 |
56 |
Correct |
21 ms |
24064 KB |
n=500 |
57 |
Correct |
18 ms |
23936 KB |
n=500 |
58 |
Correct |
21 ms |
23936 KB |
n=500 |
59 |
Correct |
24 ms |
24320 KB |
n=2000 |
60 |
Correct |
22 ms |
24448 KB |
n=2000 |
61 |
Correct |
22 ms |
24448 KB |
n=2000 |
62 |
Correct |
22 ms |
24320 KB |
n=2000 |
63 |
Correct |
22 ms |
24320 KB |
n=2000 |
64 |
Correct |
22 ms |
24448 KB |
n=2000 |
65 |
Correct |
22 ms |
24320 KB |
n=2000 |
66 |
Correct |
24 ms |
24320 KB |
n=2000 |
67 |
Correct |
22 ms |
24320 KB |
n=2000 |
68 |
Correct |
21 ms |
24320 KB |
n=2000 |
69 |
Correct |
22 ms |
24320 KB |
n=2000 |
70 |
Correct |
21 ms |
24320 KB |
n=2000 |
71 |
Correct |
26 ms |
24320 KB |
n=2000 |
72 |
Correct |
20 ms |
24296 KB |
n=2000 |
73 |
Correct |
24 ms |
24320 KB |
n=2000 |
74 |
Correct |
21 ms |
24320 KB |
n=1844 |
75 |
Correct |
24 ms |
24296 KB |
n=2000 |
76 |
Correct |
22 ms |
24320 KB |
n=2000 |
77 |
Correct |
26 ms |
24312 KB |
n=2000 |
78 |
Correct |
21 ms |
24320 KB |
n=2000 |
79 |
Correct |
26 ms |
24320 KB |
n=2000 |
80 |
Correct |
22 ms |
24320 KB |
n=2000 |
81 |
Correct |
26 ms |
24448 KB |
n=2000 |
82 |
Correct |
21 ms |
24320 KB |
n=2000 |
83 |
Correct |
22 ms |
24448 KB |
n=2000 |
84 |
Correct |
21 ms |
24448 KB |
n=2000 |
85 |
Correct |
29 ms |
24320 KB |
n=2000 |
86 |
Correct |
22 ms |
24448 KB |
n=2000 |
87 |
Correct |
22 ms |
24320 KB |
n=2000 |
88 |
Correct |
25 ms |
24448 KB |
n=2000 |
89 |
Correct |
22 ms |
24448 KB |
n=2000 |
90 |
Correct |
21 ms |
24448 KB |
n=2000 |
91 |
Correct |
21 ms |
24320 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
n=5 |
2 |
Correct |
19 ms |
23808 KB |
n=100 |
3 |
Correct |
19 ms |
23936 KB |
n=100 |
4 |
Correct |
18 ms |
23936 KB |
n=100 |
5 |
Correct |
18 ms |
23936 KB |
n=100 |
6 |
Correct |
18 ms |
23808 KB |
n=100 |
7 |
Correct |
18 ms |
23808 KB |
n=100 |
8 |
Correct |
21 ms |
23808 KB |
n=100 |
9 |
Correct |
21 ms |
23808 KB |
n=100 |
10 |
Correct |
18 ms |
23936 KB |
n=100 |
11 |
Correct |
18 ms |
23808 KB |
n=100 |
12 |
Correct |
18 ms |
23808 KB |
n=100 |
13 |
Correct |
19 ms |
23808 KB |
n=100 |
14 |
Correct |
18 ms |
23808 KB |
n=100 |
15 |
Correct |
18 ms |
23808 KB |
n=100 |
16 |
Correct |
18 ms |
23808 KB |
n=100 |
17 |
Correct |
20 ms |
23808 KB |
n=100 |
18 |
Correct |
18 ms |
23808 KB |
n=100 |
19 |
Correct |
18 ms |
23808 KB |
n=100 |
20 |
Correct |
18 ms |
23808 KB |
n=100 |
21 |
Correct |
18 ms |
23936 KB |
n=100 |
22 |
Correct |
18 ms |
23808 KB |
n=100 |
23 |
Correct |
18 ms |
23832 KB |
n=100 |
24 |
Correct |
18 ms |
23808 KB |
n=100 |
25 |
Correct |
19 ms |
23808 KB |
n=100 |
26 |
Correct |
18 ms |
23808 KB |
n=12 |
27 |
Correct |
18 ms |
23936 KB |
n=100 |
28 |
Correct |
19 ms |
23936 KB |
n=500 |
29 |
Correct |
19 ms |
23936 KB |
n=500 |
30 |
Correct |
20 ms |
23936 KB |
n=500 |
31 |
Correct |
21 ms |
23936 KB |
n=500 |
32 |
Correct |
21 ms |
23936 KB |
n=500 |
33 |
Correct |
19 ms |
23936 KB |
n=500 |
34 |
Correct |
19 ms |
23936 KB |
n=500 |
35 |
Correct |
19 ms |
23936 KB |
n=500 |
36 |
Correct |
19 ms |
23936 KB |
n=500 |
37 |
Correct |
19 ms |
23936 KB |
n=500 |
38 |
Correct |
22 ms |
23936 KB |
n=500 |
39 |
Correct |
19 ms |
23936 KB |
n=500 |
40 |
Correct |
18 ms |
23936 KB |
n=500 |
41 |
Correct |
19 ms |
23936 KB |
n=500 |
42 |
Correct |
19 ms |
23936 KB |
n=500 |
43 |
Correct |
19 ms |
23936 KB |
n=500 |
44 |
Correct |
21 ms |
24064 KB |
n=500 |
45 |
Correct |
19 ms |
23936 KB |
n=500 |
46 |
Correct |
19 ms |
23936 KB |
n=500 |
47 |
Correct |
19 ms |
24064 KB |
n=500 |
48 |
Correct |
19 ms |
23936 KB |
n=500 |
49 |
Correct |
19 ms |
24064 KB |
n=500 |
50 |
Correct |
19 ms |
23936 KB |
n=500 |
51 |
Correct |
19 ms |
24064 KB |
n=500 |
52 |
Correct |
22 ms |
23936 KB |
n=500 |
53 |
Correct |
19 ms |
23936 KB |
n=500 |
54 |
Correct |
19 ms |
23936 KB |
n=500 |
55 |
Correct |
18 ms |
23936 KB |
n=278 |
56 |
Correct |
21 ms |
24064 KB |
n=500 |
57 |
Correct |
18 ms |
23936 KB |
n=500 |
58 |
Correct |
21 ms |
23936 KB |
n=500 |
59 |
Correct |
24 ms |
24320 KB |
n=2000 |
60 |
Correct |
22 ms |
24448 KB |
n=2000 |
61 |
Correct |
22 ms |
24448 KB |
n=2000 |
62 |
Correct |
22 ms |
24320 KB |
n=2000 |
63 |
Correct |
22 ms |
24320 KB |
n=2000 |
64 |
Correct |
22 ms |
24448 KB |
n=2000 |
65 |
Correct |
22 ms |
24320 KB |
n=2000 |
66 |
Correct |
24 ms |
24320 KB |
n=2000 |
67 |
Correct |
22 ms |
24320 KB |
n=2000 |
68 |
Correct |
21 ms |
24320 KB |
n=2000 |
69 |
Correct |
22 ms |
24320 KB |
n=2000 |
70 |
Correct |
21 ms |
24320 KB |
n=2000 |
71 |
Correct |
26 ms |
24320 KB |
n=2000 |
72 |
Correct |
20 ms |
24296 KB |
n=2000 |
73 |
Correct |
24 ms |
24320 KB |
n=2000 |
74 |
Correct |
21 ms |
24320 KB |
n=1844 |
75 |
Correct |
24 ms |
24296 KB |
n=2000 |
76 |
Correct |
22 ms |
24320 KB |
n=2000 |
77 |
Correct |
26 ms |
24312 KB |
n=2000 |
78 |
Correct |
21 ms |
24320 KB |
n=2000 |
79 |
Correct |
26 ms |
24320 KB |
n=2000 |
80 |
Correct |
22 ms |
24320 KB |
n=2000 |
81 |
Correct |
26 ms |
24448 KB |
n=2000 |
82 |
Correct |
21 ms |
24320 KB |
n=2000 |
83 |
Correct |
22 ms |
24448 KB |
n=2000 |
84 |
Correct |
21 ms |
24448 KB |
n=2000 |
85 |
Correct |
29 ms |
24320 KB |
n=2000 |
86 |
Correct |
22 ms |
24448 KB |
n=2000 |
87 |
Correct |
22 ms |
24320 KB |
n=2000 |
88 |
Correct |
25 ms |
24448 KB |
n=2000 |
89 |
Correct |
22 ms |
24448 KB |
n=2000 |
90 |
Correct |
21 ms |
24448 KB |
n=2000 |
91 |
Correct |
21 ms |
24320 KB |
n=2000 |
92 |
Correct |
861 ms |
73176 KB |
n=200000 |
93 |
Correct |
1306 ms |
78200 KB |
n=200000 |
94 |
Correct |
1450 ms |
81400 KB |
n=200000 |
95 |
Correct |
950 ms |
73004 KB |
n=200000 |
96 |
Correct |
902 ms |
73196 KB |
n=200000 |
97 |
Correct |
1326 ms |
77176 KB |
n=200000 |
98 |
Correct |
757 ms |
72936 KB |
n=200000 |
99 |
Correct |
963 ms |
73080 KB |
n=200000 |
100 |
Correct |
806 ms |
72920 KB |
n=200000 |
101 |
Correct |
1235 ms |
82644 KB |
n=200000 |
102 |
Correct |
538 ms |
74120 KB |
n=200000 |
103 |
Correct |
508 ms |
74104 KB |
n=200000 |
104 |
Correct |
470 ms |
74104 KB |
n=200000 |
105 |
Correct |
534 ms |
74488 KB |
n=200000 |
106 |
Correct |
475 ms |
74488 KB |
n=200000 |
107 |
Correct |
486 ms |
74492 KB |
n=200000 |
108 |
Correct |
977 ms |
73208 KB |
n=200000 |
109 |
Correct |
954 ms |
73012 KB |
n=200000 |
110 |
Correct |
1057 ms |
73028 KB |
n=200000 |
111 |
Correct |
933 ms |
72560 KB |
n=200000 |
112 |
Correct |
1157 ms |
81656 KB |
n=200000 |
113 |
Correct |
1281 ms |
77176 KB |
n=200000 |
114 |
Correct |
871 ms |
72552 KB |
n=200000 |
115 |
Correct |
1242 ms |
75384 KB |
n=200000 |
116 |
Correct |
776 ms |
73064 KB |
n=200000 |
117 |
Correct |
1289 ms |
81944 KB |
n=200000 |
118 |
Correct |
1187 ms |
75952 KB |
n=200000 |
119 |
Correct |
794 ms |
73064 KB |
n=200000 |
120 |
Correct |
1073 ms |
81528 KB |
n=200000 |
121 |
Correct |
1256 ms |
81792 KB |
n=200000 |
122 |
Correct |
1079 ms |
82048 KB |
n=200000 |
123 |
Correct |
549 ms |
74396 KB |
n=200000 |
124 |
Correct |
243 ms |
38520 KB |
n=25264 |