func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, pre = -1;   priority_queue<pair<int, int> > q;   const int M = 3000000 * 4, N = 1e9;   int tree[M], lson[M], rson[M], val[M], size, k, root;   void updata(int &root, int l, int r, int x, int v) {     if (!root) root = ++size;     if (l == r) {       val[root] = tree[root] = v;       return;     }     int mid = (l + r) / 2;     if (x <= mid)       updata(lson[root], l, mid, x, v);     else       updata(rson[root], mid + 1, r, x, v);     tree[root] = max(tree[lson[root]], tree[rson[root]]) + val[root];   }   void add(int &root, int l, int r, int x, int y) {     if (!root || y < l || r < x) return;     if (x <= l && r <= y) {       tree[root]++;       val[root]++;       return;     }     int mid = (l + r) / 2;     add(lson[root], l, mid, x, y);     add(rson[root], mid + 1, r, x, y);     tree[root] = max(tree[lson[root]], tree[rson[root]]) + val[root];   }   int ask(int &root, int l, int r, int x, int y) {     if (!root || y < l || r < x) return 0;     if (x <= l && r <= y) return tree[root];     int mid = (l + r) / 2;     return max(ask(lson[root], l, mid, x, y), ask(rson[root], mid + 1, r, x, y)) +            val[root];   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       int l, r;       scanf( %d%d , &l, &r);       l = max(0, l);       q.push(make_pair(-r, -l));       q.push(make_pair(-l, 1));     }     while (!q.empty()) {       int l = -q.top().second, r = -q.top().first;       q.pop();       if (l >= 0)         add(root, 0, N, l, r);       else {         if (r == pre) continue;         int u = ask(root, 0, N, pre, pre), v = ask(root, 0, N, 0, r - k);         if (l == -1 || u < v) {           pre = r;           updata(root, 0, N, r, v);           if (r + root <= N) q.push(make_pair(-r - k, 2));         }       }     }     cout << tree[1] << endl;     return 0;   }   