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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;

bool solve(vector<string> &ops, map<string, P> &vs) {
  vector<set<int>> v;
  for (string s : ops) {
    set<int> tmp;
    if (vs.find(s) != vs.end())
      FOR(i, vs[s].first, vs[s].second + 1) tmp.insert(i);
    else if (isdigit(s[0]))
      tmp.insert(atoi(s.c_str()));
    else if (s == "+") {
      set<int> b = v.back();
      v.pop_back();
      set<int> a = v.back();
      v.pop_back();
      for (int x : a) {
        for (int y : b) {
          int n = x + y;
          while (n >= 256)
            n -= 256;
          tmp.insert(n);
        }
      }
    } else if (s == "-") {
      set<int> b = v.back();
      v.pop_back();
      set<int> a = v.back();
      v.pop_back();
      for (int x : a) {
        for (int y : b) {
          int n = x - y;
          while (n < 0)
            n += 256;
          tmp.insert(n);
        }
      }
    } else if (s == "*") {
      set<int> b = v.back();
      v.pop_back();
      set<int> a = v.back();
      v.pop_back();
      for (int x : a) {
        for (int y : b) {
          int n = x * y;
          while (n >= 256)
            n -= 256;
          tmp.insert(n);
        }
      }
    } else if (s == "/") {
      set<int> b = v.back();
      v.pop_back();
      set<int> a = v.back();
      v.pop_back();
      for (int x : a) {
        for (int y : b) {
          if (y == 0)
            return false;
          int n = x / y;
          while (n >= 256)
            n -= 256;
          tmp.insert(n);
        }
      }
    }
    v.push_back(tmp);
  }
  return true;
}

int main() {
  int M;
  cin >> M;
  map<string, P> vs;
  REP(i, M) {
    string s;
    cin >> s;
    int l, u;
    cin >> l >> u;
    vs[s] = P(l, u);
  }
  int N;
  cin >> N;
  vector<string> ops(N);
  REP(i, N) cin >> ops[i];
  cout << (solve(ops, vs) ? "correct" : "error") << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;

bool solve(vector<string> &ops, map<string, P> &vs) {
  vector<vector<int>> v;
  for (string s : ops) {
    vector<int> tmp;
    if (vs.find(s) != vs.end())
      FOR(i, vs[s].first, vs[s].second + 1) tmp.push_back(i);
    else if (isdigit(s[0]))
      tmp.push_back(atoi(s.c_str()));
    else if (s == "+") {
      vector<int> b = v.back();
      v.pop_back();
      vector<int> a = v.back();
      v.pop_back();
      for (int x : a) {
        for (int y : b) {
          int n = x + y;
          while (n >= 256)
            n -= 256;
          tmp.push_back(n);
        }
      }
    } else if (s == "-") {
      vector<int> b = v.back();
      v.pop_back();
      vector<int> a = v.back();
      v.pop_back();
      for (int x : a) {
        for (int y : b) {
          int n = x - y;
          while (n < 0)
            n += 256;
          tmp.push_back(n);
        }
      }
    } else if (s == "*") {
      vector<int> b = v.back();
      v.pop_back();
      vector<int> a = v.back();
      v.pop_back();
      for (int x : a) {
        for (int y : b) {
          int n = x * y;
          while (n >= 256)
            n -= 256;
          tmp.push_back(n);
        }
      }
    } else if (s == "/") {
      vector<int> b = v.back();
      v.pop_back();
      vector<int> a = v.back();
      v.pop_back();
      for (int x : a) {
        for (int y : b) {
          if (y == 0)
            return false;
          int n = x / y;
          while (n >= 256)
            n -= 256;
          tmp.push_back(n);
        }
      }
    }
    v.push_back(tmp);
  }
  return true;
}

int main() {
  int M;
  cin >> M;
  map<string, P> vs;
  REP(i, M) {
    string s;
    cin >> s;
    int l, u;
    cin >> l >> u;
    vs[s] = P(l, u);
  }
  int N;
  cin >> N;
  vector<string> ops(N);
  REP(i, N) cin >> ops[i];
  cout << (solve(ops, vs) ? "correct" : "error") << endl;
  return 0;
}