Language: Java

#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
 
 
 
 
vector<tuple<int, int, int>> s[2][100000];
int N;
int x[100000];
int L, Q;
int ans[100000];
int dist[100000];
 
int bs;
 
 
void solve(int dir) {
	rep(i, N - 1) {
		int nxt = upper_bound(x, x + N, x[i] + L) - 1 - x;
		if(s[dir][i].size() != 3){ return; }
		if (s[dir][i].size() < bs) {
			for (const auto &t : s[dir][i]) {
				int b, j, cost;
				tie(b, j, cost) = t;
				if (nxt >= b) {
					ans[j] = cost + 1;
				}
				else {
					s[dir][nxt].emplace_back(b, j, cost + 1);
				}
			}
		}
		else {
			int c = 1, d = 0;
			dist[i] = 0;
			for (int j = i + 1; j < N; j++) {
				d += x[j] - x[j - 1];
				if (d > L) {
					d = x[j] - x[j - 1];
					c++;
				}
				dist[j] = c;
			}
			for (const auto &t : s[dir][i]) {
				int b, j, cost;
				tie(b, j, cost) = t;
				ans[j] = cost + dist[b];
			}
		}
		{
			vector<tuple<int, int, int>> a;
			s[dir][i].swap(a);
		}
	}
}
 
 
 
 
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	rep(i, N)cin >> x[i];
	cin >> L >> Q;
	bs = sqrt(Q);
	rep(i, Q) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		if (a < b) {
			s[0][a].emplace_back(b, i, 0);
		}
		else {
			a = N - a - 1;
			b = N - b - 1;
			s[1][a].emplace_back(b, i, 0);
		}
	}
	solve(0);
	reverse(x, x + N);
	rep(i, N)x[i] *= -1;
	solve(1);
	rep(i, Q)cout << ans[i] << endl;
 
	return 0;
}

Compiler output:
Main.java:1: error: illegal character: '#'
#define _CRT_SECURE_NO_WARNINGS
^
Main.java:2: error: illegal character: '#'
#include<sstream>
^
Main.java:3: error: illegal character: '#'
#include<iostream>
^
Main.java:4: error: illegal character: '#'
#include<cstdio>
^
Main.java:5: error: illegal character: '#'
#include<cstdlib>
^
Main.java:6: error: illegal character: '#'
#include<cstring>
^
Main.java:7: error: illegal character: '#'
#include<climits>
^
Main.java:8: error: illegal character: '#'
#include<cmath>
^
Main.java:9: error: illegal character: '#'
#include<string>
^
Main.java:10: error: illegal character: '#'
#include<vector>
^
Main.java:11: error: illegal character: '#'
#include<set>
^
Main.java:12: error: illegal character: '#'
#include<map>
^
Main.java:13: error: illegal character: '#'
#include<queue>
^
Main.java:14: error: illegal character: '#'
#include<numeric>
^
Main.java:15: error: illegal character: '#'
#include<functional>
^
Main.java:16: error: illegal character: '#'
#include<algorithm>
^
Main.java:17: error: illegal character: '#'
#include<bitset>
^
Main.java:18: error: illegal character: '#'
#include<tuple>
^
Main.java:19: error: illegal character: '#'
#include<unordered_set>
^
Main.java:20: error: illegal character: '#'
#include<random>
^
Main.java:22: error: illegal character: '#'
#define INF (1<<29)
^
Main.java:22: error: class, interface, enum, or record expected
#define INF (1<<29)
        ^
Main.java:23: error: illegal character: '#'
#define rep(i,n) for(int i=0;i<(int)(n);i++)
^
Main.java:23: error: class, interface, enum, or record expected
#define rep(i,n) for(int i=0;i<(int)(n);i++)
                             ^
Main.java:23: error: class, interface, enum, or record expected
#define rep(i,n) for(int i=0;i<(int)(n);i++)
                                        ^
Main.java:24: error: illegal character: '#'
#define all(v) v.begin(),v.end()
^
Main.java:25: error: illegal character: '#'
#define uniq(v) v.erase(unique(all(v)),v.end())
^
Main.java:31: error: unnamed classes are a preview feature and are disabled by default.
int N;
^
  (use --enable-preview to enable unnamed classes)
Main.java:32: error: class, interface, enum, or record expected
int x[100000];
^
Main.java:33: error: class, interface, enum, or record expected
int L, Q;
^
Main.java:34: error: class, interface, enum, or record expected
int ans[100000];
^
Main.java:35: error: class, interface, enum, or record expected
int dist[100000];
^
Main.java:45: error: not a statement
			for (const auto &t : s[dir][i]) {
			                ^
Main.java:45: error: not a statement
			for (const auto &t : s[dir][i]) {
			                           ^
Main.java:67: error: not a statement
			for (const auto &t : s[dir][i]) {
			                ^
Main.java:67: error: not a statement
			for (const auto &t : s[dir][i]) {
			                           ^
Main.java:41: error: ';' expected
	rep(i, N - 1) {
	             ^
Main.java:45: error: illegal start of expression
			for (const auto &t : s[dir][i]) {
			     ^
Main.java:45: error: ';' expected
			for (const auto &t : s[dir][i]) {
			                  ^
Main.java:45: error: ';' expected
			for (const auto &t : s[dir][i]) {
			                              ^
Main.java:67: error: illegal start of expression
			for (const auto &t : s[dir][i]) {
			     ^
Main.java:67: error: ';' expected
			for (const auto &t : s[dir][i]) {
			                  ^
Main.java:67: error: ';' expected
			for (const auto &t : s[dir][i]) {
			                              ^
Main.java:85: error: not a statement
	ios::sync_with_stdio(0);
	^
Main.java:87: error: not a statement
	cin >> N;
	    ^
Main.java:88: error: not a statement
	rep(i, N)cin >> x[i];
	             ^
Main.java:89: error: not a statement
	cin >> L >> Q;
	         ^
Main.java:93: error: not a statement
		cin >> a >> b;
		         ^
Main.java:108: error: not a statement
	rep(i, Q)cout << ans[i] << endl;
	                        ^
Main.java:85: error: ';' expected
	ios::sync_with_stdio(0);
	                    ^
Main.java:88: error: ';' expected
	rep(i, N)cin >> x[i];
	         ^
Main.java:91: error: ';' expected
	rep(i, Q) {
	         ^
Main.java:106: error: ';' expected
	rep(i, N)x[i] *= -1;
	         ^
Main.java:108: error: ';' expected
	rep(i, Q)cout << ans[i] << endl;
	         ^
54 errors