# CF 983D Arkady and Rectangles

xiaoxiao2021-03-01  6

#include<bits/stdc++.h> #define N 200005 using namespace std; int n,A[N],B[N],C[N],D[N],ans,flag[N]; int n1[N],n2[N],t1,t2,T1,T2; struct info{int maxn,minn;}t[N*4]; vector<int>s[N]; set<int>q[N*4]; class seg_tree { void update(int x,int l,int r) { int lc=x<<1,rc=lc+1; if(l==r)t[x].minn=t[x].maxn=0; else { t[x].minn=min(t[lc].minn,t[rc].minn); t[x].maxn=max(t[lc].maxn,t[rc].maxn); } if(q[x].size()) { if(flag[*q[x].rbegin()]) t[x].minn=max(t[x].minn,*q[x].rbegin()); else t[x].maxn=max(t[x].maxn,*q[x].rbegin()); } if(t[x].maxn<t[x].minn)t[x].maxn=0; } public: void modify(int x,int l,int r,int ql,int qr,int col) { if(ql<=l&&r<=qr) { if(col>0)q[x].insert(col); else q[x].erase(-col); update(x,l,r);return; } int mid=l+r>>1,lc=x<<1,rc=lc+1; if(ql<=mid)modify(lc,l,mid,ql,qr,col); if(qr>mid)modify(rc,mid+1,r,ql,qr,col); update(x,l,r); } }T; int main() { int x,y; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d%d%d%d",&A[i],&B[i],&C[i],&D[i]); n1[++t1]=A[i];n1[++t1]=C[i]; n2[++t2]=B[i];n2[++t2]=D[i]; } sort(n1+1,n1+t1+1);sort(n2+1,n2+t2+1); T1=unique(n1+1,n1+t1+1)-n1-1; T2=unique(n2+1,n2+t2+1)-n2-1; for(int i=1;i<=n;i++) { A[i]=lower_bound(n1+1,n1+T1+1,A[i])-n1; B[i]=lower_bound(n2+1,n2+T2+1,B[i])-n2; C[i]=lower_bound(n1+1,n1+T1+1,C[i])-n1; D[i]=lower_bound(n2+1,n2+T2+1,D[i])-n2-1; s[A[i]].push_back(i); s[C[i]].push_back(-i); } for(int i=1;i<=T1;i++) { for(int j=0;j<s[i].size();j++) { y=s[i][j];x=abs(y); T.modify(1,1,T2,B[x],D[x],y); } while(t[1].maxn) { x=t[1].maxn;flag[x]=1;ans++; T.modify(1,1,T2,B[x],D[x],0); } } printf("%d\n",ans+1); return 0; }