func_code_string: #include <bits/stdc++.h>   using namespace std;   int n;   long long h[100005], d;   int dp[100005];   int arr[300003];   int tree[(1200004)];   int lazy[(1200004)];   void build_tree(int node, int a, int b) {     if (a > b) return;     if (a == b) {       tree[node] = arr[a];       return;     }     build_tree(node * 2, a, (a + b) / 2);     build_tree(node * 2 + 1, 1 + (a + b) / 2, b);     tree[node] = max(tree[node * 2], tree[node * 2 + 1]);   }   void update_tree(int node, int a, int b, int i, int j, int value) {     if (lazy[node] != 0) {       tree[node] += lazy[node];       if (a != b) {         lazy[node * 2] += lazy[node];         lazy[node * 2 + 1] += lazy[node];       }       lazy[node] = 0;     }     if (a > b || a > j || b < i) return;     if (a >= i && b <= j) {       tree[node] += value;       if (a != b) {         lazy[node * 2] += value;         lazy[node * 2 + 1] += value;       }       return;     }     update_tree(node * 2, a, (a + b) / 2, i, j, value);     update_tree(1 + node * 2, 1 + (a + b) / 2, b, i, j, value);     tree[node] = max(tree[node * 2], tree[node * 2 + 1]);   }   int query_tree(int node, int a, int b, int i, int j) {     if (a > b || a > j || b < i) return -0x7fffffff;     if (lazy[node] != 0) {       tree[node] += lazy[node];       if (a != b) {         lazy[node * 2] += lazy[node];         lazy[node * 2 + 1] += lazy[node];       }       lazy[node] = 0;     }     if (a >= i && b <= j) return tree[node];     int q1 = query_tree(node * 2, a, (a + b) / 2, i, j);     int q2 = query_tree(1 + node * 2, 1 + (a + b) / 2, b, i, j);     int res = max(q1, q2);     return res;   }   void reconstruct(vector<int>& ret, int val) {     long long last = -1e18;     for (int i = 0; i < n; i++) {       if (abs(last - h[i]) >= d && dp[i] == val) {         ret.push_back(i + 1);         last = h[i];         val--;       }     }   }   map<long long, int> htoi;   set<long long> ss;   int main() {     cin >> n >> d;     int counter = 0;     for (int i = 0; i < n; i++) {       scanf( %I64d , &h[i]);       ss.insert(h[i]);     }     set<long long>::iterator iit;     for (iit = ss.begin(); iit != ss.end(); iit++) htoi[*iit] = counter++;     ss.clear();     update_tree(1, 0, 300003 - 1, htoi[h[n - 1]], htoi[h[n - 1]], 1);     ss.insert(h[n - 1]);     dp[n - 1] = 1;     for (int ind = n - 2; ind >= 0; ind--) {       int index = htoi[h[ind]];       long long curmin = *ss.begin();       iit = ss.end();       iit--;       long long curmax = *iit;       int ucand = 0;       int dcand = 0;       if (ss.lower_bound(h[ind] + d) != ss.end()) {         long long curhplud = *ss.lower_bound(h[ind] + d);         ucand = max(ucand,                     query_tree(1, 0, 300003 - 1, htoi[curhplud], htoi[curmax]));       }       iit = ss.lower_bound(h[ind] - d);       if (iit == ss.begin()) {         if (*iit <= h[ind] - d) {           dcand = max(dcand,                       query_tree(1, 0, 300003 - 1, htoi[curmin], htoi[curmin]));         }       } else {         if (*iit > h[ind] - d) iit--;         if (iit == ss.end()) iit--;         long long curhmind = *iit;         dcand = max(dcand,                     query_tree(1, 0, 300003 - 1, htoi[curmin], htoi[curhmind]));       }       int curval = query_tree(1, 0, 300003 - 1, index, index);       int newval = max(max(ucand, dcand) + 1, curval);       update_tree(1, 0, 300003 - 1, index, index, newval - curval);       ss.insert(h[ind]);       dp[ind] = query_tree(1, 0, 300003 - 1, index, index);     }     int len = dp[0];     for (int i = 1; i < n; i++) len = max(len, dp[i]);     vector<int> ret;     reconstruct(ret, len);     cout << ret.size() << endl;     for (int i = 0; i < ret.size(); i++) cout << ret[i] <<    ;     cout << endl;     return 0;   }   