#include <bits/stdc++.h>   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   inline int read() {     int f = 1, x = 0;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = -1LL;     } while (ch <  0  || ch >  9 );     do {       x = x * 10 + ch -  0 ;       ch = getchar();     } while (ch >=  0  && ch <=  9 );     return f * x;   }   template <class T>   inline void chmax(T &a, T b) {     if (a < b) a = b;   }   template <class T>   inline void chmin(T &a, T b) {     if (a > b) a = b;   }   inline void swap(int &a, int &b) {     int c = a;     a = b;     b = c;   }   using namespace std;   const int N = 4e5 + 10;   set<int> seg[N << 2];   int mx[N << 2], mn[N << 2];   struct node {     int x1, y1, x2, y2;   } a[N];   inline void show(node a) { printf( %d %d %d %d n , a.x1, a.y1, a.x2, a.y2); }   vector<int> ins[N], era[N];   int n, px[N << 1], py[N << 1], totx, toty, lenx, leny, ok[N];   inline void upd(int cur) {     int mxp;     if (seg[cur].size()) {       mxp = *(--seg[cur].end());     } else {       mxp = -1;     }     int mxt = max(mx[cur << 1], mx[cur << 1 | 1]);     int mnt = min(mn[cur << 1], mn[cur << 1 | 1]);     if (mxp > mxt) {       if (ok[mxp] || mxp < mnt) {         mx[cur] = -1;       } else {         mx[cur] = mxp;       }     } else {       mx[cur] = mxt;     }     mn[cur] = max(mxp, mnt);   }   inline void cover(int cur, int L, int R, int l, int r, int id, int fl) {     if (l > r) return;     if (l <= L && r >= R) {       if (fl == 1) {         seg[cur].insert(id);       } else if (fl == -1) {         seg[cur].erase(id);       }       upd(cur);       return;     }     int mid = (L + R) >> 1;     if (l <= mid) cover(cur << 1, L, mid, l, r, id, fl);     if (r > mid) cover(cur << 1 | 1, mid + 1, R, l, r, id, fl);     upd(cur);   }   inline void norx(int &x) {     x = (int)(lower_bound(px + 1, px + lenx + 1, x) - px);   }   inline void nory(int &x) {     x = (int)(lower_bound(py + 1, py + leny + 1, x) - py);   }   int main() {     memset(mx, -1, sizeof(mx));     n = read();     for (int i = (1); i <= (n); ++i)       a[i].x1 = read(), a[i].y1 = read(), a[i].x2 = read(), a[i].y2 = read();     for (int i = (1); i <= (n); ++i) {       px[++totx] = a[i].x1;       px[++totx] = a[i].x2;       py[++toty] = a[i].y1;       py[++toty] = a[i].y2;     }     sort(px + 1, px + totx + 1);     sort(py + 1, py + toty + 1);     lenx = (int)(unique(px + 1, px + totx + 1) - px - 1);     leny = (int)(unique(py + 1, py + toty + 1) - py - 1);     for (int i = (1); i <= (n); ++i) {       norx(a[i].x1);       norx(a[i].x2);       nory(a[i].y1);       nory(a[i].y2);     }     for (int i = (1); i <= (n); ++i) {       ins[a[i].x1].push_back(i);       era[a[i].x2].push_back(i);     }     for (int t = (1); t <= (lenx); ++t) {       for (auto cur : ins[t]) {         cover(1, 1, leny, a[cur].y1, a[cur].y2 - 1, cur, 1);       }       for (auto cur : era[t]) {         cover(1, 1, leny, a[cur].y1, a[cur].y2 - 1, cur, -1);       }       while (~mx[1]) {         ok[mx[1]] = 1;         cover(1, 1, leny, a[mx[1]].y1, a[mx[1]].y2 - 1, mx[1], 0);       }     }     int ans = 1;     for (int i = (1); i <= (n); ++i)       if (ok[i]) ++ans;     printf( %d n , ans);     return 0;   }   