Problem p02605 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>

using ll = long long int;
const int INF = (1 << 30);
const ll INFLL = (1ll << 60);
const ll MOD = (ll)(1e9 + 7);

#define l_ength size

void mul_mod(ll &a, ll b) {
  a *= b;
  a %= MOD;
}

void add_mod(ll &a, ll b) {
  a = (a < MOD) ? a : (a - MOD);
  b = (b < MOD) ? b : (b - MOD);
  a += b;
  a = (a < MOD) ? a : (a - MOD);
}

std::vector<int> ud[225816][2], lr[225816][2], ul[410410][2], ur[410410][2],
    dl[410410][2], dr[410410][2];
std::vector<int>::iterator itr;

int main(void) {
  int n, i, j, x, y, ans = INF;
  char u;
  std::cin >> n;
  for (i = 0; i < n; ++i) {
    std::cin >> x >> y >> u;
    switch (u) {
    case 'U':
      ud[x][0].push_back(y);
      ul[x - y + 200000][0].push_back(x);
      ur[x + y][0].push_back(y);
      break;
    case 'D':
      ud[x][1].push_back(y);
      dr[x - y + 200000][1].push_back(x);
      dl[x + y][1].push_back(y);
      break;
    case 'L':
      lr[y][1].push_back(x);
      ul[x - y + 200000][1].push_back(x);
      dl[x + y][0].push_back(y);
      break;
    case 'R':
      lr[y][0].push_back(x);
      dr[x - y + 200000][0].push_back(x);
      ur[x + y][1].push_back(y);
      break;
    }
  }
  for (i = 0; i <= 200000; ++i) {
    std::sort(ud[i][1].begin(), ud[i][1].end());
    for (j = 0; j < ud[i][0].l_ength(); ++j) {
      itr = std::lower_bound(ud[i][1].begin(), ud[i][1].end(), ud[i][0][j]);
      if (itr == ud[i][1].end()) {
        continue;
      }
      ans = std::min(ans, (*itr - ud[i][0][j]) * 5);
    }
    std::sort(lr[i][1].begin(), lr[i][1].end());
    for (j = 0; j < lr[i][0].l_ength(); ++j) {
      itr = std::lower_bound(lr[i][1].begin(), lr[i][1].end(), lr[i][0][j]);
      if (itr == lr[i][1].end()) {
        continue;
      }
      ans = std::min(ans, (*itr - lr[i][0][j]) * 5);
    }
  }
  for (i = 0; i <= 400000; ++i) {
    std::sort(ul[i][1].begin(), ul[i][1].end());
    for (j = 0; j < ul[i][0].l_ength(); ++j) {
      itr = std::lower_bound(ul[i][1].begin(), ul[i][1].end(), ul[i][0][j]);
      if (itr == ul[i][1].end()) {
        continue;
      }
      ans = std::min(ans, (*itr - ul[i][0][j]) * 10);
    }
    std::sort(ur[i][1].begin(), ur[i][1].end());
    for (j = 0; j < ur[i][0].l_ength(); ++j) {
      itr = std::lower_bound(ur[i][1].begin(), ur[i][1].end(), ur[i][0][j]);
      if (itr == ur[i][1].end()) {
        continue;
      }
      ans = std::min(ans, (*itr - ur[i][0][j]) * 10);
    }
    std::sort(dl[i][1].begin(), dl[i][1].end());
    for (j = 0; j < dl[i][0].l_ength(); ++j) {
      itr = std::lower_bound(dl[i][1].begin(), dl[i][1].end(), dl[i][0][j]);
      if (itr == dl[i][1].end()) {
        continue;
      }
      ans = std::min(ans, (*itr - dl[i][0][j]) * 10);
    }
    std::sort(dr[i][1].begin(), dr[i][1].end());
    for (j = 0; j < dr[i][0].l_ength(); ++j) {
      itr = std::lower_bound(dr[i][1].begin(), dr[i][1].end(), dr[i][0][j]);
      if (itr == dr[i][1].end()) {
        continue;
      }
      ans = std::min(ans, (*itr - dr[i][0][j]) * 10);
    }
  }
  if (ans < INF) {
    std::cout << ans << std::endl;
  } else {
    std::cout << "SAFE" << std::endl;
  }
  return 0;
}


