#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
const int MAX_N=1e5+10;
const int MAX=1e9;
vector<vi> G;
vii ev;
int dis[MAX_N];
int n;
bool isq[MAX_N];
void bfs(int u){
for(int i=0;i<n;i++) dis[i]=MAX;
dis[u]=0; isq[u]=1;
queue<int> q; q.push(u);
while(!q.empty()){
int x=q.front(); q.pop();
isq[x]=0;
for(auto &v:G[x]){
if(dis[v]>dis[x]+1){
dis[v]=dis[x]+1;
if(!isq[v]){
isq[v]=1;
q.push(v);
}
}
}
}
}
int con[MAX_N];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int q; cin>>n>>q;
for(int i=0;i<n;i++){
int a,b; cin>>a>>b;
ev.push_back(ii(a,b));
}
memset(con,-1,sizeof con);
sort(ev.begin(),ev.end());
/*G.resize(n+1);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(ev[j].first<=ev[i].second && ev[i].second<=ev[j].second){
G[i].push_back(j);
}
}
}*/
while(q--){
int s,e; cin>>s>>e;
s--; e--;
bool im=1;
if(ev[s].first<=ev[e].second && ev[s].first>=ev[e].second)
im=0;
if(im) cout<<"impossible\n";
else {
if(s==e) cout<<"0\n";
else
cout<<"1\n";
}
/*bfs(s);
if(dis[e]>=MAX) cout<<"impossible\n";
else cout<<dis[e]<<endl;*/
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
52 ms |
2700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |