Problem p03152 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll, ll>;
using str = string;
using vpl4 = vector<pair<ll, ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x)                                                                \
  ll(x);                                                                       \
  cin >> (x);
#define stin(x)                                                                \
  str(x);                                                                      \
  cin >> (x);
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define rFOR(i, b, a) for (ll i = a; i >= b; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll MOD = 1000000007;

signed main() {
  llin(n);
  llin(m);
  vll a(n + 1, 0);
  vll b(n + 1, 0);
  ll s = 0;
  ll x = 1;
  ll y = 1;
  ll t = 1;
  FOR(i, 0, n - 1) { cin >> a[i]; }
  FOR(i, 0, m - 1) { cin >> b[i]; }
  rSORT(a);
  rSORT(b);
  ll o = a[0];
  while (x < m || y < n) {
    if (o == a[y] || o == b[x]) {
      t = 0;
      break;
    }
    if (a[y] == b[x]) {
      FOR(j, 1, o - a[y] - 1) {
        t = (t * s) % MOD;
        s--;
      }
      o = a[y];
      s += x + y;
      x++;
      y++;
    }
    if (a[y] > b[x]) {
      t = (t * x) % MOD;
      FOR(j, 1, o - a[y] - 1) {
        t = (t * s) % MOD;
        s--;
      }
      o = a[y];
      s += x - 1;
      y++;
    }
    if (a[y] < b[x]) {
      t = (t * y) % MOD;
      FOR(j, 1, o - b[x] - 1) {
        t = (t * s) % MOD;
        s--;
      }
      o = b[x];
      s += y - 1;
      x++;
    }
  }
  rFOR(j, 1, s) { t = (t * j) % MOD; }
  sal(t);
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll, ll>;
using str = string;
using vpl4 = vector<pair<ll, ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x)                                                                \
  ll(x);                                                                       \
  cin >> (x);
#define stin(x)                                                                \
  str(x);                                                                      \
  cin >> (x);
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define rFOR(i, b, a) for (ll i = a; i >= b; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll MOD = 1000000007;

signed main() {
  llin(n);
  llin(m);
  vll a(n + 1, 0);
  vll b(m + 1, 0);
  ll s = 0;
  ll x = 1;
  ll y = 1;
  ll t = 1;
  FOR(i, 0, n - 1) { cin >> a[i]; }
  FOR(i, 0, m - 1) { cin >> b[i]; }
  rSORT(a);
  rSORT(b);
  ll o = a[0];
  while (x < m || y < n) {
    if (o == a[y] || o == b[x]) {
      t = 0;
      break;
    }
    if (a[y] == b[x]) {
      FOR(j, 1, o - a[y] - 1) {
        t = (t * s) % MOD;
        s--;
      }
      o = a[y];
      s += x + y;
      x++;
      y++;
    }
    if (a[y] > b[x]) {
      t = (t * x) % MOD;
      FOR(j, 1, o - a[y] - 1) {
        t = (t * s) % MOD;
        s--;
      }
      o = a[y];
      s += x - 1;
      y++;
    }
    if (a[y] < b[x]) {
      t = (t * y) % MOD;
      FOR(j, 1, o - b[x] - 1) {
        t = (t * s) % MOD;
        s--;
      }
      o = b[x];
      s += y - 1;
      x++;
    }
  }
  rFOR(j, 1, s) { t = (t * j) % MOD; }
  sal(t);
}