Error: 127
/tmp/322c5a6a-19e3-4a0e-a8c7-57c80068be1a.out: error while loading shared libraries: libc.so.6: failed to map segment from shared object


Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>

using ll = long long int;
const int INF = (1 << 30);
const ll INFLL = (1ll << 60);
const ll MOD = (ll)(1e9 + 7);

#define l_ength size

void mul_mod(ll &a, ll b) {
  a *= b;
  a %= MOD;
}

void add_mod(ll &a, ll b) {
  a = (a < MOD) ? a : (a - MOD);
  b = (b < MOD) ? b : (b - MOD);
  a += b;
  a = (a < MOD) ? a : (a - MOD);
}

std::vector<int> ud[225816][2], lr[225816][2], ul[410410][2], ur[410410][2],
    dl[410410][2], dr[410410][2];
std::vector<int>::iterator itr;

int main(void) {
  int n, i, j, x, y, ans = INF;
  char u;
  std::cin >> n;
  for (i = 0; i < n; ++i) {
    std::cin >> x >> y >> u;
    switch (u) {
    case 'U':
      ud[x][0].push_back(y);
      ul[x - y + 100000][0].push_back(x);
      ur[x + y][0].push_back(y);
      break;
    case 'D':
      ud[x][1].push_back(y);
      dr[x - y + 100000][1].push_back(x);
      dl[x + y][1].push_back(y);
      break;
    case 'L':
      lr[y][1].push_back(x);
      ul[x - y + 100000][1].push_back(x);
      dl[x + y][0].push_back(y);
      break;
    case 'R':
      lr[y][0].push_back(x);
      dr[x - y + 100000][0].push_back(x);
      ur[x + y][1].push_back(y);
      break;
    }
  }
  for (i = 0; i <= 200000; ++i) {
    std::sort(ud[i][1].begin(), ud[i][1].end());
    for (j = 0; j < ud[i][0].l_ength(); ++j) {
      itr = std::lower_bound(ud[i][1].begin(), ud[i][1].end(), ud[i][0][j]);
      if (itr == ud[i][1].end()) {
        continue;
      }
      ans = std::min(ans, (*itr - ud[i][0][j]) * 5);
    }
    std::sort(lr[i][1].begin(), lr[i][1].end());
    for (j = 0; j < lr[i][0].l_ength(); ++j) {
      itr = std::lower_bound(lr[i][1].begin(), lr[i][1].end(), lr[i][0][j]);
      if (itr == lr[i][1].end()) {
        continue;
      }
      ans = std::min(ans, (*itr - lr[i][0][j]) * 5);
    }
  }
  for (i = 0; i <= 400000; ++i) {
    std::sort(ul[i][1].begin(), ul[i][1].end());
    for (j = 0; j < ul[i][0].l_ength(); ++j) {
      itr = std::lower_bound(ul[i][1].begin(), ul[i][1].end(), ul[i][0][j]);
      if (itr == ul[i][1].end()) {
        continue;
      }
      ans = std::min(ans, (*itr - ul[i][0][j]) * 10);
    }
    std::sort(ur[i][1].begin(), ur[i][1].end());
    for (j = 0; j < ur[i][0].l_ength(); ++j) {
      itr = std::lower_bound(ur[i][1].begin(), ur[i][1].end(), ur[i][0][j]);
      if (itr == ur[i][1].end()) {
        continue;
      }
      ans = std::min(ans, (*itr - ur[i][0][j]) * 10);
    }
    std::sort(dl[i][1].begin(), dl[i][1].end());
    for (j = 0; j < dl[i][0].l_ength(); ++j) {
      itr = std::lower_bound(dl[i][1].begin(), dl[i][1].end(), dl[i][0][j]);
      if (itr == dl[i][1].end()) {
        continue;
      }
      ans = std::min(ans, (*itr - dl[i][0][j]) * 10);
    }
    std::sort(dr[i][1].begin(), dr[i][1].end());
    for (j = 0; j < dr[i][0].l_ength(); ++j) {
      itr = std::lower_bound(dr[i][1].begin(), dr[i][1].end(), dr[i][0][j]);
      if (itr == dr[i][1].end()) {
        continue;
      }
      ans = std::min(ans, (*itr - dr[i][0][j]) * 10);
    }
  }
  if (ans < INF) {
    std::cout << ans << std::endl;
  } else {
    std::cout << "SAFE" << std::endl;
  }
  return 0;
}