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

#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//<< setprecision(5)
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme                                                                    \\
  cout << -1 << endl;                                                          \\
  return 0
const int mod = 1000000007;
const int big = 1e9 + 10;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;
template <class T, class U> void mineq(T &a, U b) {
  if (a > b) {
    a = b;
  }
}
template <class T, class U> void maxeq(T &a, U b) {
  if (a < b) {
    a = b;
  }
}
llint gcd(llint a, llint b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
llint lcm(llint a, llint b) { return a / gcd(a, b) * b; }
class seg {
public:
  int val;
  int seghi, segmg;
  seg *left, *right;
  seg(int hi, int mg) {
    left = nullptr;
    right = nullptr;
    val = 0;
    seghi = hi;
    segmg = mg;
    if (hi + 1 == mg) {
      return;
    }
    left = new seg(hi, (hi + mg) / 2);
    right = new seg((hi + mg) / 2, mg);
  }
  int ask(int hi, int mg) {
    if (hi <= seghi && segmg <= mg) {
      return val;
    }
    if (mg <= seghi || segmg <= hi) {
      return big;
    }
    return min(left->ask(hi, mg), right->ask(hi, mg));
  }
  void kou(int bas, int num) {
    if (seghi == bas && seghi + 1 == segmg) {
      val = num;
      return;
    }
    if (bas < (seghi + segmg) / 2) {
      left->kou(bas, num);
    } else {
      right->kou(bas, num);
    }
    val = min(left->val, right->val);
  }
};
int main(void) {
  int i, j, n;
  cin >> n;
  seg A(0, n);
  seg B(0, n);
  vector<int> re; //??´??°?????????????¨??????????????????´??°????????????
  for (i = 0; i < n; i++) {
    int a;
    cin >> a;
    A.kou(i, a);
  }
  for (i = 0; i < n; i++) {
    int a;
    cin >> a;
    B.kou(i, a);
  }
  for (i = 0; i < n; i++) {
    re.pub(i);
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y, z;
    cin >> x >> y >> z;
    if (x == 1) {
      A.kou(y - 1, z);
      re.pub(y - 1);
    }
    if (x == 2) {
      B.kou(y - 1, z);
      re.pub(y - 1);
    }
    if (x == 3) {
      cout << A.ask(y - 1, z) << endl;
    }
    if (x == 4) {
      cout << B.ask(y - 1, z) << endl;
    }
    if (x == 5) {
      for (i = 0; i < re.size(); i++) {
        A.kou(re[i], B.ask(re[i], re[i] + 1));
      }
      re.clear();
    }
    if (x == 6) {
      for (i = 0; i < re.size(); i++) {
        B.kou(re[i], A.ask(re[i], re[i] + 1));
      }
      re.clear();
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//<< setprecision(5)
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme                                                                    \\
  cout << -1 << endl;                                                          \\
  return 0
const int mod = 1000000007;
const int big = 1e9 + 10;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;
template <class T, class U> void mineq(T &a, U b) {
  if (a > b) {
    a = b;
  }
}
template <class T, class U> void maxeq(T &a, U b) {
  if (a < b) {
    a = b;
  }
}
llint gcd(llint a, llint b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
llint lcm(llint a, llint b) { return a / gcd(a, b) * b; }
class seg {
public:
  int val;
  int seghi, segmg;
  seg *left, *right;
  seg(int hi, int mg) {
    left = nullptr;
    right = nullptr;
    val = 0;
    seghi = hi;
    segmg = mg;
    if (hi + 1 == mg) {
      return;
    }
    left = new seg(hi, (hi + mg) / 2);
    right = new seg((hi + mg) / 2, mg);
  }
  int ask(int hi, int mg) {
    if (hi <= seghi && segmg <= mg) {
      return val;
    }
    if (mg <= seghi || segmg <= hi) {
      return big;
    }
    return min(left->ask(hi, mg), right->ask(hi, mg));
  }
  void kou(int bas, int num) {
    if (seghi == bas && seghi + 1 == segmg) {
      val = num;
      return;
    }
    if (bas < (seghi + segmg) / 2) {
      left->kou(bas, num);
    } else {
      right->kou(bas, num);
    }
    val = min(left->val, right->val);
  }
};
int main(void) {
  int i, j, n;
  cin >> n;
  seg A(0, n);
  seg B(0, n);
  vector<int> Are; //??´??°?????????????¨??????????????????´??°????????????
  vector<int> Bre;
  for (i = 0; i < n; i++) {
    int a;
    cin >> a;
    A.kou(i, a);
  }
  for (i = 0; i < n; i++) {
    int a;
    cin >> a;
    B.kou(i, a);
  }
  for (i = 0; i < n; i++) {
    Are.pub(i);
    Bre.pub(i);
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y, z;
    cin >> x >> y >> z;
    if (x == 1) {
      A.kou(y - 1, z);
      Are.pub(y - 1);
    }
    if (x == 2) {
      B.kou(y - 1, z);
      Bre.pub(z - 1);
    }
    if (x == 3) {
      cout << A.ask(y - 1, z) << endl;
    }
    if (x == 4) {
      cout << B.ask(y - 1, z) << endl;
    }
    if (x == 5) {
      for (i = 0; i < Bre.size(); i++) {
        A.kou(Bre[i], B.ask(Bre[i], Bre[i] + 1));
      }
      Bre.clear();
    }
    if (x == 6) {
      for (i = 0; i < Are.size(); i++) {
        B.kou(Are[i], A.ask(Are[i], Are[i] + 1));
      }
      Are.clear();
    }
  }
  return 0;
}