#include <bits/stdc++.h>
using namespace std;
long long bg[300005],en[300005],pa[100005][35],ope=0,twos[40],inf=1e6+1;
long long fin(long long cur,long long lim)
{
for(int i=32;i>=0;i--)
{
//cout<<ope<<" ";
if(en[pa[cur][i]]<=en[lim]&&lim!=pa[cur][i])
{
if(pa[cur][i]!=cur)
ope+=twos[i];
cur=pa[cur][i];
}
//cout<<cur<<" ";
}
return cur;
}
int main()
{
twos[0]=1;
for(int i=1;i<34;i++)
twos[i]=twos[i-1]*2;
long long n,q;
bg[inf]=2e9;
en[inf]=2e9;
pa[inf][0]=inf;
cin>>n>>q;
set <pair <pair <long long, bool> , long long > > h;
set <pair <long long, long long > > cur;
cur.insert({1000000,inf});
set <long long> bef[100005];
bef[inf].insert(3e9);
for(int i=0;i<n;i++)
{
bef[i].insert(3e9);
pa[i][0]=inf;
cin>>bg[i]>>en[i];
h.insert({{bg[i],false},i});
h.insert({{en[i],true},i});
}
for(auto i: h)
{
if(i.first.second)
{
cur.erase({i.first.first*-1,i.second});
if(cur.size()>0){
auto fg = *cur.begin();
if(en[fg.second]!=en[i.second])
pa[i.second][0]=fg.second;
bef[fg.second].insert(bg[i.second]);
}
}
else
{
cur.insert({en[i.second]*-1,i.second});
}
}
for(int i=1;i<33;i++)
{
for(int j=0;j<n;j++)
{
pa[j][i]=pa[pa[j][i-1]][i-1];
//cout<<pa[j][i]<<" ";
}
}
for(int i=0;i<q;i++)
{
long long fr,sc;
ope=1;
cin>>fr>>sc;
fr--;
sc--;
if(fr==sc){
cout<<"0\n";
continue;
}
long long las=fin(fr,sc);
if(*bef[sc].begin()<=en[las]&&en[sc]>=en[fr]&&las!=inf)
{
cout<<ope<<"\n";
}
else{
cout<<"impossible\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
9828 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
9932 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
9932 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
9932 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
9924 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
9828 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |