# 605D A. Board Game set+树状数组思想

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> Vi;
const int maxn=100005;
int tmp[maxn<<1],cnt,n,a[maxn],pre[maxn];
int b[maxn],c[maxn],d[maxn],dist[maxn];
set<pii> S[maxn<<1+5];
set<pii>::iterator it,last;
int lowbit(int x){
return x&(-x);
}
while(x<(maxn<<1)){
S[x].insert(p);
x+=lowbit(x);
}
}
Vi query(int x,int y){
Vi ret; ret.clear();
while(x){
last=S[x].upper_bound({y,maxn});
for(it=S[x].begin();it!=last;it++){
ret.push_back(it->second);
}
S[x].erase(S[x].begin(),last);
x-=lowbit(x);
}
return ret;
}
void bfs(){
memset(dist,-1,sizeof(dist));
memset(pre,-1,sizeof(pre));
Vi First = query(1,0);
queue<int> q;
for(auto x:First) q.push(x),dist[x]=1;
while(!q.empty()){
int u=q.front(); q.pop();
Vi nex=query(c[u],d[u]);
for(auto v:nex){
if(dist[v]==-1){
dist[v]=dist[u]+1;
pre[v]=u;
q.push(v);
}
}
}
}
int main(){
scanf("%d",&n);
tmp[++cnt]=0;
rep(i,1,n){
scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
tmp[++cnt]=a[i],tmp[++cnt]=c[i];
}
sort(tmp+1,tmp+1+cnt);
cnt=unique(tmp+1,tmp+1+cnt)-tmp-1;
rep(i,1,n){
a[i]=lower_bound(tmp+1,tmp+1+cnt,a[i])-tmp;
c[i]=lower_bound(tmp+1,tmp+1+cnt,c[i])-tmp;
}
bfs();
if(dist[n]==-1) printf("-1\n");
else{
stack<int> Sa;
int now=n;
while(now!=-1){
Sa.push(now);
now=pre[now];
}
int sz=Sa.size();
printf("%d\n",sz);
for(int i=1;i<=sz;i++){
printf("%d%c",Sa.top(),i==sz?'\n':' ');
Sa.pop();
}
}
return 0;
}

12-21 1250

08-01 1485
05-14 37