Problem p03771 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, v;
int x[100010];
vector<pair<int, int>> tot;
vector<pair<int, int>> seg[20];
int fl[1 << 20], fr[1 << 20];
int main() {
  scanf("%d%d", &n, &v);
  for (int i = 1; i <= n; i++)
    scanf("%d", x + i);
  for (int i = 1; i <= n; i++) {
    int j = i;
    while (j + 1 <= n && x[j + 1] - x[j] <= v)
      j++;
    tot.push_back(make_pair(i, j));
    i = j;
  }
  if ((int)tot.size() > 20) {
    for (int i = 1; i <= n; i++)
      puts("Impossible");
    return 0;
  }
  v /= 2;
  int k;
  for (k = 0;; k++, v /= 2) {
    for (int i = 1; i <= n; i++) {
      int j = i;
      while (j + 1 <= n && x[j + 1] - x[j] <= v)
        j++;
      seg[k].push_back(make_pair(i, j));
      i = j;
    }
    sort(seg[k].begin(), seg[k].end());
    if (!v)
      break;
  }
  k++;
  for (int i = 0; i < (1 << k); i++)
    fr[i] = n + 1;
  for (int i = 0; i < (1 << k); i++) {
    for (int j = 0; j < k; j++) {
      if (i >> j & 1)
        continue;
      int pl =
          lower_bound(seg[j].begin(), seg[j].end(), make_pair(fl[i] + 2, 0)) -
          seg[j].begin();
      fl[i | (1 << j)] = max(fl[i | (1 << j)], fl[i]);
      if (pl)
        fl[i | (1 << j)] = max(fl[i | (1 << j)], seg[j][pl - 1].second);
      int pr = lower_bound(seg[j].begin(), seg[j].end(), make_pair(fr[i], 0)) -
               seg[j].begin();
      fr[i | (1 << j)] = min(fr[i | (1 << j)], fr[i]);
      if (pr)
        fr[i | (1 << j)] = min(fr[i | (1 << j)], seg[j][pr - 1].first);
    }
  }
  for (int i = 0; i < (int)tot.size(); i++) {
    bool ok = false;
    for (int j = 0; j < (1 << k); j++) {
      if (fl[j] >= tot[i].first - 1 &&
          fr[((1 << k) - 1) ^ j] <= tot[i].second + 1) {
        ok = true;
        break;
      }
    }
    for (int j = tot[i].first; j <= tot[i].second; j++)
      puts(ok ? "Possible" : "Impossible");
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, v;
int x[200010];
vector<pair<int, int>> tot;
vector<pair<int, int>> seg[20];
int fl[1 << 20], fr[1 << 20];
int main() {
  scanf("%d%d", &n, &v);
  for (int i = 1; i <= n; i++)
    scanf("%d", x + i);
  for (int i = 1; i <= n; i++) {
    int j = i;
    while (j + 1 <= n && x[j + 1] - x[j] <= v)
      j++;
    tot.push_back(make_pair(i, j));
    i = j;
  }
  if ((int)tot.size() > 20) {
    for (int i = 1; i <= n; i++)
      puts("Impossible");
    return 0;
  }
  v /= 2;
  int k;
  for (k = 0;; k++, v /= 2) {
    for (int i = 1; i <= n; i++) {
      int j = i;
      while (j + 1 <= n && x[j + 1] - x[j] <= v)
        j++;
      seg[k].push_back(make_pair(i, j));
      i = j;
    }
    sort(seg[k].begin(), seg[k].end());
    if (!v)
      break;
  }
  k++;
  for (int i = 0; i < (1 << k); i++)
    fr[i] = n + 1;
  for (int i = 0; i < (1 << k); i++) {
    for (int j = 0; j < k; j++) {
      if (i >> j & 1)
        continue;
      int pl =
          lower_bound(seg[j].begin(), seg[j].end(), make_pair(fl[i] + 2, 0)) -
          seg[j].begin();
      fl[i | (1 << j)] = max(fl[i | (1 << j)], fl[i]);
      if (pl)
        fl[i | (1 << j)] = max(fl[i | (1 << j)], seg[j][pl - 1].second);
      int pr = lower_bound(seg[j].begin(), seg[j].end(), make_pair(fr[i], 0)) -
               seg[j].begin();
      fr[i | (1 << j)] = min(fr[i | (1 << j)], fr[i]);
      if (pr)
        fr[i | (1 << j)] = min(fr[i | (1 << j)], seg[j][pr - 1].first);
    }
  }
  for (int i = 0; i < (int)tot.size(); i++) {
    bool ok = false;
    for (int j = 0; j < (1 << k); j++) {
      if (fl[j] >= tot[i].first - 1 &&
          fr[((1 << k) - 1) ^ j] <= tot[i].second + 1) {
        ok = true;
        break;
      }
    }
    for (int j = tot[i].first; j <= tot[i].second; j++)
      puts(ok ? "Possible" : "Impossible");
  }
  return 0;
}