Language: C++

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

int main() {
  int n, q, a, b;
  long long l;
  long long x[100000];
  std::vector<std::vector<int>> next(100000, std::vector<int>(20));
  std::cin >> n;
  for (int ni = 0; ni < n; ++ni) {
    std::cin >> x[ni];
  }
  std::cin >> l >> q;
  for (int ni = 0; ni < n; ++ni) {
    int inf = 0;
    int sup = n;
    while (sup - inf > 1) {
      int c = (inf + sup) / 2;
      if (x[c] <= x[ni] + l) {
        inf = c;
      } else {
        sup = c;
      }
    }
    next[ni][0] = inf;
  }
  for (int c = 1; c < 20; ++c) {
    for (int ni = 0; ni < n; ++ni) {
      next[ni][c] = next[next[ni][c - 1]][c - 1];
    }
  }
  for (int qi = 0; qi < q; ++qi) {
    int ans = 0;
    std::cin >> a >> b;
    if (a > b) {
      std::swap(a, b);
    }
    --a;
    --b;
    while (a < b) {
      for (int d = 19; d >= 0; --d) {
        if (next[a][d] <= b) {
          a = next[a][d] + 1;
          ans += 1 << d;
          break;
        }
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

int main() {
  int n, q, a, b;
  long long l;
  long long x[100000];
  std::vector<std::vector<int>> next(100000, std::vector<int>(20));
  std::cin >> n;
  for (int ni = 0; ni < n; ++ni) {
    std::cin >> x[ni];
  }
  std::cin >> l >> q;
  for (int ni = 0; ni < n; ++ni) {
    int inf = 0;
    int sup = n;
    while (sup - inf > 1) {
      int c = (inf + sup) / 2;
      if (x[c] <= x[ni] + l) {
        inf = c;
      } else {
        sup = c;
      }
    }
    next[ni][0] = inf;
  }
  for (int c = 1; c < 20; ++c) {
    for (int ni = 0; ni < n; ++ni) {
      next[ni][c] = next[next[ni][c - 1]][c - 1];
    }
  }
  for (int qi = 0; qi < q; ++qi) {
    int ans = 0;
    std::cin >> a >> b;
    if (a > b) {
      std::swap(a, b);
    }
    --a;
    --b;
    while (a < b) {
      for (int d = 19; d >= 0; --d) {
        if (next[a][d] <= b) {
          a = next[a][d] + 1;
          ans += 1 << d;
          break;
        }
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

int main() {
  int n, q, a, b;
  long long l;
  long long x[100000];
  std::vector<std::vector<int>> next(100000, std::vector<int>(20));
  std::cin >> n;
  for (int ni = 0; ni < n; ++ni) {
    std::cin >> x[ni];
  }
  std::cin >> l >> q;
  for (int ni = 0; ni < n; ++ni) {
    int inf = 0;
    int sup = n;
    while (sup - inf > 1) {
      int c = (inf + sup) / 2;
      if (x[c] <= x[ni] + l) {
        inf = c;
      } else {
        sup = c;
      }
    }
    next[ni][0] = inf;
  }
  for (int c = 1; c < 20; ++c) {
    for (int ni = 0; ni < n; ++ni) {
      next[ni][c] = next[next[ni][c - 1]][c - 1];
    }
  }
  for (int qi = 0; qi < q; ++qi) {
    int ans = 0;
    std::cin >> a >> b;
    if (a > b) {
      std::swap(a, b);
    }
    --a;
    --b;
    while (a < b) {
      for (int d = 19; d >= 0; --d) {
        if (next[a][d] <= b) {
          a = next[a][d] + 1;
          ans += 1 << d;
          break;
        }
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Compiler output:
a.cc:65:5: error: redefinition of 'int main()'
   65 | int main() {
      |     ^~~~
a.cc:8:5: note: 'int main()' previously defined here
    8 | int main() {
      |     ^~~~
a.cc:122:5: error: redefinition of 'int main()'
  122 | int main() {
      |     ^~~~
a.cc:8:5: note: 'int main()' previously defined here
    8 | int main() {
      |     ^~~~