func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const int oo = 0x3f3f3f3f;   const int maxn = 200000, max0 = 100000, maxabs = 1e9;   struct node;   node *newnode();   struct node {     node *c[2];     int Max;     int label;     node() : Max(0), label(0) { memset(c, 0, sizeof c); }     void update() {       Max = 0;       for (int i = (0), _end_ = (2); i < _end_; ++i)         if (c[i]) chkmax(Max, c[i]->Max);     }     void flag_label(int _label) {       label += _label;       Max += _label;     }     void push_down() {       if (label) {         for (int i = (0), _end_ = (2); i < _end_; ++i) {           if (!c[i]) c[i] = newnode();           c[i]->flag_label(label);         }         label = 0;       }     }     inline int get_Max() { return this ? Max : 0; }   };   node *nd_pool;   int nd_res = 0;   node *newnode() {     if (!nd_res) nd_pool = new node[max0], nd_res = max0;     return nd_pool + (--nd_res);   }   node *rt;   int seg_x, seg_y, seg_z;   void add(node *&rt, int l, int r) {     if (!rt) rt = newnode();     if (seg_x <= l && r <= seg_y) {       rt->flag_label(seg_z);       return;     }     int mid = (l + r) >> 1;     rt->push_down();     if (seg_x < mid) add(rt->c[0], l, mid);     if (seg_y > mid) add(rt->c[1], mid, r);     rt->update();   }   inline bool seg_add(int first, int second, int z) {     if (first >= second) return 0;     seg_x = first, seg_y = second, seg_z = z;     add(rt, 0, maxabs + 1);     return 1;   }   inline void find(node *rt, int l, int r) {     assert(rt);     if (r - l <= 1) {       seg_y = l;       return;     }     rt->push_down();     int mid = (l + r) >> 1;     if (rt->c[0]->get_Max() >= seg_x)       find(rt->c[0], l, mid);     else       find(rt->c[1], mid, r);   }   int n, d;   pair<int, int> a[maxn + 5];   inline bool cmp(const pair<int, int> &first, const pair<int, int> &second) {     return first.second < second.second;   }   inline int find(int first) {     if (first > rt->get_Max()) return oo;     seg_x = first;     seg_y = oo;     find(rt, 0, maxabs + 1);     return seg_y;   }   int main() {     scanf( %d%d , &n, &d);     for (int i = (0), _end_ = (n); i < _end_; ++i)       scanf( %d%d , &a[i].first, &a[i].second), ++a[i].second,           chkmax(a[i].first, 0), chkmax(a[i].second, 0);     int now = 0;     sort(a, a + n, cmp);     int lst = 0;     for (int i = (0), _end_ = (n); i < _end_; ++i) {       seg_add(lst, a[i].second, now);       int tmp = -1;       while ((tmp = find(now + 1) + d) < a[i].second) {         ++now;         chkmax(tmp, lst);         seg_add(tmp, a[i].second, 1);       }       seg_add(a[i].first, a[i].second, 1);       chkmax(lst, a[i].second);     }     printf( %d n , rt->get_Max());     return 0;   }   