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

#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define MAX_N 100000
int N, Q;
vector<int> vec, vec2;
string S[MAX_N][3], T[4];
bool Find(string U, string V) {
  int X = U.size(), Y = V.size();
  for (int i = 0; i <= X - Y; i++) {
    string W = U.substr(i, Y);
    if (W == V) {
      return true;
    }
  }
  return false;
}
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> S[i][0] >> S[i][1] >> S[i][2];
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    if (i >= 1) {
      cout << endl;
    }
    cin >> T[0] >> T[1] >> T[2] >> T[3];
    vec.clear();
    vec2.clear();
    for (int j = 0; j < N; j++) {
      vec.push_back(j);
    }
    vec2 = vec;
    if (T[0] != "*") {
      vec2.clear();
      for (int j = 0; j < vec.size(); j++) {
        if (Find(S[vec[j]][0], T[0]) == true) {
          vec2.push_back(vec[j]);
        }
      }
    }
    vec.clear();
    vec = vec2;
    if (T[1] != "*") {
      vec2.clear();
      for (int j = 0; j < vec.size(); j++) {
        if (Find(S[vec[j]][1], T[1]) == true) {
          vec2.push_back(vec[j]);
        }
      }
    }
    vec.clear();
    vec = vec2;
    if (T[2] != "*") {
      vec2.clear();
      for (int j = 0; j < vec.size(); j++) {
        if (S[vec[j]][2] >= T[2]) {
          vec2.push_back(vec[j]);
        }
      }
    }
    vec.clear();
    vec = vec2;
    if (T[3] != "*") {
      vec2.clear();
      for (int j = 0; j < vec.size(); j++) {
        if (S[vec[j]][2] <= T[3]) {
          vec2.push_back(vec[j]);
        }
      }
    }
    vec.clear();
    vec = vec2;
    vec2.clear();
    for (int j = 0; j < vec.size(); j++) {
      cout << S[vec[j]][0] << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
#pragma warning(disable : 4996)

#define MAX_N 10000

int n, m, a1, a2, a3;
string a[MAX_N], b[MAX_N];
int c[MAX_N];
string S, T, U, V, W;
bool ok, ok1, ok2, ok3, ok4;

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    scanf("%04d/%04d/%04d", &a1, &a2, &a3);
    c[i] = a1 * 10000 + a2 * 100 + a3;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    if (i >= 1) {
      cout << endl;
    }
    ok = false;
    cin >> S >> T >> U >> V;
    if (S == "*") {
      W = "";
    } else {
      W = S;
    }
    a1 = 1000;
    a2 = 1000;
    if (U == "*") {
      a1 = 0;
    }
    if (V == "*") {
      a2 = 1 << 30;
    }
    if (T == "*") {
      ok = true;
    }
    for (int j = 0; j < n; j++) {
      ok1 = false;
      ok2 = false;
      ok3 = false;
      ok4 = false;
      if (W != "") {
        for (int k = 0; k <= a[j].size() - W.size(); k++) {
          if (a[j].substr(k, W.size()) == W) {
            ok1 = true;
          }
        }
      } else {
        ok1 = true;
      }
      if (ok == true) {
        ok2 = true;
      } else {
        if (T == b[j]) {
          ok2 = true;
        }
      }
      if (a1 > 0) {
        a1 = stoi(U.substr(0, 4)) * 10000 + stoi(U.substr(5, 2)) * 100 +
             stoi(U.substr(8, 2));
      }
      if (a2 < (1 << 28)) {
        a2 = stoi(V.substr(0, 4)) * 10000 + stoi(V.substr(5, 2)) * 100 +
             stoi(V.substr(8, 2));
      }
      if (a1 <= c[j] && c[j] <= a2) {
        ok3 = true;
      }
      if (ok1 == true && ok2 == true && ok3 == true) {
        cout << a[j] << endl;
      }
    }
  }
  return 0;
}