Language: C++

//2018-1-18
//miaomiao
//
#include <bits/stdc++.h>
using namespace std;

#define Set(a, v) memset(a, v, sizeof(a))
#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)

#define M 18
#define N (100000+5)

int n, m, dn, pos[N], dis[M], nxt[N][M], beg[N], end[N];
int f[1<<M];

bool Solve(int l, int r){
	if(l == 1 && r == n) return true;

	f[0] = 0;
	
	int tmp;
	For(i, 1, (1<<dn)-1){
		f[i] = 0;
		For(j, 1, dn) if(i & (1<<(j-1))){
			tmp = f[i ^ (1<<(j-1))] + 1;
			if(tmp >= l && tmp <= r) tmp = r+1;

			f[i] = max(f[i], nxt[tmp][j]);
			if(f[i]+1 >= l && f[i]+1 <= r) f[i] = r;
		}
		if(f[i] >= n) return true;
	}
	return false;
}

int main(){
	scanf("%d%d", &n, &m);
	For(i, 1, n) scanf("%d", &pos[i]);
	
	int st, ed, cnt = 0;
	for(int d = m; d >= 0; d >>= 1){
		st = 1; if(d != m) dis[++dn] = d;

		while(st <= n){
			ed = st;
			while(ed < n && pos[ed+1]-pos[ed] <= d) ++ed;
			For(i, st, ed) nxt[i][dn] = ed;
			
			if(d == m){
				beg[++cnt] = st; end[cnt] = ed;
			}
			st = ed+1;
		}

		if(!d) break;
	}

	For(i, 1, dn) nxt[n+1][i] = n+1;
//	For(i, 1, n) For(j, 1, dn) printf("nxt[%d][%d] = %d\n", i, j, nxt[i][j]);

	if(cnt > dn+1){
		For(i, 1, n) puts("Impossible"); return 0;
	}

	For(si, 1, cnt){
	//	printf("%d -> %d free\n", beg[si], end[si]);
		if(Solve(beg[si], end[si])){
			For(i, beg[si], end[si]) puts("Possible");
		}else{
			For(i, beg[si], end[si]) puts("Impossible"); 
		}
	}
	
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:50:50: error: reference to 'end' is ambiguous
   50 |                                 beg[++cnt] = st; end[cnt] = ed;
      |                                                  ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166,
                 from a.cc:4:
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
In file included from /usr/include/c++/14/bits/algorithmfwd.h:39,
                 from /usr/include/c++/14/bits/stl_algo.h:59,
                 from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:13:50: note:                 'int end [100005]'
   13 | int n, m, dn, pos[N], dis[M], nxt[N][M], beg[N], end[N];
      |                                                  ^~~
a.cc:67:35: error: reference to 'end' is ambiguous
   67 |                 if(Solve(beg[si], end[si])){
      |                                   ^~~
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:13:50: note:                 'int end [100005]'
   13 | int n, m, dn, pos[N], dis[M], nxt[N][M], beg[N], end[N];
      |                                                  ^~~
a.cc:68:41: error: reference to 'end' is ambiguous
   68 |                         For(i, beg[si], end[si]) puts("Possible");
      |                                         ^~~
a.cc:8:50: note: in definition of macro 'For'
    8 | #define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
      |                                                  ^
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:13:50: note:                 'int end [100005]'
   13 | int n, m, dn, pos[N], dis[M], nxt[N][M], beg[N], end[N];
      |                                                  ^~~
a.cc:70:41: error: reference to 'end' is ambiguous
   70 |                         For(i, beg[si], end[si]) puts("Impossible");
      |                                         ^~~
a.cc:8:50: note: in definition of macro 'For'
    8 | #define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
      |                                                  ^
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:13:50: note:                 'int end [100005]'
   13 | int n, m, dn, pos[N], dis[M], nxt[N][M], beg[N], end[N];
      |                                                  ^~~