#include <stdio.h>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
#define F first
#define S second
typedef pair<int,int> pi;
const int INF=1e9+10;
struct line{
    int from;
    int to;
    int pos;
    int orpos;
    bool type;
    void in(){
        int px,py,qx,qy;
        scanf("%d%d%d%d",&px,&py,&qx,&qy);
        if(px==qx){
            type=false;
            orpos=pos=px;
            from=min(py,qy);
            to=max(py,qy);
        }
        else{
            type=true;
            orpos=pos=py;
            from=min(px,qx);
            to=max(px,qx);
        }
        return ;
    }
};
const int N=1e5+10;
struct seg{
    int ltop[N*4];
    int lbot[N*4];
    int rtop[N*4];
    int rbot[N*4];
    int size[N*4];
    void init(int n,int l,int r){
        ltop[n]=lbot[n]=rtop[n]=rbot[n]=-1;
        size[n]=0;
        if(r>l){
            int mid=(l+r)>>1;
            init(n*2+1,l,mid);
            init(n*2+2,mid+1,r);
        }
        return ;
    }
    bool ask(int n,int l,int r,int L,int R,int x){return asks(n,l,r,L,R)>=askl(n,l,r,L,R,x)+askr(n,l,r,L,R,x);}
    int askl(int n,int l,int r,int L,int R,int x){
        if(ltop[n]<=x)return asks(n,l,r,L,R);
        else if(L>r||l>R||lbot[n]>x)return 0;
        else{
            int mid=(l+r)>>1;
            return askl(n*2+1,l,mid,L,R,x)+askl(n*2+2,mid+1,r,L,R,x);
        }
    }
    int askr(int n,int l,int r,int L,int R,int x){
        if(rbot[n]>=x)return asks(n,l,r,L,R);
        else if(L>r||l>R||rtop[n]<x)return 0;
        else{
            int mid=(l+r)>>1;
            return askr(n*2+1,l,mid,L,R,x)+askr(n*2+2,mid+1,r,L,R,x);
        }
    }
    int asks(int n,int l,int r,int L,int R){
        if(L<=l&&r<=R)return size[n];
        else if(L>r||l>R)return 0;
        else{
            int mid=(l+r)>>1;
            return asks(n*2+1,l,mid,L,R)+asks(n*2+2,mid+1,r,L,R);
        }
    }
    void add(int n,int l,int r,int pos,int L,int R){
        size[n]++;
        if(l==r){
            rtop[n]=rbot[n]=R;
            ltop[n]=lbot[n]=L;
        }
        else{
            int mid=(l+r)>>1;
            if(pos>mid)add(n*2+2,mid+1,r,pos,L,R);
            else add(n*2+1,l,mid,pos,L,R);
            ltop[n]=max(ltop[n*2+1],ltop[n*2+2]);
            rtop[n]=max(rtop[n*2+1],rtop[n*2+2]);
            if(lbot[n*2+1]==-1)lbot[n]=lbot[n*2+2];
            else if(lbot[n*2+2]==-1)lbot[n]=lbot[n*2+1];
            else lbot[n]=min(lbot[n*2+1],lbot[n*2+2]);
            if(rbot[n*2+1]==-1)rbot[n]=rbot[n*2+2];
            else if(rbot[n*2+2]==-1)rbot[n]=rbot[n*2+1];
            else rbot[n]=min(rbot[n*2+1],rbot[n*2+2]);
        }
        return ;
    }
};
int main(){
    int n,lpos=0,rpos=0,left,right,mid,now=0;
    bool f;
    map<int,int> x[N],y[N],ll,rr;
    map<int,int>::iterator u;
    line a[N];
    pi l[N],r[N];
    seg L,R;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        a[i].in();
        if(a[i].type){
            l[lpos++]={a[i].pos,i};
            ll.insert({a[i].pos,0});
        }
        else {
            r[rpos++]={a[i].pos,i};
            rr.insert({a[i].pos,0});
        }
    }
    for(map<int,int>::iterator i=ll.begin();i!=ll.end();i++)i->S=now++;
    now=0;
    for(map<int,int>::iterator i=rr.begin();i!=rr.end();i++)i->S=now++;
    for(int i=0;i<n;i++){
        if(a[i].type)a[i].orpos=ll[a[i].orpos];
        else a[i].orpos=rr[a[i].orpos];
    }
    l[lpos++]={-1,N};
    r[rpos++]={-1,N};
    sort(l,l+lpos);
    sort(r,r+rpos);
    for(int i=0;i<lpos;i++)a[l[i].S].pos=i;
    for(int i=0;i<rpos;i++)a[r[i].S].pos=i;
    lpos++;
    rpos++;
    L.init(0,0,lpos-1);
    R.init(0,0,rpos-1);
    for(int i=0;i<n;i++){
        f=true;
        if(a[i].type){
            u=x[a[i].orpos].lower_bound(a[i].from);
            if(u!=x[a[i].orpos].end())if(u->F<=a[i].to)f=false;
            if(f&&u!=x[a[i].orpos].begin()){
                u--;
                if(u->S>=a[i].from)f=false;
            }
            if(f){
                x[a[i].orpos].insert({a[i].from,a[i].to});
                u=x[a[i].orpos].find(a[i].from);
            }
            else {
                printf("0\n");
                continue;
            }
            left=0;
            right=rpos-1;
            while(right-left>1){
                mid=(left+right)>>1;
                if(a[i].from<=r[mid].F)right=mid;
                else left=mid;
            }
            if(r[left].F>=a[i].from)a[i].from=left;
            else a[i].from=right;
            left=0;
            right=rpos-1;
            while(right-left>1){
                mid=(left+right)>>1;
                if(a[i].to>=r[mid].F)left=mid;
                else right=mid;
            }
            if(r[right].F<=a[i].to)a[i].to=right;
            else a[i].to=left;
            if(f&&!R.ask(0,0,rpos-1,a[i].from,a[i].to,a[i].pos))f=false;
            if(f){
                L.add(0,0,lpos-1,a[i].pos,a[i].from,a[i].to);
                printf("1\n");
            }
            else {
                x[a[i].orpos].erase(u);
                printf("0\n");
            }
        }
        else{
            u=y[a[i].orpos].lower_bound(a[i].from);
            if(u!=y[a[i].orpos].end())if(u->F<=a[i].to)f=false;
            if(f&&u!=y[a[i].orpos].begin()){
                u--;
                if(u->S>=a[i].from)f=false;
            }
            if(f){
                y[a[i].orpos].insert({a[i].from,a[i].to});
                u=y[a[i].orpos].find(a[i].from);
            }
            else {
                printf("0\n");
                continue;
            }
            left=0;
            right=lpos-1;
            while(right-left>1){
                mid=(left+right)>>1;
                if(a[i].from<=l[mid].F)right=mid;
                else left=mid;
            }
            if(l[left].F>=a[i].from)a[i].from=left;
            else a[i].from=right;
            left=0;
            right=lpos-1;
            while(right-left>1){
                mid=(left+right)>>1;
                if(a[i].to>=l[mid].F)left=mid;
                else right=mid;
            }
            if(l[right].F<=a[i].to)a[i].to=right;
            else a[i].to=left;
            if(f&&!L.ask(0,0,lpos-1,a[i].from,a[i].to,a[i].pos))f=false;
            if(f){
                R.add(0,0,rpos-1,a[i].pos,a[i].from,a[i].to);
                printf("1\n");
            }
            else {
                printf("0\n");
                y[a[i].orpos].erase(u);
            }
        }
    }
}


Measured memory_bytes: 30104