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

#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "ctime"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;

constexpr long long int MOD = 1000000007;
// constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
// constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

// int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  map<string, int> l;
  map<string, int> r;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    cin >> L >> R;
    l[s] = L;
    r[s] = R;
  }
  cin >> N;
  stack<bitset<256>> st;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    // cout << i << endl;
    // if (!st.empty())cout << st.top().to_string() << endl;
    if (s[0] == '+') {
      auto b = st.top();
      st.pop();
      auto a = st.top();
      st.pop();
      bitset<256> ret;
      for (int j = 0; j < 256; j++) {
        for (int k = 0; k < 256; k++) {
          if (a.test(j) && b.test(k)) {
            ret.set((j + k) % 256);
          }
        }
      }
      st.push(ret);
    } else if (s[0] == '-') {
      auto b = st.top();
      st.pop();
      auto a = st.top();
      st.pop();
      bitset<256> ret;
      for (int j = 0; j < 256; j++) {
        for (int k = 0; k < 256; k++) {
          if (a.test(j) && b.test(k)) {
            ret.set((j - k + 256) % 256);
          }
        }
      }
      st.push(ret);
    } else if (s[0] == '*') {
      auto b = st.top();
      st.pop();
      auto a = st.top();
      st.pop();
      bitset<256> ret;
      for (int j = 0; j < 256; j++) {
        for (int k = 0; k < 256; k++) {
          if (a.test(j) && b.test(k)) {
            ret.set((j * k) % 256);
          }
        }
      }
      st.push(ret);
    } else if (s[0] == '/') {
      auto b = st.top();
      st.pop();
      auto a = st.top();
      st.pop();
      bitset<256> ret;
      if (b.test(0)) {
        cout << "error" << endl;
        return 0;
      }
      for (int j = 0; j < 256; j++) {
        for (int k = 0; k < 256; k++) {
          if (a.test(j) && b.test(k)) {
            ret.set((j / k) % 256);
          }
        }
      }
      st.push(ret);
    } else if (s[0] <= '9' && s[0] >= '0') {
      int num = stoi(s);
      bitset<256> ret;
      ret.set(num);
      st.push(ret);
    } else {
      bitset<256> ret;
      for (int i = l[s]; i <= r[s]; i++) {
        ret.set(i);
      }
      st.push(ret);
    }
  }
  cout << "correct" << endl;
}


Error: 0

Fixed submission:

#include <cctype>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
using namespace std;
map<string, vector<bool>> mp;
int main() {
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    string name;
    int l, u;
    cin >> name >> l >> u;
    vector<bool> v;
    for (int i = 0; i <= 255; i++) {
      v.push_back(l <= i && i <= u);
    }
    mp[name] = v;
  }
  int n;
  cin >> n;
  stack<vector<bool>> s;
  for (int i = 0; i < n; i++) {
    string e;
    cin >> e;
    if (mp.find(e) != mp.end()) {
      s.push(mp[e]);
    } else if (isdigit(e[0])) {
      int val = 0;
      for (int j = 0; j < e.size(); j++) {
        val *= 10;
        val += e[j] - '0';
      }
      vector<bool> v;
      for (int j = 0; j <= 255; j++) {
        v.push_back(j == val);
      }
      s.push(v);
    } else {
      vector<bool> op1, op2, res;
      op2 = s.top();
      s.pop();
      op1 = s.top();
      s.pop();
      for (int j = 0; j <= 255; j++)
        res.push_back(0);
      for (int j = 0; j <= 255; j++) {
        if (!op1[j])
          continue;
        for (int k = 0; k <= 255; k++) {
          if (!op2[k])
            continue;
          if (e[0] == '+') {
            res[(j + k) % 256] = 1;
          } else if (e[0] == '-') {
            res[(j - k + 256) % 256] = 1;
          } else if (e[0] == '*') {
            res[j * k % 256] = 1;
          } else {
            if (k == 0) {
              cout << "error" << endl;
              return 0;
            }
            res[j / k] = 1;
          }
        }
      }
    }
  }
  cout << "correct" << endl;
}