Language: C++

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 200000 + 1000;
const int MAXM = 1048576;
const int MAXK = 20;


int n, m, V;
int a[MAXN], v[MAXK];
int f[MAXM], g[MAXM];
int next[MAXN][MAXK], prev[MAXN][MAXK];
int ans[MAXN];

void yes()
{
	cout << "Possible" << endl;
}

void no()
{
	cout << "Impossible" << endl;
}

void init()
{
	for(m = 0; V; V /= 2, m++)
		v[m] = V;
	v[m++] = 0;

	for(int i = 0; i <= m - 1; i++)
		next[n + 1][i] = next[n][i] = n;
	for(int i = n - 1; i >= 1; i--)
		for(int j = 0; j <= m - 1; j++)
			next[i][j] = (a[i + 1] - a[i] <= v[j] ? next[i + 1][j] : i);

	for(int i = 0; i <= m - 1; i++)
		prev[0][i] = prev[1][i] = 1;
	for(int i = 2; i <= n; i++)
		for(int j = 0; j <= m - 1; j++)
			prev[i][j] = (a[i] - a[i - 1] <= v[j] ? prev[i - 1][j] : i);
}

void work()
{
	f[0] = 0;
	for(int i = 1; i < (1 << m); i++)
	{
		f[i] = 0;
		for(int j = 0; j < m; j++)
			if((i >> j) & 1)
				f[i] = max(f[i], next[f[i ^ (1 << j)] + 1][j]);
	}
	g[0] = n + 1;
	for(int i = 1; i < (1 << m); i++)
	{
		g[i] = n + 1;
		for(int j = 0; j < m; j++)
			if((i >> j) & 1)
				g[i] = min(g[i], prev[g[i ^ (1 << j)] - 1][j]);
	}

	for(int i = 0; i < (1 << m); i++)
	{
		int s1 = i, s2 = ((1 << m) - 1) ^ i;
		s1 = s1 & ~1, s2 = s2 & ~1;
		int p = f[s1], q = g[s2];
		if(p + 1 > q - 1)
		{
			for(int j = 1; j <= n; j++)
				yes();
			return ;
		}
		if(next[p + 1][0] >= q - 1)
			ans[p + 1] += 1, ans[q - 1 + 1] -= 1;
	}
	for(int i = 1; i <= n; i++)
		ans[i] += ans[i - 1];
	for(int i = 1; i <= n; i++)
		ans[i] > 0 ? yes() : no();
	// for(int i = 1; i <= n; i++)
	// 	cerr << ans[i] << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n >> V;
	for(int i = 1; i <= n; i++)
		cin >> a[i];

	init();
	work();

	return 0;
}


Compiler output:
a.cc: In function 'void init()':
a.cc:41:17: error: reference to 'next' is ambiguous
   41 |                 next[n + 1][i] = next[n][i] = n;
      |                 ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:21:5: note:                 'int next [201000][20]'
   21 | int next[MAXN][MAXK], prev[MAXN][MAXK];
      |     ^~~~
a.cc:41:34: error: reference to 'next' is ambiguous
   41 |                 next[n + 1][i] = next[n][i] = n;
      |                                  ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:21:5: note:                 'int next [201000][20]'
   21 | int next[MAXN][MAXK], prev[MAXN][MAXK];
      |     ^~~~
a.cc:44:25: error: reference to 'next' is ambiguous
   44 |                         next[i][j] = (a[i + 1] - a[i] <= v[j] ? next[i + 1][j] : i);
      |                         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:21:5: note:                 'int next [201000][20]'
   21 | int next[MAXN][MAXK], prev[MAXN][MAXK];
      |     ^~~~
a.cc:44:65: error: reference to 'next' is ambiguous
   44 |                         next[i][j] = (a[i + 1] - a[i] <= v[j] ? next[i + 1][j] : i);
      |                                                                 ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:21:5: note:                 'int next [201000][20]'
   21 | int next[MAXN][MAXK], prev[MAXN][MAXK];
      |     ^~~~
a.cc:47:17: error: reference to 'prev' is ambiguous
   47 |                 prev[0][i] = prev[1][i] = 1;
      |                 ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:21:23: note:                 'int prev [201000][20]'
   21 | int next[MAXN][MAXK], prev[MAXN][MAXK];
      |                       ^~~~
a.cc:47:30: error: reference to 'prev' is ambiguous
   47 |                 prev[0][i] = prev[1][i] = 1;
      |                              ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:21:23: note:                 'int prev [201000][20]'
   21 | int next[MAXN][MAXK], prev[MAXN][MAXK];
      |                       ^~~~
a.cc:50:25: error: reference to 'prev' is ambiguous
   50 |                         prev[i][j] = (a[i] - a[i - 1] <= v[j] ? prev[i - 1][j] : i);
      |                         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:21:23: note:                 'int prev [201000][20]'
   21 | int next[MAXN][MAXK], prev[MAXN][MAXK];
      |                       ^~~~
a.cc:50:65: error: reference to 'prev' is ambiguous
   50 |                         prev[i][j] = (a[i] - a[i - 1] <= v[j] ? prev[i - 1][j] : i);
      |                                                                 ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:21:23: note:                 'int prev [201000][20]'
   21 | int next[MAXN][MAXK], prev[MAXN][MAXK];
      |                       ^~~~
a.cc: In function 'void work()':
a.cc:61:50: error: reference to 'next' is ambiguous
   61 |                                 f[i] = max(f[i], next[f[i ^ (1 << j)] + 1][j]);
      |                                                  ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:21:5: note:                 'int next [201000][20]'
   21 | int next[MAXN][MAXK], prev[MAXN][MAXK];
      |     ^~~~
a.cc:69:50: error: reference to 'prev' is ambiguous
   69 |                                 g[i] = min(g[i], prev[g[i ^ (1 << j)] - 1][j]);
      |                                                  ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:21:23: note:                 'int prev [201000][20]'
   21 | int next[MAXN][MAXK], prev[MAXN][MAXK];
      |                       ^~~~
a.cc:83:20: error: reference to 'next' is ambiguous
   83 |                 if(next[p + 1][0] >= q - 1)
      |                    ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:21:5: note:                 'int next [201000][20]'
   21 | int next[MAXN][MAXK], prev[MAXN][MAXK];
      |     ^~~~