Language: C++

#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
#define int long long

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;


int main() {

	int n;
	cin >> n;

	VI x(n+1);
	REP(i, n)cin >> x[i];
	int l;
	cin >> l;
	VVI d(n + 5, VI(30, n+1));

	REP(i, n) {
		d[i][0] = upper_bound(ALL(x), x[i] + l) - x.begin();
		d[i][0]--;
	}
	
	REP(j, 29)REP(i, n) {
		d[i][j + 1] = d[d[i][j]][j];
	}

	int q;
	cin >> q;
	REP(i, q) {
		int a, b;
		cin >> a >> b;
		if (a > b)swap(a, b);
		a--;
		b--;

		ll ans = 0;

		for (int i = 29; i >= 0; i--) {
			if (d[a][i] < b) {
				if (d[a][i] == 0)continue;
				a = d[a][i];
				ans += 1 << i;
			}
		}
		ans++;

		cout << ans << endl;

	}

	return 0;


}



Compiler output:
cc1plus: error: '::main' must return 'int'
a.cc: In function 'int main()':
a.cc:19:13: error: expected primary-expression before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:35:9: note: in expansion of macro 'REP'
   35 |         REP(i, n)cin >> x[i];
      |         ^~~
a.cc:19:13: error: expected ';' before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:35:9: note: in expansion of macro 'REP'
   35 |         REP(i, n)cin >> x[i];
      |         ^~~
a.cc:19:13: error: expected primary-expression before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:35:9: note: in expansion of macro 'REP'
   35 |         REP(i, n)cin >> x[i];
      |         ^~~
a.cc:19:13: error: expected ')' before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:35:9: note: in expansion of macro 'REP'
   35 |         REP(i, n)cin >> x[i];
      |         ^~~
a.cc:6:21: note: to match this '('
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                     ^
a.cc:35:9: note: in expansion of macro 'REP'
   35 |         REP(i, n)cin >> x[i];
      |         ^~~
a.cc:35:13: error: 'i' was not declared in this scope
   35 |         REP(i, n)cin >> x[i];
      |             ^
a.cc:6:41: note: in definition of macro 'REP'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                         ^
a.cc:19:13: error: expected primary-expression before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:40:9: note: in expansion of macro 'REP'
   40 |         REP(i, n) {
      |         ^~~
a.cc:19:13: error: expected ';' before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:40:9: note: in expansion of macro 'REP'
   40 |         REP(i, n) {
      |         ^~~
a.cc:19:13: error: expected primary-expression before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:40:9: note: in expansion of macro 'REP'
   40 |         REP(i, n) {
      |         ^~~
a.cc:19:13: error: expected ')' before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:40:9: note: in expansion of macro 'REP'
   40 |         REP(i, n) {
      |         ^~~
a.cc:6:21: note: to match this '('
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                     ^
a.cc:40:9: note: in expansion of macro 'REP'
   40 |         REP(i, n) {
      |         ^~~
a.cc:19:13: error: expected primary-expression before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:45:9: note: in expansion of macro 'REP'
   45 |         REP(j, 29)REP(i, n) {
      |         ^~~
a.cc:19:13: error: expected ';' before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:45:9: note: in expansion of macro 'REP'
   45 |         REP(j, 29)REP(i, n) {
      |         ^~~
a.cc:19:13: error: expected primary-expression before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:45:9: note: in expansion of macro 'REP'
   45 |         REP(j, 29)REP(i, n) {
      |         ^~~
a.cc:19:13: error: expected ')' before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:45:9: note: in expansion of macro 'REP'
   45 |         REP(j, 29)REP(i, n) {
      |         ^~~
a.cc:6:21: note: to match this '('
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                     ^
a.cc:45:9: note: in expansion of macro 'REP'
   45 |         REP(j, 29)REP(i, n) {
      |         ^~~
a.cc:19:13: error: expected primary-expression before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:45:9: note: in expansion of macro 'REP'
   45 |         REP(j, 29)REP(i, n) {
      |         ^~~
a.cc:45:13: error: 'j' was not declared in this scope
   45 |         REP(j, 29)REP(i, n) {
      |             ^
a.cc:6:41: note: in definition of macro 'REP'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                         ^
a.cc:19:13: error: expected primary-expression before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:45:19: note: in expansion of macro 'REP'
   45 |         REP(j, 29)REP(i, n) {
      |                   ^~~
a.cc:19:13: error: expected primary-expression before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:51:9: note: in expansion of macro 'REP'
   51 |         REP(i, q) {
      |         ^~~
a.cc:19:13: error: expected ';' before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:51:9: note: in expansion of macro 'REP'
   51 |         REP(i, q) {
      |         ^~~
a.cc:19:13: error: expected primary-expression before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:51:9: note: in expansion of macro 'REP'
   51 |         REP(i, q) {
      |         ^~~
a.cc:19:13: error: expected ')' before 'long'
   19 | #define int long long
      |             ^~~~
a.cc:6:33: note: in expansion of macro 'int'
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                                 ^~~
a.cc:51:9: note: in expansion of macro 'REP'
   51 |         REP(i, q) {
      |         ^~~
a.cc:6:21: note: to match this '('
    6 | #define REP(i,n) for(int i=0; i<int(n); i++)
      |                     ^
a.cc:51:9: note: in expansion of macro 'REP'
   51 |         REP(i, q) {
      |         ^~~