Submission #603052

# Submission time Handle Problem Language Result Execution time Memory
603052 2022-07-23T14:36:21 Z DanerZein Event Hopping (BOI22_events) C++14
0 / 100
47 ms 3840 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
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 ord[MAX_N];
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int q; cin>>n>>q;
  vector<iii> t1;
  for(int i=0;i<n;i++){
    int a,b; cin>>a>>b;
    ev.push_back(ii(a,b));
    t1.push_back(iii(ii(a,b),i));
  }
  memset(ord,-1,sizeof ord);
  sort(t1.begin(),t1.end());
  int c=0;
  int o=0;
  for(int i=0;i<n-1;i++){
    int u=t1[i].second;
    if(t1[i].first.first<=t1[i+1].first.second && t1[i+1].first.second<=t1[i].first.second){
      con[t1[i+1].second]=c;
    }
    else c++;
    ord[u]=o++;
  }
  /*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--;
    if(s==e){
      cout<<"0\n";
      continue;
    }
    bool im=0;
    if(con[s]==con[e]){
      if(ord[s]<ord[e]) cout<<ord[e]-ord[s]<<"\n";
      else im=1;
    }
    else im=1;
    if(im) cout<<"impossible\n";
      /*bfs(s);
    if(dis[e]>=MAX) cout<<"impossible\n";
    else cout<<dis[e]<<endl;*/
  }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 3840 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -