#include <bits/stdc++.h>
using namespace std;
const int nmax=2e5+1;
vector <int> g[nmax];
int ab[nmax*8],t[nmax*2];
void build(int nod, int st, int dr)
{
if(st==dr)
ab[nod]=t[st];
else
{
int mij=(st+dr)/2;
build(nod*2,st,mij);
build(nod*2+1,mij+1,dr);
ab[nod]=min(ab[nod*2],ab[nod*2+1]);
}
}
int k,n;
bool ok[nmax];
int prim[nmax],l[nmax];
void tur(int nod)
{
t[++k]=nod;
prim[nod]=k;
ok[nod]=true;
for(auto x : g[nod])
{
if(!ok[x])
tur(x);
t[++k]=nod;
}
}
int a,b,rez;
void qry(int nod, int st, int dr)
{
if(a<=st&&dr<=b)
{
rez=min(rez,ab[nod]);
}
else
{
int mij=(st+dr)/2;
if(a<=mij)
qry(nod*2,st,mij);
if(b>mij)
qry(nod*2+1,mij+1,dr);
}
}
set <int> sol1[nmax],sol2[nmax];
void mini(int x, int y)
{
a=min(prim[x],prim[y]);
b=max(prim[x],prim[y]);
rez=n+1;
qry(1,1,n*2-1);
}
std :: set <int> :: iterator it;
int main()
{
/// freopen("test.in","r",stdin);
/// freopen("test.out","w",stdout);
ios :: sync_with_stdio(false);
cin.tie(0);
int m,q,i,x,y;
cin>>n>>m>>q;
for(i=1;i<n;i++)
{
cin>>x>>y;
g[x].push_back(y);
g[y].push_back(x);
}
tur(1);
build(1,1,n*2-1);
for(i=1;i<=m;i++)
{
cin>>l[i];
sol1[l[i]].insert(i);
}
for(i=1;i<m;i++)
{
mini(l[i],l[i+1]);
sol2[rez].insert(i);
}
int tip,st,dr;
bool found;
while(q>0)
{
q--;
cin>>tip;
if(tip==1)
{
cin>>x>>y;
sol1[l[x]].erase(x);
sol1[y].insert(x);
if(x!=1)
{
mini(l[x],l[x-1]);
sol2[rez].erase(x-1);
mini(y,l[x-1]);
sol2[rez].insert(x-1);
}
if(x!=m)
{
mini(l[x],l[x+1]);
sol2[rez].erase(x);
mini(y,l[x+1]);
sol2[rez].insert(x);
}
l[x]=y;
}
else
{
cin>>st>>dr>>x;
found=false;
if(!sol1[x].empty())
{
it=sol1[x].lower_bound(st);
if(*it<=dr)
{
found=true;
cout<<*it<<" "<<*it<<'\n';
}
}
if(!found&&!sol2[x].empty())
{
it=sol2[x].lower_bound(st);
if(*it<dr)
{
found=true;
cout<<*it<<" "<<*it+1<<'\n';
}
}
if(!found)
cout<<"-1 -1"<<'\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
29264 KB |
n=5 |
2 |
Execution timed out |
4072 ms |
29264 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
29264 KB |
n=5 |
2 |
Execution timed out |
4072 ms |
29264 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
29264 KB |
n=5 |
2 |
Execution timed out |
4072 ms |
29264 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
29264 KB |
n=5 |
2 |
Execution timed out |
4072 ms |
29264 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |