#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) (x)*(x)
#define PB push_back
#define endl "\n"
#define y1 sfsdaf
#define pll pair<ll, ll>
using namespace std;
typedef double ld;
const ll N = 4e5 + 200;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
ll h[2 * N],ft[2 * N],n,d[2 * N],m,Q,x,y,st[2 * N];
pair<ll, ll> T[2 * N][25];
vector<pair<ll, ll> > a;
vector<ll> v[2 * N];
set<ll> s[2 * N],pisos[2 * N];
set<ll> :: iterator it;
void dfs(ll x,ll y)
{
h[x] = h[y] + 1;
T[a.size()][0] = {h[x], x};
ft[x] = a.size();
a.PB({h[x], x});
for(auto to : v[x]) if(!h[to])
{
dfs(to, x);
T[a.size()][0] = {h[x], x};
a.PB({h[x], x});
}
}
ll lca(ll a,ll b)
{
ll l,r,k;
l = ft[a];
r = ft[b];
if(l > r) swap(l, r);
k = st[r - l + 1];
return min(T[l][k], T[r - (1 << k) + 1][k]).se;
}
void ins(ll val,ll pos)
{
s[val].insert(pos);
}
void ers(ll val,ll pos)
{
s[val].erase(pos);
}
void build(ll m)
{
for(int i = 1; i <= m; i++) ins(lca(d[i], d[i + 1]), i);
}
int main()
{
ios_base::sync_with_stdio();cin.tie(0);cout.tie(0);
cin>>n>>m>>Q;
for(int i = 1; i < n; i++)
{
cin>>x>>y;
v[x].PB(y);
v[y].PB(x);
}
dfs(1, 1);
for(int i = 1; i < 2 * N; i++)
{
st[i] = st[i - 1];
if(1 << (st[i] + 1) <= i) st[i]++;
}
for(int j = 1; j < 20; j++)
{
x = (1 << (j - 1));
for(int i = 0; i + x < a.size(); i++) T[i][j] = min(T[i][j - 1], T[i + x][j - 1]);
}
for(int i = 1; i <= m; i++)
{
cin>>d[i];
pisos[d[i]].insert(i);
}
m--;
if(m) build(m);
while(Q--)
{
ll t,pos,x,l,r,v;
cin>>t;
if(t == 1)
{
cin>>pos>>x;
if(pos <= m) ers(lca(d[pos], d[pos + 1]), pos);
if(pos - 1 > 0) ers(lca(d[pos - 1], d[pos]), pos - 1);
pisos[d[pos]].erase(pos);
d[pos] = x;
pisos[d[pos]].insert(pos);
if(pos <= m) ins(lca(d[pos], d[pos + 1]), pos);
if(pos - 1 > 0) ins(lca(d[pos - 1], d[pos]), pos - 1);
} else
{
cin>>l>>r>>v;
if(!pisos[v].empty())
{
it = lower_bound(all(pisos[v]), l);
if(it != pisos[v].end() && *it <= r)
{
cout<<*it<<" "<<*it<<endl;
continue;
}
}
if(!s[v].empty())
{
it = lower_bound(all(s[v]), l);
if(it != s[v].end() && *it + 1 <= r)
{
cout<<*it<<" "<<*it + 1<<endl;
continue;
}
}
cout<<"-1 -1"<<endl;
}
}
return 0;
}
/*
1 1 1
1
2 1 1 1
*/
Compilation message
treearray.cpp: In function 'int main()':
treearray.cpp:79:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i + x < a.size(); i++) T[i][j] = min(T[i][j - 1], T[i + x][j - 1]);
~~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
100732 KB |
n=5 |
2 |
Correct |
98 ms |
100728 KB |
n=100 |
3 |
Correct |
100 ms |
100728 KB |
n=100 |
4 |
Correct |
98 ms |
100828 KB |
n=100 |
5 |
Correct |
99 ms |
100728 KB |
n=100 |
6 |
Correct |
99 ms |
100728 KB |
n=100 |
7 |
Correct |
98 ms |
100856 KB |
n=100 |
8 |
Correct |
98 ms |
100728 KB |
n=100 |
9 |
Correct |
98 ms |
100728 KB |
n=100 |
10 |
Correct |
100 ms |
100744 KB |
n=100 |
11 |
Correct |
98 ms |
100732 KB |
n=100 |
12 |
Correct |
98 ms |
100856 KB |
n=100 |
13 |
Correct |
99 ms |
100728 KB |
n=100 |
14 |
Correct |
97 ms |
100736 KB |
n=100 |
15 |
Correct |
99 ms |
100732 KB |
n=100 |
16 |
Correct |
98 ms |
100728 KB |
n=100 |
17 |
Correct |
98 ms |
100728 KB |
n=100 |
18 |
Correct |
99 ms |
100756 KB |
n=100 |
19 |
Correct |
97 ms |
100728 KB |
n=100 |
20 |
Correct |
98 ms |
100704 KB |
n=100 |
21 |
Correct |
98 ms |
100728 KB |
n=100 |
22 |
Correct |
107 ms |
100740 KB |
n=100 |
23 |
Correct |
99 ms |
100728 KB |
n=100 |
24 |
Correct |
104 ms |
100636 KB |
n=100 |
25 |
Correct |
140 ms |
100824 KB |
n=100 |
26 |
Correct |
98 ms |
100600 KB |
n=12 |
27 |
Correct |
103 ms |
100740 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
100732 KB |
n=5 |
2 |
Correct |
98 ms |
100728 KB |
n=100 |
3 |
Correct |
100 ms |
100728 KB |
n=100 |
4 |
Correct |
98 ms |
100828 KB |
n=100 |
5 |
Correct |
99 ms |
100728 KB |
n=100 |
6 |
Correct |
99 ms |
100728 KB |
n=100 |
7 |
Correct |
98 ms |
100856 KB |
n=100 |
8 |
Correct |
98 ms |
100728 KB |
n=100 |
9 |
Correct |
98 ms |
100728 KB |
n=100 |
10 |
Correct |
100 ms |
100744 KB |
n=100 |
11 |
Correct |
98 ms |
100732 KB |
n=100 |
12 |
Correct |
98 ms |
100856 KB |
n=100 |
13 |
Correct |
99 ms |
100728 KB |
n=100 |
14 |
Correct |
97 ms |
100736 KB |
n=100 |
15 |
Correct |
99 ms |
100732 KB |
n=100 |
16 |
Correct |
98 ms |
100728 KB |
n=100 |
17 |
Correct |
98 ms |
100728 KB |
n=100 |
18 |
Correct |
99 ms |
100756 KB |
n=100 |
19 |
Correct |
97 ms |
100728 KB |
n=100 |
20 |
Correct |
98 ms |
100704 KB |
n=100 |
21 |
Correct |
98 ms |
100728 KB |
n=100 |
22 |
Correct |
107 ms |
100740 KB |
n=100 |
23 |
Correct |
99 ms |
100728 KB |
n=100 |
24 |
Correct |
104 ms |
100636 KB |
n=100 |
25 |
Correct |
140 ms |
100824 KB |
n=100 |
26 |
Correct |
98 ms |
100600 KB |
n=12 |
27 |
Correct |
103 ms |
100740 KB |
n=100 |
28 |
Correct |
118 ms |
101140 KB |
n=500 |
29 |
Correct |
100 ms |
101180 KB |
n=500 |
30 |
Correct |
113 ms |
101040 KB |
n=500 |
31 |
Correct |
108 ms |
101200 KB |
n=500 |
32 |
Correct |
123 ms |
101112 KB |
n=500 |
33 |
Correct |
117 ms |
101144 KB |
n=500 |
34 |
Correct |
107 ms |
101112 KB |
n=500 |
35 |
Correct |
118 ms |
101248 KB |
n=500 |
36 |
Correct |
100 ms |
101112 KB |
n=500 |
37 |
Correct |
99 ms |
101112 KB |
n=500 |
38 |
Correct |
99 ms |
101112 KB |
n=500 |
39 |
Correct |
119 ms |
101112 KB |
n=500 |
40 |
Correct |
100 ms |
101080 KB |
n=500 |
41 |
Correct |
100 ms |
101128 KB |
n=500 |
42 |
Correct |
104 ms |
101164 KB |
n=500 |
43 |
Correct |
101 ms |
101120 KB |
n=500 |
44 |
Correct |
117 ms |
101112 KB |
n=500 |
45 |
Correct |
105 ms |
101208 KB |
n=500 |
46 |
Correct |
101 ms |
101172 KB |
n=500 |
47 |
Correct |
102 ms |
101044 KB |
n=500 |
48 |
Correct |
104 ms |
101036 KB |
n=500 |
49 |
Correct |
99 ms |
101112 KB |
n=500 |
50 |
Correct |
100 ms |
101112 KB |
n=500 |
51 |
Correct |
99 ms |
101112 KB |
n=500 |
52 |
Correct |
99 ms |
101112 KB |
n=500 |
53 |
Correct |
100 ms |
101128 KB |
n=500 |
54 |
Correct |
100 ms |
101112 KB |
n=500 |
55 |
Correct |
99 ms |
100984 KB |
n=278 |
56 |
Correct |
100 ms |
101112 KB |
n=500 |
57 |
Correct |
100 ms |
101112 KB |
n=500 |
58 |
Correct |
101 ms |
101020 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
100732 KB |
n=5 |
2 |
Correct |
98 ms |
100728 KB |
n=100 |
3 |
Correct |
100 ms |
100728 KB |
n=100 |
4 |
Correct |
98 ms |
100828 KB |
n=100 |
5 |
Correct |
99 ms |
100728 KB |
n=100 |
6 |
Correct |
99 ms |
100728 KB |
n=100 |
7 |
Correct |
98 ms |
100856 KB |
n=100 |
8 |
Correct |
98 ms |
100728 KB |
n=100 |
9 |
Correct |
98 ms |
100728 KB |
n=100 |
10 |
Correct |
100 ms |
100744 KB |
n=100 |
11 |
Correct |
98 ms |
100732 KB |
n=100 |
12 |
Correct |
98 ms |
100856 KB |
n=100 |
13 |
Correct |
99 ms |
100728 KB |
n=100 |
14 |
Correct |
97 ms |
100736 KB |
n=100 |
15 |
Correct |
99 ms |
100732 KB |
n=100 |
16 |
Correct |
98 ms |
100728 KB |
n=100 |
17 |
Correct |
98 ms |
100728 KB |
n=100 |
18 |
Correct |
99 ms |
100756 KB |
n=100 |
19 |
Correct |
97 ms |
100728 KB |
n=100 |
20 |
Correct |
98 ms |
100704 KB |
n=100 |
21 |
Correct |
98 ms |
100728 KB |
n=100 |
22 |
Correct |
107 ms |
100740 KB |
n=100 |
23 |
Correct |
99 ms |
100728 KB |
n=100 |
24 |
Correct |
104 ms |
100636 KB |
n=100 |
25 |
Correct |
140 ms |
100824 KB |
n=100 |
26 |
Correct |
98 ms |
100600 KB |
n=12 |
27 |
Correct |
103 ms |
100740 KB |
n=100 |
28 |
Correct |
118 ms |
101140 KB |
n=500 |
29 |
Correct |
100 ms |
101180 KB |
n=500 |
30 |
Correct |
113 ms |
101040 KB |
n=500 |
31 |
Correct |
108 ms |
101200 KB |
n=500 |
32 |
Correct |
123 ms |
101112 KB |
n=500 |
33 |
Correct |
117 ms |
101144 KB |
n=500 |
34 |
Correct |
107 ms |
101112 KB |
n=500 |
35 |
Correct |
118 ms |
101248 KB |
n=500 |
36 |
Correct |
100 ms |
101112 KB |
n=500 |
37 |
Correct |
99 ms |
101112 KB |
n=500 |
38 |
Correct |
99 ms |
101112 KB |
n=500 |
39 |
Correct |
119 ms |
101112 KB |
n=500 |
40 |
Correct |
100 ms |
101080 KB |
n=500 |
41 |
Correct |
100 ms |
101128 KB |
n=500 |
42 |
Correct |
104 ms |
101164 KB |
n=500 |
43 |
Correct |
101 ms |
101120 KB |
n=500 |
44 |
Correct |
117 ms |
101112 KB |
n=500 |
45 |
Correct |
105 ms |
101208 KB |
n=500 |
46 |
Correct |
101 ms |
101172 KB |
n=500 |
47 |
Correct |
102 ms |
101044 KB |
n=500 |
48 |
Correct |
104 ms |
101036 KB |
n=500 |
49 |
Correct |
99 ms |
101112 KB |
n=500 |
50 |
Correct |
100 ms |
101112 KB |
n=500 |
51 |
Correct |
99 ms |
101112 KB |
n=500 |
52 |
Correct |
99 ms |
101112 KB |
n=500 |
53 |
Correct |
100 ms |
101128 KB |
n=500 |
54 |
Correct |
100 ms |
101112 KB |
n=500 |
55 |
Correct |
99 ms |
100984 KB |
n=278 |
56 |
Correct |
100 ms |
101112 KB |
n=500 |
57 |
Correct |
100 ms |
101112 KB |
n=500 |
58 |
Correct |
101 ms |
101020 KB |
n=500 |
59 |
Correct |
127 ms |
102648 KB |
n=2000 |
60 |
Correct |
107 ms |
102764 KB |
n=2000 |
61 |
Correct |
108 ms |
102620 KB |
n=2000 |
62 |
Correct |
108 ms |
102752 KB |
n=2000 |
63 |
Correct |
137 ms |
102624 KB |
n=2000 |
64 |
Correct |
108 ms |
102772 KB |
n=2000 |
65 |
Correct |
140 ms |
102776 KB |
n=2000 |
66 |
Correct |
107 ms |
102660 KB |
n=2000 |
67 |
Correct |
121 ms |
102668 KB |
n=2000 |
68 |
Correct |
108 ms |
102716 KB |
n=2000 |
69 |
Correct |
107 ms |
102648 KB |
n=2000 |
70 |
Correct |
106 ms |
102648 KB |
n=2000 |
71 |
Correct |
106 ms |
102568 KB |
n=2000 |
72 |
Correct |
121 ms |
102648 KB |
n=2000 |
73 |
Correct |
107 ms |
102724 KB |
n=2000 |
74 |
Correct |
130 ms |
102524 KB |
n=1844 |
75 |
Correct |
107 ms |
102648 KB |
n=2000 |
76 |
Correct |
108 ms |
102648 KB |
n=2000 |
77 |
Correct |
107 ms |
102688 KB |
n=2000 |
78 |
Correct |
107 ms |
102648 KB |
n=2000 |
79 |
Correct |
122 ms |
102648 KB |
n=2000 |
80 |
Correct |
107 ms |
102648 KB |
n=2000 |
81 |
Correct |
107 ms |
102648 KB |
n=2000 |
82 |
Correct |
120 ms |
102544 KB |
n=2000 |
83 |
Correct |
106 ms |
102648 KB |
n=2000 |
84 |
Correct |
124 ms |
102520 KB |
n=2000 |
85 |
Correct |
108 ms |
102648 KB |
n=2000 |
86 |
Correct |
111 ms |
102792 KB |
n=2000 |
87 |
Correct |
108 ms |
102520 KB |
n=2000 |
88 |
Correct |
107 ms |
102776 KB |
n=2000 |
89 |
Correct |
109 ms |
102852 KB |
n=2000 |
90 |
Correct |
106 ms |
102776 KB |
n=2000 |
91 |
Correct |
107 ms |
102648 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
100732 KB |
n=5 |
2 |
Correct |
98 ms |
100728 KB |
n=100 |
3 |
Correct |
100 ms |
100728 KB |
n=100 |
4 |
Correct |
98 ms |
100828 KB |
n=100 |
5 |
Correct |
99 ms |
100728 KB |
n=100 |
6 |
Correct |
99 ms |
100728 KB |
n=100 |
7 |
Correct |
98 ms |
100856 KB |
n=100 |
8 |
Correct |
98 ms |
100728 KB |
n=100 |
9 |
Correct |
98 ms |
100728 KB |
n=100 |
10 |
Correct |
100 ms |
100744 KB |
n=100 |
11 |
Correct |
98 ms |
100732 KB |
n=100 |
12 |
Correct |
98 ms |
100856 KB |
n=100 |
13 |
Correct |
99 ms |
100728 KB |
n=100 |
14 |
Correct |
97 ms |
100736 KB |
n=100 |
15 |
Correct |
99 ms |
100732 KB |
n=100 |
16 |
Correct |
98 ms |
100728 KB |
n=100 |
17 |
Correct |
98 ms |
100728 KB |
n=100 |
18 |
Correct |
99 ms |
100756 KB |
n=100 |
19 |
Correct |
97 ms |
100728 KB |
n=100 |
20 |
Correct |
98 ms |
100704 KB |
n=100 |
21 |
Correct |
98 ms |
100728 KB |
n=100 |
22 |
Correct |
107 ms |
100740 KB |
n=100 |
23 |
Correct |
99 ms |
100728 KB |
n=100 |
24 |
Correct |
104 ms |
100636 KB |
n=100 |
25 |
Correct |
140 ms |
100824 KB |
n=100 |
26 |
Correct |
98 ms |
100600 KB |
n=12 |
27 |
Correct |
103 ms |
100740 KB |
n=100 |
28 |
Correct |
118 ms |
101140 KB |
n=500 |
29 |
Correct |
100 ms |
101180 KB |
n=500 |
30 |
Correct |
113 ms |
101040 KB |
n=500 |
31 |
Correct |
108 ms |
101200 KB |
n=500 |
32 |
Correct |
123 ms |
101112 KB |
n=500 |
33 |
Correct |
117 ms |
101144 KB |
n=500 |
34 |
Correct |
107 ms |
101112 KB |
n=500 |
35 |
Correct |
118 ms |
101248 KB |
n=500 |
36 |
Correct |
100 ms |
101112 KB |
n=500 |
37 |
Correct |
99 ms |
101112 KB |
n=500 |
38 |
Correct |
99 ms |
101112 KB |
n=500 |
39 |
Correct |
119 ms |
101112 KB |
n=500 |
40 |
Correct |
100 ms |
101080 KB |
n=500 |
41 |
Correct |
100 ms |
101128 KB |
n=500 |
42 |
Correct |
104 ms |
101164 KB |
n=500 |
43 |
Correct |
101 ms |
101120 KB |
n=500 |
44 |
Correct |
117 ms |
101112 KB |
n=500 |
45 |
Correct |
105 ms |
101208 KB |
n=500 |
46 |
Correct |
101 ms |
101172 KB |
n=500 |
47 |
Correct |
102 ms |
101044 KB |
n=500 |
48 |
Correct |
104 ms |
101036 KB |
n=500 |
49 |
Correct |
99 ms |
101112 KB |
n=500 |
50 |
Correct |
100 ms |
101112 KB |
n=500 |
51 |
Correct |
99 ms |
101112 KB |
n=500 |
52 |
Correct |
99 ms |
101112 KB |
n=500 |
53 |
Correct |
100 ms |
101128 KB |
n=500 |
54 |
Correct |
100 ms |
101112 KB |
n=500 |
55 |
Correct |
99 ms |
100984 KB |
n=278 |
56 |
Correct |
100 ms |
101112 KB |
n=500 |
57 |
Correct |
100 ms |
101112 KB |
n=500 |
58 |
Correct |
101 ms |
101020 KB |
n=500 |
59 |
Correct |
127 ms |
102648 KB |
n=2000 |
60 |
Correct |
107 ms |
102764 KB |
n=2000 |
61 |
Correct |
108 ms |
102620 KB |
n=2000 |
62 |
Correct |
108 ms |
102752 KB |
n=2000 |
63 |
Correct |
137 ms |
102624 KB |
n=2000 |
64 |
Correct |
108 ms |
102772 KB |
n=2000 |
65 |
Correct |
140 ms |
102776 KB |
n=2000 |
66 |
Correct |
107 ms |
102660 KB |
n=2000 |
67 |
Correct |
121 ms |
102668 KB |
n=2000 |
68 |
Correct |
108 ms |
102716 KB |
n=2000 |
69 |
Correct |
107 ms |
102648 KB |
n=2000 |
70 |
Correct |
106 ms |
102648 KB |
n=2000 |
71 |
Correct |
106 ms |
102568 KB |
n=2000 |
72 |
Correct |
121 ms |
102648 KB |
n=2000 |
73 |
Correct |
107 ms |
102724 KB |
n=2000 |
74 |
Correct |
130 ms |
102524 KB |
n=1844 |
75 |
Correct |
107 ms |
102648 KB |
n=2000 |
76 |
Correct |
108 ms |
102648 KB |
n=2000 |
77 |
Correct |
107 ms |
102688 KB |
n=2000 |
78 |
Correct |
107 ms |
102648 KB |
n=2000 |
79 |
Correct |
122 ms |
102648 KB |
n=2000 |
80 |
Correct |
107 ms |
102648 KB |
n=2000 |
81 |
Correct |
107 ms |
102648 KB |
n=2000 |
82 |
Correct |
120 ms |
102544 KB |
n=2000 |
83 |
Correct |
106 ms |
102648 KB |
n=2000 |
84 |
Correct |
124 ms |
102520 KB |
n=2000 |
85 |
Correct |
108 ms |
102648 KB |
n=2000 |
86 |
Correct |
111 ms |
102792 KB |
n=2000 |
87 |
Correct |
108 ms |
102520 KB |
n=2000 |
88 |
Correct |
107 ms |
102776 KB |
n=2000 |
89 |
Correct |
109 ms |
102852 KB |
n=2000 |
90 |
Correct |
106 ms |
102776 KB |
n=2000 |
91 |
Correct |
107 ms |
102648 KB |
n=2000 |
92 |
Runtime error |
452 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
93 |
Halted |
0 ms |
0 KB |
- |