Problem:
Problem L: RMQ 2
Problem
長さ$N$の2つの数列$A$と$B$が与えられる。はじめ、数列$A$の$i$項目は$a_i$であり、数列$B$の$i$項目は$b_i$である。
以下のような形式の命令文が合計$Q$個与えられるので、与えられた順に処理を行うプログラムを作成せよ。
各命令文は3つの整数$x,y,z$で表される。
数列$A$の$y$項目の値を$z$にする。 ($x=1$のとき)
数列$B$の$y$項目の値を$z$にする。 ($x=2$のとき)
数列$A$の$y$項目から$z$項目の中で最小の値を見つけて報告する。 ($x=3$のとき)
数列$B$の$y$項目から$z$項目の中で最小の値を見つけて報告する。 ($x=4$のとき)
数列$A$を、数列$B$と全く同じになるように変更する。 ($x=5$のとき)
数列$B$を、数列$A$と全く同じになるように変更する。 ($x=6$のとき)
Input
入力は以下の形式で与えられる。
$N$
$a_{1}$ $a_{2}$ ... $a_{N}$
$b_{1}$ $b_{2}$ ... $b_{N}$
$Q$
$x_1$ $y_1$ $z_1$
$x_2$ $y_2$ $z_2$
...
$x_Q$ $y_Q$ $z_Q$
Constraints
入力は以下の条件を満たす。
$2 \le N \le 2 \times 10^5$
$2 \le Q \le 2 \times 10^5$
$1 \le a_i \le 10^9$
$1 \le b_i \le 10^9$
$1 \le x_i \le 6$
$1 \le y_i \le N $ ($1 \le x_i \le 4$のとき)
$y_i = -1$ ($x_i=5, 6$のとき)
$1 \le z_i \le 10^9$ ($x_i=1, 2$のとき)
$y_i \le z_i \le N$ ($x_i=3, 4$のとき)
$z_i = -1$ ($x_i=5, 6$のとき)
入力はすべて整数
Output
$x=3$または$x=4$の命令文が入力で与えられる度に、見つけた値を1行に出力する。
Sample Input 1
5
1 3 5 7 9
6 2 3 2 6
10
1 3 4
3 4 5
4 2 3
5 -1 -1
2 3 8
3 2 5
4 3 3
1 1 1
6 -1 -1
3 1 5
Sample Output 1
7
2
2
8
1

Submitted solutions:

code_snippet: #line 1 "/home/maspy/compro/library/my_template.hpp"
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;

template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define FOR4_R(i, a, b, c) for (ll i = (b)-1; i >= ll(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) \
  overload4(__VA_ARGS__, FOR4_R, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)

#define FOR_subset(t, s) for (ll t = s; t >= 0; t = (t == 0 ? -1 : (t - 1) & s))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll

template <typename T, typename U>
T SUM(const vector<U> &A) {
  T sum = 0;
  for (auto &&a: A) sum += a;
  return sum;
}

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T pick(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}

template <typename T>
T pick(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}

template <typename T>
T pick(pqg<T> &que) {
  assert(que.size());
  T a = que.top();
  que.pop();
  return a;
}

template <typename T>
T pick(vc<T> &que) {
  assert(que.size());
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename T, typename U>
T ceil(T x, U y) {
  return (x > 0 ? (x + y - 1) / y : x / y);
}

template <typename T, typename U>
T floor(T x, U y) {
  return (x > 0 ? x / y : (x - y + 1) / y);
}

template <typename T, typename U>
pair<T, T> divmod(T x, U y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template <typename F>
ll binary_search(F check, ll ok, ll ng) {
  assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
  }
  return ok;
}

template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
  FOR(iter) {
    double x = (ok + ng) / 2;
    tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
  }
  return (ok + ng) / 2;
}

template <class T, class S>
inline bool chmax(T &a, const S &b) {
  return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
  return (a > b ? a = b, 1 : 0);
}

vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  FOR(i, S.size()) { A[i] = S[i] - first_char; }
  return A;
}

template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
  int N = A.size();
  vector<T> B(N + 1);
  FOR(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

template <typename CNT, typename T>
vc<CNT> bincount(const vc<T> &A, int size) {
  vc<CNT> C(size);
  for (auto &&x: A) { ++C[x]; }
  return C;
}

// stable
template <typename T>
vector<int> argsort(const vector<T> &A) {
  vector<int> ids(A.size());
  iota(all(ids), 0);
  sort(all(ids),
       [&](int i, int j) { return A[i] < A[j] || (A[i] == A[j] && i < j); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
  int n = len(I);
  vc<T> B(n);
  FOR(i, n) B[i] = A[I[i]];
  return B;
}
#line 1 "/home/maspy/compro/library/other/io.hpp"
// based on yosupo's fastio
#include <unistd.h>

namespace detail {
template <typename T, decltype(&T::is_modint) = &T::is_modint>
std::true_type check_value(int);
template <typename T>
std::false_type check_value(long);
} // namespace detail

template <typename T>
struct is_modint : decltype(detail::check_value<T>(0)) {};
template <typename T>
using is_modint_t = enable_if_t<is_modint<T>::value>;
template <typename T>
using is_not_modint_t = enable_if_t<!is_modint<T>::value>;

struct Scanner {
  FILE *fp;
  char line[(1 << 15) + 1];
  size_t st = 0, ed = 0;
  void reread() {
    memmove(line, line + st, ed - st);
    ed -= st;
    st = 0;
    ed += fread(line + ed, 1, (1 << 15) - ed, fp);
    line[ed] = '\0';
  }
  bool succ() {
    while (true) {
      if (st == ed) {
        reread();
        if (st == ed) return false;
      }
      while (st != ed && isspace(line[st])) st++;
      if (st != ed) break;
    }
    if (ed - st <= 50) {
      bool sep = false;
      for (size_t i = st; i < ed; i++) {
        if (isspace(line[i])) {
          sep = true;
          break;
        }
      }
      if (!sep) reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    while (true) {
      size_t sz = 0;
      while (st + sz < ed && !isspace(line[st + sz])) sz++;
      ref.append(line + st, sz);
      st += sz;
      if (!sz || st != ed) break;
      reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    bool neg = false;
    if (line[st] == '-') {
      neg = true;
      st++;
    }
    ref = T(0);
    while (isdigit(line[st])) { ref = 10 * ref + (line[st++] & 0xf); }
    if (neg) ref = -ref;
    return true;
  }
  template <class T, is_modint_t<T> * = nullptr>
  bool read_single(T &ref) {
    long long val = 0;
    bool f = read_single(val);
    ref = T(val);
    return f;
  }
  bool read_single(double &ref) {
    string s;
    if (!read_single(s)) return false;
    ref = std::stod(s);
    return true;
  }
  bool read_single(char &ref) {
    string s;
    if (!read_single(s) || s.size() != 1) return false;
    ref = s[0];
    return true;
  }
  template <class T>
  bool read_single(vector<T> &ref) {
    for (auto &d: ref) {
      if (!read_single(d)) return false;
    }
    return true;
  }
  template <class T, class U>
  bool read_single(pair<T, U> &p) {
    return (read_single(p.first) && read_single(p.second));
  }
  template <class A, class B, class C>
  bool read_single(tuple<A, B, C> &p) {
    return (read_single(get<0>(p)) && read_single(get<1>(p))
            && read_single(get<2>(p)));
  }
  template <class A, class B, class C, class D>
  bool read_single(tuple<A, B, C, D> &p) {
    return (read_single(get<0>(p)) && read_single(get<1>(p))
            && read_single(get<2>(p)) && read_single(get<3>(p)));
  }
  void read() {}
  template <class H, class... T>
  void read(H &h, T &... t) {
    bool f = read_single(h);
    assert(f);
    read(t...);
  }
  Scanner(FILE *fp) : fp(fp) {}
};

struct Printer {
  Printer(FILE *_fp) : fp(_fp) {}
  ~Printer() { flush(); }

  static constexpr size_t SIZE = 1 << 15;
  FILE *fp;
  char line[SIZE], small[50];
  size_t pos = 0;
  void flush() {
    fwrite(line, 1, pos, fp);
    pos = 0;
  }
  void write(const char &val) {
    if (pos == SIZE) flush();
    line[pos++] = val;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  void write(T val) {
    if (pos > (1 << 15) - 50) flush();
    if (val == 0) {
      write('0');
      return;
    }
    if (val < 0) {
      write('-');
      val = -val; // todo min
    }
    size_t len = 0;
    while (val) {
      small[len++] = char(0x30 | (val % 10));
      val /= 10;
    }
    for (size_t i = 0; i < len; i++) { line[pos + i] = small[len - 1 - i]; }
    pos += len;
  }
  void write(const string &s) {
    for (char c: s) write(c);
  }
  void write(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++) write(s[i]);
  }
  void write(const double &x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  void write(const long double &x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  template <class T, is_modint_t<T> * = nullptr>
  void write(T &ref) {
    write(ref.val);
  }
  template <class T>
  void write(const vector<T> &val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  template <class T, class U>
  void write(const pair<T, U> &val) {
    write(val.first);
    write(' ');
    write(val.second);
  }
  template <class A, class B, class C>
  void write(const tuple<A, B, C> &val) {
    auto &[a, b, c] = val;
    write(a), write(' '), write(b), write(' '), write(c);
  }
  template <class A, class B, class C, class D>
  void write(const tuple<A, B, C, D> &val) {
    auto &[a, b, c, d] = val;
    write(a), write(' '), write(b), write(' '), write(c), write(' '), write(d);
  }
  template <class A, class B, class C, class D, class E>
  void write(const tuple<A, B, C, D, E> &val) {
    auto &[a, b, c, d, e] = val;
    write(a), write(' '), write(b), write(' '), write(c), write(' '), write(d), write(' '), write(e);
  }
  template <class A, class B, class C, class D, class E, class F>
  void write(const tuple<A, B, C, D, E, F> &val) {
    auto &[a, b, c, d, e, f] = val;
    write(a), write(' '), write(b), write(' '), write(c), write(' '), write(d), write(' '), write(e), write(' '), write(f);
  }
  template <class T, size_t S>
  void write(const array<T, S> &val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  void write(i128 val) {
    string s;
    bool negative = 0;
    if(val < 0){
      negative = 1;
      val = -val;
    }
    while (val) {
      s += '0' + int(val % 10);
      val /= 10;
    }
    if(negative) s += "-";
    reverse(all(s));
    if (len(s) == 0) s = "0";
    write(s);
  }
};

Scanner scanner = Scanner(stdin);
Printer printer = Printer(stdout);

void flush() { printer.flush(); }
void print() { printer.write('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  printer.write(head);
  if (sizeof...(Tail)) printer.write(' ');
  print(forward<Tail>(tail)...);
}

void read() {}
template <class Head, class... Tail>
void read(Head &head, Tail &... tail) {
  scanner.read(head);
  read(tail...);
}

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __VA_ARGS__; \
  read(__VA_ARGS__)
#define STR(...)      \
  string __VA_ARGS__; \
  read(__VA_ARGS__)
#define CHAR(...)      \
  char __VA_ARGS__; \
  read(__VA_ARGS__)
#define DBL(...)      \
  double __VA_ARGS__; \
  read(__VA_ARGS__)

#define VEC(type, name, size) \
  vector<type> name(size);    \
  read(name)
#define VV(type, name, h, w)                     \
  vector<vector<type>> name(h, vector<type>(w)); \
  read(name)

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 2 "/home/maspy/compro/library/ds/lazysegtree.hpp"

template <typename Lazy>
struct LazySegTree {
  using Monoid_X = typename Lazy::X_structure;
  using Monoid_A = typename Lazy::A_structure;
  using X = typename Monoid_X::value_type;
  using A = typename Monoid_A::value_type;
  int n, log, size;
  vc<X> dat;
  vc<A> laz;

  LazySegTree() : LazySegTree(0) {}
  LazySegTree(int n) : LazySegTree(vc<X>(n, Monoid_X::unit())) {}
  LazySegTree(vc<X> v) : n(len(v)) {
    log = 1;
    while ((1 << log) < n) ++log;
    size = 1 << log;
    dat.assign(size << 1, Monoid_X::unit());
    laz.assign(size, Monoid_A::unit());
    FOR(i, n) dat[size + i] = v[i];
    FOR3_R(i, 1, size) update(i);
  }

  template <typename F>
  LazySegTree(int n, F f) : n(n) {
    log = 1;
    while ((1 << log) < n) ++log;
    size = 1 << log;
    dat.assign(size << 1, Monoid_X::unit());
    laz.assign(size, Monoid_A::unit());
    FOR(i, n) dat[size + i] = f(i);
    FOR3_R(i, 1, size) update(i);
  }

  void reset() {
    fill(all(dat), Monoid_X::unit());
    fill(all(laz), Monoid_A::unit());
  }

  void reset(const vc<X>& v) {
    assert(len(v) == n);
    reset();
    FOR(i, n) dat[size + i] = v[i];
    FOR3_R(i, 1, size) update(i);
  }

  void update(int k) { dat[k] = Monoid_X::op(dat[2 * k], dat[2 * k + 1]); }

  void all_apply(int k, A a) {
    dat[k] = Lazy::act(dat[k], a);
    if (k < size) laz[k] = Monoid_A::op(laz[k], a);
  }

  void push(int k) {
    all_apply(2 * k, laz[k]);
    all_apply(2 * k + 1, laz[k]);
    laz[k] = Monoid_A::unit();
  }

  void set(int p, X x) {
    assert(0 <= p && p < n);
    p += size;
    for (int i = log; i >= 1; i--) push(p >> i);
    dat[p] = x;
    for (int i = 1; i <= log; i++) update(p >> i);
  }

  X get(int p) {
    assert(0 <= p && p < n);
    p += size;
    for (int i = log; i >= 1; i--) push(p >> i);
    return dat[p];
  }

  vc<X> get_all() {
    FOR(i, size) push(i);
    return {dat.begin() + size, dat.begin() + size + n};
  }

  X prod(int l, int r) {
    assert(0 <= l && l <= r && r <= n);
    if (l == r) return Monoid_X::unit();

    l += size;
    r += size;

    for (int i = log; i >= 1; i--) {
      if (((l >> i) << i) != l) push(l >> i);
      if (((r >> i) << i) != r) push((r - 1) >> i);
    }

    X xl = Monoid_X::unit(), xr = Monoid_X::unit();
    while (l < r) {
      if (l & 1) xl = Monoid_X::op(xl, dat[l++]);
      if (r & 1) xr = Monoid_X::op(dat[--r], xr);
      l >>= 1;
      r >>= 1;
    }

    return Monoid_X::op(xl, xr);
  }

  X prod_all() { return dat[1]; }

  void apply(int p, A a) {
    assert(0 <= p && p < n);
    p += size;
    dat[p] = Lazy::act(dat[p], a);
    for (int i = 1; i <= log; i++) update(p >> i);
  }

  void apply(int l, int r, A a) {
    assert(0 <= l && l <= r && r <= n);
    if (l == r) return;

    l += size;
    r += size;

    for (int i = log; i >= 1; i--) {
      if (((l >> i) << i) != l) push(l >> i);
      if (((r >> i) << i) != r) push((r - 1) >> i);
    }

    {
      int l2 = l, r2 = r;
      while (l < r) {
        if (l & 1) all_apply(l++, a);
        if (r & 1) all_apply(--r, a);
        l >>= 1;
        r >>= 1;
      }
      l = l2;
      r = r2;
    }

    for (int i = 1; i <= log; i++) {
      if (((l >> i) << i) != l) update(l >> i);
      if (((r >> i) << i) != r) update((r - 1) >> i);
    }
  }

  template <typename C>
  int max_right(C& check, int l) {
    assert(0 <= l && l <= n);
    assert(check(Monoid_X::unit()));
    if (l == n) return n;
    l += size;
    for (int i = log; i >= 1; i--) push(l >> i);
    X sm = Monoid_X::unit();
    do {
      while (l % 2 == 0) l >>= 1;
      if (!check(Monoid_X::op(sm, dat[l]))) {
        while (l < size) {
          push(l);
          l = (2 * l);
          if (check(Monoid_X::op(sm, dat[l]))) {
            sm = Monoid_X::op(sm, dat[l]);
            l++;
          }
        }
        return l - size;
      }
      sm = Monoid_X::op(sm, dat[l]);
      l++;
    } while ((l & -l) != l);
    return n;
  }

  template <typename C>
  int min_left(C& check, int r) {
    assert(0 <= r && r <= n);
    assert(check(Monoid_X::unit()));
    if (r == 0) return 0;
    r += size;
    for (int i = log; i >= 1; i--) push((r - 1) >> i);
    X sm = Monoid_X::unit();
    do {
      r--;
      while (r > 1 && (r % 2)) r >>= 1;
      if (!check(Monoid_X::op(dat[r], sm))) {
        while (r < size) {
          push(r);
          r = (2 * r + 1);
          if (check(Monoid_X::op(dat[r], sm))) {
            sm = Monoid_X::op(dat[r], sm);
            r--;
          }
        }
        return r + 1 - size;
      }
      sm = Monoid_X::op(dat[r], sm);
    } while ((r & -r) != r);
    return 0;
  }

  void debug() { print("lazysegtree getall:", get_all()); }
};
#line 4 "main.cpp"

struct MonoX {
  using value_type = pair<int, int>;
  using X = value_type;
  static X op(X x, X y) { return {min(x.fi, y.fi), min(x.se, y.se)}; }
  static constexpr X unit() {
    constexpr int mx = numeric_limits<int>::max();
    return {mx, mx};
  }
  static constexpr bool commute = 1;
};

struct MonoA {
  using value_type = int;
  using X = value_type;
  static X op(X x, X y) {
    if (x == 0) return y;
    return x;
  }
  static constexpr X unit() { return 0; }
  static constexpr bool commute = 0;
};

struct Lazy {
  using MX = MonoX;
  using MA = MonoA;
  using X_structure = MX;
  using A_structure = MA;
  using X = typename MX::value_type;
  using A = typename MA::value_type;
  static constexpr X act(const X &x, const A &a) {
    if (a == 0) return x;
    if (a == 1) return {x.fi, x.fi};
    return {x.se, x.se};
  }
};

void solve() {
  LL(N);
  VEC(int, A, N);
  VEC(int, B, N);
  LazySegTree<Lazy> seg(N, [&](int i) -> pair<int, int> {
    return {A[i], B[i]};
  });
  LL(Q);
  FOR(Q) {
    LL(x, y, z);
    --y;
    if (x == 1) {
      auto [a, b] = seg.prod(y, y + 1);
      seg.set(y, {z, b});
    }
    if (x == 2) {
      auto [a, b] = seg.prod(y, y + 1);
      seg.set(y, {a, z});
    }
    if (x == 3) { print(seg.prod(y, z).fi); }
    if (x == 4) { print(seg.prod(y, z).se); }
    if (x == 5) seg.apply(0, N, 2);
    if (x == 6) seg.apply(0, N, 1);
  }
}

signed main() {
  cout << fixed << setprecision(15);

  ll T = 1;
  // LL(T);
  FOR(T) solve();

  return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 9848
final_rank: 1

code_snippet: #line 1 "/home/maspy/compro/library/my_template.hpp"
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;

template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define FOR4_R(i, a, b, c) for (ll i = (b)-1; i >= ll(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) \
  overload4(__VA_ARGS__, FOR4_R, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)

#define FOR_subset(t, s) for (ll t = s; t >= 0; t = (t == 0 ? -1 : (t - 1) & s))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll

template <typename T, typename U>
T SUM(const vector<U> &A) {
  T sum = 0;
  for (auto &&a: A) sum += a;
  return sum;
}

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T pick(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}

template <typename T>
T pick(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}

template <typename T>
T pick(pqg<T> &que) {
  assert(que.size());
  T a = que.top();
  que.pop();
  return a;
}

template <typename T>
T pick(vc<T> &que) {
  assert(que.size());
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename T, typename U>
T ceil(T x, U y) {
  return (x > 0 ? (x + y - 1) / y : x / y);
}

template <typename T, typename U>
T floor(T x, U y) {
  return (x > 0 ? x / y : (x - y + 1) / y);
}

template <typename T, typename U>
pair<T, T> divmod(T x, U y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template <typename F>
ll binary_search(F check, ll ok, ll ng) {
  assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
  }
  return ok;
}

template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
  FOR(iter) {
    double x = (ok + ng) / 2;
    tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
  }
  return (ok + ng) / 2;
}

template <class T, class S>
inline bool chmax(T &a, const S &b) {
  return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
  return (a > b ? a = b, 1 : 0);
}

vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  FOR(i, S.size()) { A[i] = S[i] - first_char; }
  return A;
}

template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
  int N = A.size();
  vector<T> B(N + 1);
  FOR(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

template <typename CNT, typename T>
vc<CNT> bincount(const vc<T> &A, int size) {
  vc<CNT> C(size);
  for (auto &&x: A) { ++C[x]; }
  return C;
}

// stable
template <typename T>
vector<int> argsort(const vector<T> &A) {
  vector<int> ids(A.size());
  iota(all(ids), 0);
  sort(all(ids),
       [&](int i, int j) { return A[i] < A[j] || (A[i] == A[j] && i < j); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
  int n = len(I);
  vc<T> B(n);
  FOR(i, n) B[i] = A[I[i]];
  return B;
}
#line 1 "/home/maspy/compro/library/other/io.hpp"
// based on yosupo's fastio
#include <unistd.h>

namespace detail {
template <typename T, decltype(&T::is_modint) = &T::is_modint>
std::true_type check_value(int);
template <typename T>
std::false_type check_value(long);
} // namespace detail

template <typename T>
struct is_modint : decltype(detail::check_value<T>(0)) {};
template <typename T>
using is_modint_t = enable_if_t<is_modint<T>::value>;
template <typename T>
using is_not_modint_t = enable_if_t<!is_modint<T>::value>;

struct Scanner {
  FILE *fp;
  char line[(1 << 15) + 1];
  size_t st = 0, ed = 0;
  void reread() {
    memmove(line, line + st, ed - st);
    ed -= st;
    st = 0;
    ed += fread(line + ed, 1, (1 << 15) - ed, fp);
    line[ed] = '\0';
  }
  bool succ() {
    while (true) {
      if (st == ed) {
        reread();
        if (st == ed) return false;
      }
      while (st != ed && isspace(line[st])) st++;
      if (st != ed) break;
    }
    if (ed - st <= 50) {
      bool sep = false;
      for (size_t i = st; i < ed; i++) {
        if (isspace(line[i])) {
          sep = true;
          break;
        }
      }
      if (!sep) reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    while (true) {
      size_t sz = 0;
      while (st + sz < ed && !isspace(line[st + sz])) sz++;
      ref.append(line + st, sz);
      st += sz;
      if (!sz || st != ed) break;
      reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    bool neg = false;
    if (line[st] == '-') {
      neg = true;
      st++;
    }
    ref = T(0);
    while (isdigit(line[st])) { ref = 10 * ref + (line[st++] & 0xf); }
    if (neg) ref = -ref;
    return true;
  }
  template <class T, is_modint_t<T> * = nullptr>
  bool read_single(T &ref) {
    long long val = 0;
    bool f = read_single(val);
    ref = T(val);
    return f;
  }
  bool read_single(double &ref) {
    string s;
    if (!read_single(s)) return false;
    ref = std::stod(s);
    return true;
  }
  bool read_single(char &ref) {
    string s;
    if (!read_single(s) || s.size() != 1) return false;
    ref = s[0];
    return true;
  }
  template <class T>
  bool read_single(vector<T> &ref) {
    for (auto &d: ref) {
      if (!read_single(d)) return false;
    }
    return true;
  }
  template <class T, class U>
  bool read_single(pair<T, U> &p) {
    return (read_single(p.first) && read_single(p.second));
  }
  template <class A, class B, class C>
  bool read_single(tuple<A, B, C> &p) {
    return (read_single(get<0>(p)) && read_single(get<1>(p))
            && read_single(get<2>(p)));
  }
  template <class A, class B, class C, class D>
  bool read_single(tuple<A, B, C, D> &p) {
    return (read_single(get<0>(p)) && read_single(get<1>(p))
            && read_single(get<2>(p)) && read_single(get<3>(p)));
  }
  void read() {}
  template <class H, class... T>
  void read(H &h, T &... t) {
    bool f = read_single(h);
    assert(f);
    read(t...);
  }
  Scanner(FILE *fp) : fp(fp) {}
};

struct Printer {
  Printer(FILE *_fp) : fp(_fp) {}
  ~Printer() { flush(); }

  static constexpr size_t SIZE = 1 << 15;
  FILE *fp;
  char line[SIZE], small[50];
  size_t pos = 0;
  void flush() {
    fwrite(line, 1, pos, fp);
    pos = 0;
  }
  void write(const char &val) {
    if (pos == SIZE) flush();
    line[pos++] = val;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  void write(T val) {
    if (pos > (1 << 15) - 50) flush();
    if (val == 0) {
      write('0');
      return;
    }
    if (val < 0) {
      write('-');
      val = -val; // todo min
    }
    size_t len = 0;
    while (val) {
      small[len++] = char(0x30 | (val % 10));
      val /= 10;
    }
    for (size_t i = 0; i < len; i++) { line[pos + i] = small[len - 1 - i]; }
    pos += len;
  }
  void write(const string &s) {
    for (char c: s) write(c);
  }
  void write(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++) write(s[i]);
  }
  void write(const double &x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  void write(const long double &x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  template <class T, is_modint_t<T> * = nullptr>
  void write(T &ref) {
    write(ref.val);
  }
  template <class T>
  void write(const vector<T> &val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  template <class T, class U>
  void write(const pair<T, U> &val) {
    write(val.first);
    write(' ');
    write(val.second);
  }
  template <class A, class B, class C>
  void write(const tuple<A, B, C> &val) {
    auto &[a, b, c] = val;
    write(a), write(' '), write(b), write(' '), write(c);
  }
  template <class A, class B, class C, class D>
  void write(const tuple<A, B, C, D> &val) {
    auto &[a, b, c, d] = val;
    write(a), write(' '), write(b), write(' '), write(c), write(' '), write(d);
  }
  template <class A, class B, class C, class D, class E>
  void write(const tuple<A, B, C, D, E> &val) {
    auto &[a, b, c, d, e] = val;
    write(a), write(' '), write(b), write(' '), write(c), write(' '), write(d), write(' '), write(e);
  }
  template <class A, class B, class C, class D, class E, class F>
  void write(const tuple<A, B, C, D, E, F> &val) {
    auto &[a, b, c, d, e, f] = val;
    write(a), write(' '), write(b), write(' '), write(c), write(' '), write(d), write(' '), write(e), write(' '), write(f);
  }
  template <class T, size_t S>
  void write(const array<T, S> &val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  void write(i128 val) {
    string s;
    bool negative = 0;
    if(val < 0){
      negative = 1;
      val = -val;
    }
    while (val) {
      s += '0' + int(val % 10);
      val /= 10;
    }
    if(negative) s += "-";
    reverse(all(s));
    if (len(s) == 0) s = "0";
    write(s);
  }
};

Scanner scanner = Scanner(stdin);
Printer printer = Printer(stdout);

void flush() { printer.flush(); }
void print() { printer.write('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  printer.write(head);
  if (sizeof...(Tail)) printer.write(' ');
  print(forward<Tail>(tail)...);
}

void read() {}
template <class Head, class... Tail>
void read(Head &head, Tail &... tail) {
  scanner.read(head);
  read(tail...);
}

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __VA_ARGS__; \
  read(__VA_ARGS__)
#define STR(...)      \
  string __VA_ARGS__; \
  read(__VA_ARGS__)
#define CHAR(...)      \
  char __VA_ARGS__; \
  read(__VA_ARGS__)
#define DBL(...)      \
  double __VA_ARGS__; \
  read(__VA_ARGS__)

#define VEC(type, name, size) \
  vector<type> name(size);    \
  read(name)
#define VV(type, name, h, w)                     \
  vector<vector<type>> name(h, vector<type>(w)); \
  read(name)

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 2 "/home/maspy/compro/library/ds/lazysegtree.hpp"

template <typename Lazy>
struct LazySegTree {
  using Monoid_X = typename Lazy::X_structure;
  using Monoid_A = typename Lazy::A_structure;
  using X = typename Monoid_X::value_type;
  using A = typename Monoid_A::value_type;
  int n, log, size;
  vc<X> dat;
  vc<A> laz;

  LazySegTree() : LazySegTree(0) {}
  LazySegTree(int n) : LazySegTree(vc<X>(n, Monoid_X::unit())) {}
  LazySegTree(vc<X> v) : n(len(v)) {
    log = 1;
    while ((1 << log) < n) ++log;
    size = 1 << log;
    dat.assign(size << 1, Monoid_X::unit());
    laz.assign(size, Monoid_A::unit());
    FOR(i, n) dat[size + i] = v[i];
    FOR3_R(i, 1, size) update(i);
  }

  template <typename F>
  LazySegTree(int n, F f) : n(n) {
    log = 1;
    while ((1 << log) < n) ++log;
    size = 1 << log;
    dat.assign(size << 1, Monoid_X::unit());
    laz.assign(size, Monoid_A::unit());
    FOR(i, n) dat[size + i] = f(i);
    FOR3_R(i, 1, size) update(i);
  }

  void reset() {
    fill(all(dat), Monoid_X::unit());
    fill(all(laz), Monoid_A::unit());
  }

  void reset(const vc<X>& v) {
    assert(len(v) == n);
    reset();
    FOR(i, n) dat[size + i] = v[i];
    FOR3_R(i, 1, size) update(i);
  }

  void update(int k) { dat[k] = Monoid_X::op(dat[2 * k], dat[2 * k + 1]); }

  void all_apply(int k, A a) {
    dat[k] = Lazy::act(dat[k], a);
    if (k < size) laz[k] = Monoid_A::op(laz[k], a);
  }

  void push(int k) {
    all_apply(2 * k, laz[k]);
    all_apply(2 * k + 1, laz[k]);
    laz[k] = Monoid_A::unit();
  }

  void set(int p, X x) {
    assert(0 <= p && p < n);
    p += size;
    for (int i = log; i >= 1; i--) push(p >> i);
    dat[p] = x;
    for (int i = 1; i <= log; i++) update(p >> i);
  }

  X get(int p) {
    assert(0 <= p && p < n);
    p += size;
    for (int i = log; i >= 1; i--) push(p >> i);
    return dat[p];
  }

  vc<X> get_all() {
    FOR(i, size) push(i);
    return {dat.begin() + size, dat.begin() + size + n};
  }

  X prod(int l, int r) {
    assert(0 <= l && l <= r && r <= n);
    if (l == r) return Monoid_X::unit();

    l += size;
    r += size;

    for (int i = log; i >= 1; i--) {
      if (((l >> i) << i) != l) push(l >> i);
      if (((r >> i) << i) != r) push((r - 1) >> i);
    }

    X xl = Monoid_X::unit(), xr = Monoid_X::unit();
    while (l < r) {
      if (l & 1) xl = Monoid_X::op(xl, dat[l++]);
      if (r & 1) xr = Monoid_X::op(dat[--r], xr);
      l >>= 1;
      r >>= 1;
    }

    return Monoid_X::op(xl, xr);
  }

  X prod_all() { return dat[1]; }

  void apply(int p, A a) {
    assert(0 <= p && p < n);
    p += size;
    dat[p] = Lazy::act(dat[p], a);
    for (int i = 1; i <= log; i++) update(p >> i);
  }

  void apply(int l, int r, A a) {
    assert(0 <= l && l <= r && r <= n);
    if (l == r) return;

    l += size;
    r += size;

    for (int i = log; i >= 1; i--) {
      if (((l >> i) << i) != l) push(l >> i);
      if (((r >> i) << i) != r) push((r - 1) >> i);
    }

    {
      int l2 = l, r2 = r;
      while (l < r) {
        if (l & 1) all_apply(l++, a);
        if (r & 1) all_apply(--r, a);
        l >>= 1;
        r >>= 1;
      }
      l = l2;
      r = r2;
    }

    for (int i = 1; i <= log; i++) {
      if (((l >> i) << i) != l) update(l >> i);
      if (((r >> i) << i) != r) update((r - 1) >> i);
    }
  }

  template <typename C>
  int max_right(C& check, int l) {
    assert(0 <= l && l <= n);
    assert(check(Monoid_X::unit()));
    if (l == n) return n;
    l += size;
    for (int i = log; i >= 1; i--) push(l >> i);
    X sm = Monoid_X::unit();
    do {
      while (l % 2 == 0) l >>= 1;
      if (!check(Monoid_X::op(sm, dat[l]))) {
        while (l < size) {
          push(l);
          l = (2 * l);
          if (check(Monoid_X::op(sm, dat[l]))) {
            sm = Monoid_X::op(sm, dat[l]);
            l++;
          }
        }
        return l - size;
      }
      sm = Monoid_X::op(sm, dat[l]);
      l++;
    } while ((l & -l) != l);
    return n;
  }

  template <typename C>
  int min_left(C& check, int r) {
    assert(0 <= r && r <= n);
    assert(check(Monoid_X::unit()));
    if (r == 0) return 0;
    r += size;
    for (int i = log; i >= 1; i--) push((r - 1) >> i);
    X sm = Monoid_X::unit();
    do {
      r--;
      while (r > 1 && (r % 2)) r >>= 1;
      if (!check(Monoid_X::op(dat[r], sm))) {
        while (r < size) {
          push(r);
          r = (2 * r + 1);
          if (check(Monoid_X::op(dat[r], sm))) {
            sm = Monoid_X::op(dat[r], sm);
            r--;
          }
        }
        return r + 1 - size;
      }
      sm = Monoid_X::op(dat[r], sm);
    } while ((r & -r) != r);
    return 0;
  }

  void debug() { print("lazysegtree getall:", get_all()); }
};
#line 4 "main.cpp"

struct MonoX {
  using value_type = pair<int, int>;
  using X = value_type;
  static X op(X x, X y) { return {min(x.fi, y.fi), min(x.se, y.se)}; }
  static constexpr X unit() {
    constexpr int mx = numeric_limits<int>::max();
    return {mx, mx};
  }
  static constexpr bool commute = 1;
};

struct MonoA {
  using value_type = int;
  using X = value_type;
  static X op(X x, X y) {
    if (x == 0) return y;
    return x;
  }
  static constexpr X unit() { return 0; }
  static constexpr bool commute = 0;
};

struct Lazy {
  using MX = MonoX;
  using MA = MonoA;
  using X_structure = MX;
  using A_structure = MA;
  using X = typename MX::value_type;
  using A = typename MA::value_type;
  static constexpr X act(const X &x, const A &a) {
    if (a == 0) return x;
    if (a == 1) return {x.fi, x.fi};
    return {x.se, x.se};
  }
};

void solve() {
  LL(N);
  VEC(int, A, N);
  VEC(int, B, N);
  LazySegTree<Lazy> seg(N, [&](int i) -> pair<int, int> {
    return {A[i], B[i]};
  });
  LL(Q);
  FOR(Q) {
    LL(x, y, z);
    --y;
    if (x == 1) {
      A[y] = z;
      seg.set(y, {A[y], B[y]});
    }
    if (x == 2) {
      B[y] = z;
      seg.set(y, {A[y], B[y]});
    }
    if (x == 3) { print(seg.prod(y, z).fi); }
    if (x == 4) { print(seg.prod(y, z).se); }
    if (x == 5) seg.apply(0, N, 2);
    if (x == 6) seg.apply(0, N, 1);
  }
}

signed main() {
  cout << fixed << setprecision(15);

  ll T = 1;
  // LL(T);
  FOR(T) solve();

  return 0;
}
accuracy: 0.125
time_ms: 40
memory_kb: 9740
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;

template <class T>
struct SegmentTree {
  typedef function<T(T, T)> F;
  int n;
  F f;
  T unit;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(const vector<T> &v, F f, T t) : f(f), unit(t) {
    int _n = v.size();
    init(v.size());
    for (int i = 0; i < _n; ++i) dat[n + i] = v[i];
    for (int i = n - 1; i >= 0; --i) dat[i] = f(dat[i << 1], dat[(i << 1) | 1]);
  }
  void init(int _n) {
    n = 1;
    while (n < _n) n <<= 1;
    dat.assign(n << 1, unit);
  }
  void update(int k, T newdata) {
    dat[k += n] = newdata;
    while (k >>= 1) dat[k] = f(dat[k << 1], dat[(k << 1) | 1]);
  }
  T query(int a, int b) {
    T vl = unit, vr = unit;
    for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) vl = f(vl, dat[l++]);
      if (r & 1) vr = f(dat[--r], vr);
    }
    return f(vl, vr);
  }
};

struct query {
  int x, y, z;
  query(int a = 0, int b = 0, int c = 0) : x(a), y(b), z(c) {}
};

using P = pair<int, int>;
int n, q;
vector<int> a, b;
vector<query> qu, memo[2];
SegmentTree<int> seg[2];

int main() {
  cin >> n;
  a.resize(n);
  for (auto &p : a) cin >> p;
  b.resize(n);
  for (auto &p : b) cin >> p;
  cin >> q;
  qu.resize(q);
  for (auto &p : qu) cin >> p.x >> p.y >> p.z;
  auto f = [](int l, int r) { return min(l, r); };
  seg[1] = SegmentTree<int>(a, f, 2e9);
  seg[0] = SegmentTree<int>(b, f, 2e9);
  bool copied = 0;
  for (auto [x, y, z] : qu) {
    if (x <= 2) {
      --y;
      int now = seg[x & 1].query(y, y + 1);
      memo[x & 1].emplace_back(y, now, z);
      seg[x & 1].update(y, z);
    } else if (x <= 4)
      cout << seg[x & 1].query(--y, z) << endl;
    else {
      if (!copied)
        seg[x & 1] = seg[(x & 1) ^ 1];
      else {
        while (memo[x & 1].size()) {
          auto [id, bf, af] = memo[x & 1].back();
          seg[x & 1].update(id, bf);
          memo[x & 1].pop_back();
        }
        int len = memo[(x & 1) ^ 1].size();
        for (int j = 0; j < len; ++j) {
          auto [id, bf, af] = memo[(x & 1) ^ 1][j];
          seg[x & 1].update(id, af);
        }
      }
      copied = 1;
      memo[0].clear();
      memo[1].clear();
    }
  }
  return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 11232
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

template <class T>
struct SegmentTree {
  typedef function<T(T, T)> F;
  int n;
  F f;
  T unit;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(const vector<T> &v, F f, T t) : f(f), unit(t) {
    int _n = v.size();
    init(v.size());
    for (int i = 0; i < _n; ++i) dat[n + i] = v[i];
    for (int i = n - 1; i >= 0; --i) dat[i] = f(dat[i << 1], dat[(i << 1) | 1]);
  }
  void init(int _n) {
    n = 1;
    while (n < _n) n <<= 1;
    dat.assign(n << 1, unit);
  }
  void update(int k, T newdata) {
    dat[k += n] = newdata;
    while (k >>= 1) dat[k] = f(dat[k << 1], dat[(k << 1) | 1]);
  }
  T query(int a, int b) {
    T vl = unit, vr = unit;
    for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) vl = f(vl, dat[l++]);
      if (r & 1) vr = f(dat[--r], vr);
    }
    return f(vl, vr);
  }
};

struct query {
  int x, y, z;
  query(int a = 0, int b = 0, int c = 0) : x(a), y(b), z(c) {}
};

using P = pair<int, int>;
int n, q;
vector<int> a, b;
vector<query> qu, memo[2];
SegmentTree<int> seg[2];

int main() {
  cin >> n;
  a.resize(n);
  for (auto &p : a) cin >> p;
  b.resize(n);
  for (auto &p : b) cin >> p;
  cin >> q;
  qu.resize(q);
  for (auto &p : qu) cin >> p.x >> p.y >> p.z;
  auto f = [](int l, int r) { return min(l, r); };
  seg[1] = SegmentTree<int>(a, f, 2e9);
  seg[0] = SegmentTree<int>(b, f, 2e9);
  bool copied = 0;
  for (auto [x, y, z] : qu) {
    if (x <= 2) {
      --y;
      int now = seg[x & 1].query(y, y + 1);
      memo[x & 1].emplace_back(y, now, z);
      seg[x & 1].update(y, z);
    } else if (x <= 4)
      cout << seg[x & 1].query(--y, z) << endl;
    else {
      if (!copied)
        seg[x & 1] = seg[(x & 1) ^ 1];
      else {
        while (memo[x & 1].size()) {
          auto [id, bf, af] = memo[x & 1].back();
          seg[x & 1].update(id, bf);
          memo[x & 1].pop_back();
        }
        int len = memo[(x & 1) ^ 1].size();
        for (int j = 0; j < len; ++j) {
          auto [id, bf, af] = memo[(x & 1) ^ 1][j];
          seg[(x & 1) ^ 1].update(id, af);
        }
      }
      copied = 1;
      memo[0].clear();
      memo[1].clear();
    }
  }
  return 0;
}
accuracy: 0.125
time_ms: 190
memory_kb: 10900
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;

template <class T>
struct SegmentTree {
  typedef function<T(T, T)> F;
  int n;
  F f;
  T unit;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(const vector<T> &v, F f, T t) : f(f), unit(t) {
    int _n = v.size();
    init(v.size());
    for (int i = 0; i < _n; ++i) dat[n + i] = v[i];
    for (int i = n - 1; i >= 0; --i) dat[i] = f(dat[i << 1], dat[(i << 1) | 1]);
  }
  void init(int _n) {
    n = 1;
    while (n < _n) n <<= 1;
    dat.assign(n << 1, unit);
  }
  void update(int k, T newdata) {
    dat[k += n] = newdata;
    while (k >>= 1) dat[k] = f(dat[k << 1], dat[(k << 1) | 1]);
  }
  T query(int a, int b) {
    T vl = unit, vr = unit;
    for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) vl = f(vl, dat[l++]);
      if (r & 1) vr = f(dat[--r], vr);
    }
    return f(vl, vr);
  }
};

struct query {
  int x, y, z;
  query(int a = 0, int b = 0, int c = 0) : x(a), y(b), z(c) {}
};

using P = pair<int, int>;
int n, q;
vector<int> a, b;
vector<query> qu, memo[2];
SegmentTree<int> seg[2];

int main() {
  cin >> n;
  a.resize(n);
  for (auto &p : a) cin >> p;
  b.resize(n);
  for (auto &p : b) cin >> p;
  cin >> q;
  qu.resize(q);
  for (auto &p : qu) cin >> p.x >> p.y >> p.z;
  auto f = [](int l, int r) { return min(l, r); };
  seg[1] = SegmentTree<int>(a, f, 2e9);
  seg[0] = SegmentTree<int>(b, f, 2e9);
  bool copied = 0;
  for (auto [x, y, z] : qu) {
    if (x <= 2) {
      int now = seg[x & 1].query(--y, z);
      memo[x & 1].emplace_back(y, now, z);
      seg[x & 1].update(y, z);
    } else if (x <= 4)
      cout << seg[x & 1].query(--y, z) << endl;
    else {
      if (!copied)
        seg[x & 1] = seg[(x & 1) ^ 1];
      else {
        while (memo[x & 1].size()) {
          auto [id, bf, af] = memo[x & 1].back();
          seg[x & 1].update(id, bf);
          memo[x & 1].pop_back();
        }
        int len = memo[(x & 1) ^ 1].size();
        for (int j = 0; j < len; ++j) {
          auto [id, bf, af] = memo[(x & 1) ^ 1][j];
          seg[(x & 1) ^ 1].update(id, af);
        }
      }
      copied = 1;
      memo[0].clear();
      memo[1].clear();
    }
  }
  return 0;
}
accuracy: 0.125
time_ms: 130
memory_kb: 10900
final_rank: 16

code_snippet: //四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(i) sort(i.begin(),i.end())
#define rSORT(i) sort(i.rbegin(),i.rend())
#define fSORT(i,a) sort(i.begin(),i.end(),a)
#define all(i) i.begin(),i.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n; cin >> n;
    int sq = sqrt(n);
    VI a(n), c(n); cin >> a >> c;
    VI b((n + sq - 1) / sq), d((n + sq - 1) / sq), e((n + sq - 1) / sq);
    //e 0:どちらもコピーされていない 1:Aがコピー元 2:Bがコピー元

    {
        int s = INF, t = INF;
        FOR(i, 0, n) {
            chmin(s, a[i]), chmin(t, c[i]);
            if (i == n - 1 || (i + 1) % sq == 0) {
                b[i / sq] = s, d[i / sq] = t;
                s = t = INF;
            }
        }
    }

    //type 1:Aをコピーする 2:Bをコピーする
    function<void(int, int)> Trans = [&](int type, int num)->void {
        VI *w = &a, *x = &b, *y = &c, *z = &d;
        if (type == 1)swap(w, y), swap(x, z);
        x->at(num) = z->at(num);
        for (int i = sq * num, m = min(n, sq * (num + 1)); i < m; ++i) {
            w->at(i) = y->at(i);
        }
    };
    function<void(int, int, int, int)> Assign = [&](int type, int idx, int num, int val)->void {
        VI *w = (type == 1 ? &a : &c), *x = (type == 1 ? &b : &d);
        w->at(idx) = val;
        int res = INF;
        for (int i = num * sq, m = min((num + 1) * sq, n); i < m; ++i) {
            chmin(res, w->at(i));
        }
        x->at(num) = res;
    };

    int q; cin >> q;
    while (q--) {
        int x, y, z; cin >> x >> y >> z;
        if (x <= 2) {
            --y;
            int num = y / sq;
            if (e[num] != 0) {
                Trans(e[num], num);
                e[num] = 0;
            }
            Assign(x, y, num, z);
        }
        else if (5 <= x) {
            each(i, e)if (i == 0)i = 7 - x;
        }
        else {
            --y;
            int res = INF;
            for (int i = y; i < z;) {
                int num = i / sq, k;
                if (x == 3) {
                    if (e[num] == 2)k = 2;
                    else k = 1;
                }
                else {
                    if (e[num] == 1)k = 1;
                    else k = 2;
                }

                if (i % sq || z < min(i + sq, n)) {
                    chmin(res, (k == 1 ? a[i] : c[i]));
                    ++i;
                }
                else {
                    chmin(res, (k == 1 ? b[num] : d[num]));
                    i += sq;
                }
            }
            print(res);
        }
    }

    return 0;
}
accuracy: 1
time_ms: 420
memory_kb: 4272
final_rank: 8

code_snippet: //四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(i) sort(i.begin(),i.end())
#define rSORT(i) sort(i.rbegin(),i.rend())
#define fSORT(i,a) sort(i.begin(),i.end(),a)
#define all(i) i.begin(),i.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n; cin >> n;
    int sq = sqrt(n);
    VI a(n), c(n); cin >> a >> c;
    VI b((n + sq - 1) / sq), d((n + sq - 1) / sq), e((n + sq - 1) / sq);
    //e 0:どちらもコピーされていない 1:Aがコピー元 2:Bがコピー元

    {
        int s = INF, t = INF;
        FOR(i, 0, n) {
            chmin(s, a[i]), chmin(t, c[i]);
            if (i == n - 1 || (i + 1) % sq == 0) {
                b[i / sq] = s, d[i / sq] = t;
                s = t = INF;
            }
        }
    }

    //type 1:Aをコピーする 2:Bをコピーする
    function<void(int, int)> Trans = [&](int type, int num)->void {
        VI *w = &a, *x = &b, *y = &c, *z = &d;
        if (type == 1)swap(w, y), swap(x, z);
        x->at(num) = z->at(num);
        for (int i = sq * num, m = min(n, sq * (num + 1)); i < m; ++i) {
            w->at(i) = y->at(i);
        }
    };
    function<void(int, int, int, int)> Assign = [&](int type, int idx, int num, int val)->void {
        VI *w = (type == 1 ? &a : &c), *x = (type == 1 ? &b : &d);
        w->at(idx) = val;
        int res = INF;
        for (int i = num * sq, m = (num + 1) * sq; i < m; ++i) {
            chmin(res, w->at(i));
        }
        x->at(num) = res;
    };

    int q; cin >> q;
    while (q--) {
        int x, y, z; cin >> x >> y >> z;
        if (x <= 2) {
            --y;
            int num = y / sq;
            if (e[num] != 0) {
                Trans(e[num], num);
                e[num] = 0;
            }
            Assign(x, y, num, z);
        }
        else if (5 <= x) {
            each(i, e)if (i == 0)i = 7 - x;
        }
        else {
            --y;
            int res = INF;
            for (int i = y; i < z;) {
                int num = i / sq, k;
                if (x == 3) {
                    if (e[num] == 2)k = 2;
                    else k = 1;
                }
                else {
                    if (e[num] == 1)k = 1;
                    else k = 2;
                }

                if (i % sq || z < min(i + sq, n)) {
                    chmin(res, (k == 1 ? a[i] : c[i]));
                    ++i;
                }
                else {
                    chmin(res, (k == 1 ? b[num] : d[num]));
                    i += sq;
                }
            }
            print(res);
        }
    }

    return 0;
}
accuracy: 0.125
time_ms: 90
memory_kb: 4224
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  F f;
  T ti;
  SegmentTree(F f,T ti):f(f),ti(ti){}

  struct Node{
    Node *l,*r;
    T dat;
    Node(T dat):dat(dat){l=r=nullptr;}
  };

  Node* clone(Node *a){
    return new Node(*a);
  }

  Node* reflect(Node *a){
    a->dat=f(a->l->dat,a->r->dat);
    return a;
  }

  int n,height;
  Node* build(const vector<T> &v){
    int n_=v.size();
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    vector<Node*> vs(n<<1);
    for(int i=0;i<n_;i++) vs[n+i]=new Node(v[i]);
    for(int i=n_;i<n;i++) vs[n+i]=new Node(ti);
    for(int i=n-1;i;i--){
      vs[i]=new Node(ti);
      vs[i]->l=vs[(i<<1)|0];
      vs[i]->r=vs[(i<<1)|1];
      reflect(vs[i]);
    }
    return vs[1];
  }

  Node* set_val(Node* t,int k,T x,int h){
    t=clone(t);
    if(h<0){
      t->dat=x;
      return t;
    }
    if((k>>h)&1) t->r=set_val(t->r,k,x,h-1);
    else t->l=set_val(t->l,k,x,h-1);
    return reflect(t);
  }

  T query(Node* t,int l,int r,int lb,int ub){
    if(r<=lb||ub<=l) return ti;
    if(l<=lb&&ub<=r) return t->dat;
    int m=(lb+ub)>>1;
    return f(query(t->l,l,r,lb,m),query(t->r,l,r,m,ub));
  }

  Node* set_val(Node* t,int k,T x){
    return set_val(t,k,x,height-1);
  }

  T query(Node* t,int l,int r){
    return query(t,l,r,0,n);
  }
};
//END CUT HERE
//INSERT ABOVE HERE
signed HAPPYQUERY_B(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n;
  cin>>n;
  vector<int> as(n);
  for(int i=0;i<n;i++) cin>>as[i];

  auto f=[](int a,int b){return min(a,b);};
  int ti=INT_MAX;
  SegmentTree<int> seg(f,ti);
  auto rt=seg.build(as);

  vector<decltype(rt)> rts;
  rts.emplace_back(rt);

  int q1;
  cin>>q1;
  rts.reserve(q1+1);

  for(int i=0;i<q1;i++){
    int p,x;
    cin>>p>>x;
    p--;
    rt=seg.set_val(rt,p,x);
    rts.emplace_back(rt);
  }

  int q2;
  cin>>q2;
  int x=0;
  for(int i=0;i<q2;i++){
    int a,b,c;
    cin>>a>>b>>c;
    int k=a^x;
    int l=(b^x)-1;
    int r=(c^x);
    assert(l<r);
    x=seg.query(rts[k],l,r);
    cout<<x<<"\n";
  }
  cout<<flush;
  return 0;
}
/*
  verified on 2019/06/22
  https://www.hackerrank.com/contests/happy-query-contest/challenges/minimum-history-query
*/

signed AOJ_3024(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n;
  cin>>n;
  vector<int> as(n),bs(n);
  for(int i=0;i<n;i++) cin>>as[i];
  for(int i=0;i<n;i++) cin>>bs[i];

  auto f=[](int a,int b){return min(a,b);};
  int ti=INT_MAX;
  SegmentTree<int> seg(f,ti);
  auto ra=seg.build(as);
  auto rb=seg.build(bs);

  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int x,y,z;
    cin>>x>>y>>z;
    y--;
    if(x==1) ra=seg.set_val(ra,y,z);
    if(x==2) rb=seg.set_val(rb,y,z);
    if(x==3) cout<<seg.query(ra,y,z)<<"\n";
    if(x==4) cout<<seg.query(rb,y,z)<<"\n";
    if(x==5) ra=seg.clone(rb);
    if(x==6) rb=seg.clone(ra);
  }
  cout<<flush;
  return 0;
}

signed main(){
  //HAPPYQUERY_B();
  AOJ_3024();
  return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 91532
final_rank: 10

code_snippet: #include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

#define MAX_NODE 8000000
struct AVL {
	struct Node {
		Node *l;
		Node *r;
		int val;
		int min;
		int height;
		int size;
		Node *fetch() {
			min = std::min({val, l->min, r->min});
			height = 1 + std::max(l->height, r->height);
			size = 1 + l->size + r->size;
			return this;
		}
		Node *rotate_l() {
			Node *new_root = AVL::new_node(r);
			r = new_root->l;
			new_root->l = this;
			fetch();
			new_root->fetch();
			return new_root;
		}
		Node *rotate_r() {
			Node *new_root = AVL::new_node(l);
			l = new_root->r;
			new_root->r = this;
			fetch();
			new_root->fetch();
			return new_root;
		}
		int height_diff() {
			return l->height - r->height;
		}
		Node *balance() {
			int dif = height_diff();
			if (dif == 2) {
				if (l->height_diff() < 0) l = new_node(l)->rotate_l();
				return rotate_r();
			} else if (dif == -2) {
				if (r->height_diff() > 0) r = new_node(r)->rotate_r();
				return rotate_l();
			} else return fetch();
		}
	};
	static Node buf[MAX_NODE];
	static int head;
	static Node *NONE;
	Node *root = NONE;
	AVL() {
		if (!head) buf[head++] = {NONE, NONE, 0, 1000000000, 0, 0};
	}
	static Node *new_node(Node *node) {
		if (node == NONE) return node;
		buf[head] = *node;
		return &buf[head++];
	}
	Node *push_back(Node *node, int val) {
		if (node == NONE) {
			buf[head] = {NONE, NONE, val, val, 1, 1};
			return &buf[head++];
		}
		node = new_node(node);
		node->r = push_back(node->r, val);
		return node->balance();
	}
	Node *assign(Node *node, int index, int val) {
		node = new_node(node);
		int lsize = node->l->size;
		if (index < lsize) node->l = assign(node->l, index, val);
		else if (index > lsize) node->r = assign(node->r, index - lsize - 1, val);
		else node->val = val;
		return node->balance();
	}
	int min(Node *node, int l, int r) {
		if (l <= 0 && r >= node->size) return node->min;
		int lsize = node->l->size;
		int res = 1000000000;
		if (l <= lsize && r > lsize) res = node->val;
		if (l < lsize && node->l != NONE) res = std::min(res, min(node->l, l, r));
		if (r > lsize + 1 && node->r != NONE) res = std::min(res, min(node->r, l - lsize - 1, r - lsize - 1));
		return res;
	}
	void dump(Node *node, std::vector<int> &res) {
		if (node->l != NONE) dump(node->l, res);
		res.push_back(node->val);
		if (node->r != NONE) dump(node->r, res);
	}
	std::vector<int> dump() {
		std::vector<int> res;
		dump(root, res);
		return res;
	}
	void push_back(int val) {
		root = push_back(root, val);
	}
	void assign(int index, int val) {
		root = assign(root, index, val);
	}
	int min(int l, int r) {
		return min(root, l, r);
	}
};
AVL::Node AVL::buf[MAX_NODE];
int AVL::head = 0;
AVL::Node *AVL::NONE = AVL::buf;

int main() {
	int n = ri();
	AVL a, b;
	for (int i = 0; i < n; i++) a.push_back(ri());
	for (int i = 0; i < n; i++) b.push_back(ri());
	int q = ri();
	for (int i = 0; i < q; i++) {
		int t = ri();
		int y = ri();
		int z = ri();
		if (t == 1) a.assign(y - 1, z);
		else if (t == 2) b.assign(y - 1, z);
		else if (t == 3) printf("%d\n", a.min(y - 1, z));
		else if (t == 4) printf("%d\n", b.min(y - 1, z));
		else if (t == 5) a.root = b.root;
		else if (t == 6) b.root = a.root;
		if (i % 15000 == 0) {
			std::vector<int> a_ = a.dump(), b_ = b.dump();
			AVL::head = 1;
			a.root = AVL::NONE;
			b.root = AVL::NONE;
			for (auto i : a_) a.push_back(i);
			for (auto i : b_) b.push_back(i);
		}
	}
	return 0;
}
accuracy: 1
time_ms: 1180
memory_kb: 242840
final_rank: 12

code_snippet: #include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

#define MAX_NODE 8000000
struct AVL {
	struct Node {
		Node *l;
		Node *r;
		int val;
		int min;
		int height;
		int size;
		Node *fetch() {
			min = std::min({val, l->min, r->min});
			height = 1 + std::max(l->height, r->height);
			size = 1 + l->size + r->size;
			return this;
		}
		Node *rotate_l() {
			Node *new_root = AVL::new_node(r);
			r = new_root->l;
			new_root->l = this;
			fetch();
			new_root->fetch();
			return new_root;
		}
		Node *rotate_r() {
			Node *new_root = AVL::new_node(l);
			l = new_root->r;
			new_root->r = this;
			fetch();
			new_root->fetch();
			return new_root;
		}
		int height_diff() {
			return l->height - r->height;
		}
		Node *balance() {
			int dif = height_diff();
			if (dif == 2) {
				if (l->height_diff() < 0) l = new_node(l)->rotate_l();
				return rotate_r();
			} else if (dif == -2) {
				if (r->height_diff() > 0) r = new_node(r)->rotate_r();
				return rotate_l();
			} else return fetch();
		}
	};
	static Node buf[MAX_NODE];
	static int head;
	static Node *NONE;
	Node *root = NONE;
	AVL() {
		if (!head) buf[head++] = {NONE, NONE, 0, 1000000000, 0, 0};
	}
	static Node *new_node(Node *node) {
		if (node == NONE) return node;
		buf[head] = *node;
		return &buf[head++];
	}
	Node *push_back(Node *node, int val) {
		if (node == NONE) {
			buf[head] = {NONE, NONE, val, val, 1, 1};
			return &buf[head++];
		}
		node = new_node(node);
		node->r = push_back(node->r, val);
		return node->balance();
	}
	Node *assign(Node *node, int index, int val) {
		node = new_node(node);
		int lsize = node->l->size;
		if (index < lsize) node->l = assign(node->l, index, val);
		else if (index > lsize) node->r = assign(node->r, index - lsize - 1, val);
		else node->val = val;
		return node->balance();
	}
	int min(Node *node, int l, int r) {
		if (l <= 0 && r >= node->size) return node->min;
		int lsize = node->l->size;
		int res = 1000000000;
		if (l <= lsize && r > lsize) res = node->val;
		if (l < lsize && node->l != NONE) res = std::min(res, min(node->l, l, r));
		if (r > lsize + 1 && node->r != NONE) res = std::min(res, min(node->r, l - lsize - 1, r - lsize - 1));
		return res;
	}
	void dump(Node *node, std::vector<int> &res) {
		if (node->l != NONE) dump(node->l, res);
		res.push_back(node->val);
		if (node->r != NONE) dump(node->r, res);
	}
	std::vector<int> dump() {
		std::vector<int> res;
		dump(root, res);
		return res;
	}
	void push_back(int val) {
		root = push_back(root, val);
	}
	void assign(int index, int val) {
		root = assign(root, index, val);
	}
	int min(int l, int r) {
		return min(root, l, r);
	}
};
AVL::Node AVL::buf[MAX_NODE];
int AVL::head = 0;
AVL::Node *AVL::NONE = AVL::buf;

int main() {
	int n = ri();
	AVL a, b;
	for (int i = 0; i < n; i++) a.push_back(ri());
	for (int i = 0; i < n; i++) b.push_back(ri());
	int q = ri();
	for (int i = 0; i < q; i++) {
		int t = ri();
		int y = ri();
		int z = ri();
		if (t == 1) a.assign(y - 1, z);
		else if (t == 2) b.assign(y - 1, z);
		else if (t == 3) printf("%d\n", a.min(y - 1, z));
		else if (t == 4) printf("%d\n", b.min(y - 1, z));
		else if (t == 5) a.root = b.root;
		else if (t == 6) b.root = a.root;
		if (i % 8000 == 0) {
			std::vector<int> a_ = a.dump(), b_ = b.dump();
			AVL::head = 1;
			a.root = AVL::NONE;
			b.root = AVL::NONE;
			for (auto i : a_) a.push_back(i);
			for (auto i : b_) b.push_back(i);
		}
	}
	return 0;
}
accuracy: 1
time_ms: 1900
memory_kb: 241076
final_rank: 13

code_snippet: #include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

#define MAX_NODE 8000000
struct AVL {
	struct Node {
		Node *l;
		Node *r;
		int val;
		int min;
		int height;
		int size;
		Node *fetch() {
			min = std::min({val, l->min, r->min});
			height = 1 + std::max(l->height, r->height);
			size = 1 + l->size + r->size;
			return this;
		}
		Node *rotate_l() {
			Node *new_root = AVL::new_node(r);
			r = new_root->l;
			new_root->l = this;
			fetch();
			new_root->fetch();
			return new_root;
		}
		Node *rotate_r() {
			Node *new_root = AVL::new_node(l);
			l = new_root->r;
			new_root->r = this;
			fetch();
			new_root->fetch();
			return new_root;
		}
		int height_diff() {
			return l->height - r->height;
		}
		Node *balance() {
			int dif = height_diff();
			if (dif == 2) {
				if (l->height_diff() < 0) l = new_node(l)->rotate_l();
				return rotate_r();
			} else if (dif == -2) {
				if (r->height_diff() > 0) r = new_node(r)->rotate_r();
				return rotate_l();
			} else return fetch();
		}
	};
	static Node buf[MAX_NODE];
	static int head;
	static Node *NONE;
	Node *root = NONE;
	AVL() {
		if (!head) buf[head++] = {NONE, NONE, 0, 1000000000, 0, 0};
	}
	static Node *new_node(Node *node) {
		if (node == NONE) return node;
		buf[head] = *node;
		return &buf[head++];
	}
	Node *push_back(Node *node, int val) {
		if (node == NONE) {
			buf[head] = {NONE, NONE, val, val, 1, 1};
			return &buf[head++];
		}
		node = new_node(node);
		node->r = push_back(node->r, val);
		return node->balance();
	}
	Node *assign(Node *node, int index, int val) {
		node = new_node(node);
		int lsize = node->l->size;
		if (index < lsize) node->l = assign(node->l, index, val);
		else if (index > lsize) node->r = assign(node->r, index - lsize - 1, val);
		else node->val = val;
		return node->balance();
	}
	int min(Node *node, int l, int r) {
		if (l <= 0 && r >= node->size) return node->min;
		int lsize = node->l->size;
		int res = 1000000000;
		if (l <= lsize && r > lsize) res = node->val;
		if (l < lsize && node->l != NONE) res = std::min(res, min(node->l, l, r));
		if (r > lsize + 1 && node->r != NONE) res = std::min(res, min(node->r, l - lsize - 1, r - lsize - 1));
		return res;
	}
	void push_back(int val) {
		root = push_back(root, val);
	}
	void assign(int index, int val) {
		root = assign(root, index, val);
	}
	int min(int l, int r) {
		return min(root, l, r);
	}
};
AVL::Node AVL::buf[MAX_NODE];
int AVL::head = 0;
AVL::Node *AVL::NONE = AVL::buf;

int main() {
	int n = ri();
	AVL a, b;
	for (int i = 0; i < n; i++) a.push_back(ri());
	for (int i = 0; i < n; i++) b.push_back(ri());
	int q = ri();
	for (int i = 0; i < q; i++) {
		int t = ri();
		int y = ri();
		int z = ri();
		if (t == 1) a.assign(y - 1, z);
		else if (t == 2) b.assign(y - 1, z);
		else if (t == 3) printf("%d\n", a.min(y - 1, z));
		else if (t == 4) printf("%d\n", b.min(y - 1, z));
		else if (t == 5) a.root = b.root;
		else if (t == 6) b.root = a.root;
	}
	return 0;
}
accuracy: 0.125
time_ms: 140
memory_kb: 236752
final_rank: 20

code_snippet: #include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
class PersistentMinSegTree;
class MinSegBranch;
using seg = std::shared_ptr<PersistentMinSegTree>;

class PersistentMinSegTree {
public:
	virtual bool is_defined_at(const int position) const = 0;
	virtual int min_of_all() const = 0;
	virtual int min_of(const int from, const int to) const = 0;
	virtual seg updated(const int position, const int new_value) = 0;
};
class MinSegBranch : public PersistentMinSegTree {
	seg left, right;
	int from, to, min_cache;
public:
	MinSegBranch(int _from, int _to, const seg& _left, const seg& _right) : left{ _left }, right{ _right }, from{ _from }, to{ _to }, min_cache{ std::min(_left->min_of_all(), _right->min_of_all()) }{};
	bool is_defined_at(const int position) const override { return from <= position && position <= to; }
	int min_of_all() const override { return min_cache; }
	int min_of(const int from, const int to) const override {
		if (from <= this->from && this->to <= to) {
			return min_cache;
		}
		else if (this->from <= to && from <= this->to) {
			return std::min(left->min_of(from, to), right->min_of(from, to));
		}
		else {
			return INT_MAX;
		}
	}
	seg updated(const int position, const int new_value) override {
		if (left->is_defined_at(position)) return std::make_shared<MinSegBranch>(from, to, left->updated(position, new_value), right);
		if (right->is_defined_at(position)) return std::make_shared<MinSegBranch>(from, to, left, right->updated(position, new_value));
		throw 0;
	}
};
class MinSegLeaf : public PersistentMinSegTree {
	int position, value;
public:
	MinSegLeaf(const int _position, const int _value) : position{ _position }, value{ _value }{};
	bool is_defined_at(const int position) const override { return position == this->position; }
	int min_of_all() const override { return value; }
	int min_of(const int from, const int to) const override { return (from <= position && position <= to) ? value : INT_MAX; }
	seg updated(const int position, const int new_value) override {
		return (position == this->position) ? std::make_shared<MinSegLeaf>(position, new_value) : throw 0;
	}
};


class MinSegmentTree {
	seg root;
	static seg make(const std::vector<int>& array, const int from, const int until) {
		return (until - from == 1) ? std::shared_ptr<PersistentMinSegTree>(new MinSegLeaf(from, array[from])) : std::make_shared<MinSegBranch>(from, until - 1, make(array, from, (from + until) / 2), make(array, (from + until) / 2, until));
	}
	MinSegmentTree(seg _root) :root{ _root } {};
public:
	void copy_from(const MinSegmentTree& tree) {
		root = tree.root;
	}
	static MinSegmentTree make(const std::vector<int>& array) {
		return MinSegmentTree(make(array, 0, array.size()));
	}
	void update(int position, int new_value) {
		root = root->updated(position, new_value);
	}
	int min_of(int from, int to) const {
		return root->min_of(from, to);
	}
};
int main() {
	std::cin.tie(0); std::cin.sync_with_stdio(false);
	int n; std::cin >> n;
	std::vector<int> a(n), b(n); for (auto& i : a) std::cin >> i; for (auto& i : b) std::cin >> i;
	auto seg_a = MinSegmentTree::make(a);
	auto seg_b = MinSegmentTree::make(b);
	int q; std::cin >> q;
	for (auto _i = 0; _i < q; ++_i) {
		int x, y, z; std::cin >> x >> y >> z;
		switch (x) {
		case 1: seg_a.update(y - 1, z); break;
		case 2: seg_b.update(y - 1, z); break;
		case 3: std::cout << seg_a.min_of(y - 1, z - 1) << '\n'; break;
		case 4: std::cout << seg_b.min_of(y - 1, z - 1) << '\n'; break;
		case 5: seg_a.copy_from(seg_b); break;
		case 6: seg_b.copy_from(seg_a); break;
		default: throw 0;
		}
	}
}
accuracy: 1
time_ms: 360
memory_kb: 60952
final_rank: 9

code_snippet: #include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
using namespace std;

template<typename Monoid>
struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;
    const F f;
    const Monoid M1;
    int sz;
    vector<Monoid> dat;
    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1), sz(1) {
        while (sz < n) sz <<= 1;
        dat.assign(sz * 2, M1);
    }
    void set(int k, const Monoid &x) { dat[k + sz] = x; }
    void build() {
        for (int k = sz - 1; k > 0; k--) {
            dat[k] = f(dat[2 * k], dat[2 * k + 1]);
        }
    }
    void update(int k, const Monoid &x) {
        dat[k += sz] = x;
        while (k >>= 1) dat[k] = f(dat[2 * k], dat[2 * k + 1]);
    }
    Monoid get(int a, int b) {  // [a, b)
        Monoid L = M1, R = M1;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if (a & 1) L = f(L, dat[a++]);
            if (b & 1) R = f(dat[--b], R);
        }
        return f(L, R);
    }
    Monoid operator[](const int &k) const { return dat[k + sz]; }
    friend ostream& operator<<(ostream& os, SegmentTree<Monoid> &seg) {
        for (int i = 0; i < seg.sz; i++) os << seg[i] << " ";
        return os;
    }
};

const int INF = numeric_limits<int>::max();
int main() {
    int n; cin >> n;
    SegmentTree<int> seg1(n, [](int a, int b) { return min(a, b); }, INF);
    SegmentTree<int> seg2(n, [](int a, int b) { return min(a, b); }, INF);
    for (int i = 0; i < n; i++) { int a; cin >> a; seg1.set(i, a); }
    for (int i = 0; i < n; i++) { int b; cin >> b; seg2.set(i, b); }
    seg1.build();
    seg2.build();
    int q; cin >> q;
    vector<pair<int, int>> a_his, a_upd, b_his, b_upd;
    bool init = true;
    #define eb emplace_back
    while (q--) {
        int x, y, z; cin >> x >> y >> z; y--;
        if (x == 1) a_his.eb(y, seg1[y]), seg1.update(y, z), a_upd.eb(y, z);
        if (x == 2) b_his.eb(y, seg2[y]), seg2.update(y, z), b_upd.eb(y, z);
        if (x == 3) cout << seg1.get(y, z) << endl;
        if (x == 4) cout << seg2.get(y, z) << endl;
        if (x == 5) {
            if (init) {
                for (int i = 0; i < n; i++) seg1.update(i, seg2[i]);
                init = false;
            } else {
                reverse(a_his.begin(), a_his.end());
                for (auto &p: a_his) seg1.update(p.first, p.second);
                for (auto &p: b_upd) seg1.update(p.first, p.second);
            }
            a_his.clear(), a_upd.clear(), b_his.clear(), b_upd.clear();
        }
        if (x == 6) {
            if (init) {
                for (int i = 0; i < n; i++) seg2.update(i, seg1[i]);
                init = false;
            } else {
                reverse(b_his.begin(), b_his.end());
                for (auto &p: b_his) seg2.update(p.first, p.second);
                for (auto &p: a_upd) seg2.update(p.first, p.second);
            }
            a_his.clear(), a_upd.clear(), b_his.clear(), b_upd.clear();
        }
    }
    return 0;
}
accuracy: 1
time_ms: 320
memory_kb: 7060
final_rank: 7

code_snippet: #include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
using namespace std;

template<typename Monoid>
struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;
    const F f;
    const Monoid M1;
    int sz;
    vector<Monoid> dat;
    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1), sz(1) {
        while (sz < n) sz <<= 1;
        dat.assign(sz * 2, M1);
    }
    void set(int k, const Monoid &x) { dat[k + sz] = x; }
    void build() {
        for (int k = sz - 1; k > 0; k--) {
            dat[k] = f(dat[2 * k], dat[2 * k + 1]);
        }
    }
    void update(int k, const Monoid &x) {
        dat[k += sz] = x;
        while (k >>= 1) dat[k] = f(dat[2 * k], dat[2 * k + 1]);
    }
    Monoid get(int a, int b) {  // [a, b)
        Monoid L = M1, R = M1;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if (a & 1) L = f(L, dat[a++]);
            if (b & 1) R = f(dat[--b], R);
        }
        return f(L, R);
    }
    Monoid operator[](const int &k) const { return dat[k + sz]; }
    friend ostream& operator<<(ostream& os, SegmentTree<Monoid> &seg) {
        for (int i = 0; i < seg.sz; i++) os << seg[i] << " ";
        return os;
    }
};

const int INF = numeric_limits<int>::max();
int main() {
    int n; cin >> n;
    SegmentTree<int> seg1(n, [](int a, int b) { return min(a, b); }, INF);
    SegmentTree<int> seg2(n, [](int a, int b) { return min(a, b); }, INF);
    for (int i = 0; i < n; i++) { int a; cin >> a; seg1.set(i, a); }
    for (int i = 0; i < n; i++) { int b; cin >> b; seg2.set(i, b); }
    int q; cin >> q;
    vector<pair<int, int>> a_his, a_upd, b_his, b_upd;
    bool init = true;
    #define eb emplace_back
    while (q--) {
        int x, y, z; cin >> x >> y >> z; y--;
        if (x == 1) a_his.eb(y, seg1[y]), seg1.update(y, z), a_upd.eb(y, z);
        if (x == 2) b_his.eb(y, seg2[y]), seg2.update(y, z), b_upd.eb(y, z);
        if (x == 3) cout << seg1.get(y, z) << endl;
        if (x == 4) cout << seg2.get(y, z) << endl;
        if (x == 5) {
            if (init) {
                for (int i = 0; i < n; i++) seg1.update(i, seg2[i]);
                init = false;
            } else {
                reverse(a_his.begin(), a_his.end());
                for (auto &p: a_his) seg1.update(p.first, p.second);
                for (auto &p: b_upd) seg1.update(p.first, p.second);
            }
            a_his.clear(), a_upd.clear(), b_his.clear(), b_upd.clear();
        }
        if (x == 6) {
            if (init) {
                for (int i = 0; i < n; i++) seg2.update(i, seg1[i]);
                init = false;
            } else {
                reverse(b_his.begin(), b_his.end());
                for (auto &p: b_his) seg2.update(p.first, p.second);
                for (auto &p: a_upd) seg2.update(p.first, p.second);
            }
            a_his.clear(), a_upd.clear(), b_his.clear(), b_upd.clear();
        }
    }
    return 0;
}
accuracy: 0.125
time_ms: 260
memory_kb: 7060
final_rank: 19

code_snippet: #include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
using namespace std;

template<typename Monoid>
struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;
    const F f;
    const Monoid M1;
    int sz;
    vector<Monoid> dat;
    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1), sz(1) {
        while (sz < n) sz <<= 1;
        dat.assign(sz * 2, M1);
    }
    void set(int k, const Monoid &x) { dat[k + sz] = x; }
    void build() {
        for (int k = sz - 1; k > 0; k--) {
            dat[k] = f(dat[2 * k], dat[2 * k + 1]);
        }
    }
    void update(int k, const Monoid &x) {
        dat[k += sz] = x;
        while (k >>= 1) dat[k] = f(dat[2 * k], dat[2 * k + 1]);
    }
    Monoid get(int a, int b) {  // [a, b)
        Monoid L = M1, R = M1;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if (a & 1) L = f(L, dat[a++]);
            if (b & 1) R = f(dat[--b], R);
        }
        return f(L, R);
    }
    Monoid operator[](const int &k) const { return dat[k + sz]; }
    friend ostream& operator<<(ostream& os, SegmentTree<Monoid> &seg) {
        for (int i = 0; i < seg.sz; i++) os << seg[i] << " ";
        return os;
    }
};

const int INF = numeric_limits<int>::max();
int main() {
    int n; cin >> n;
    SegmentTree<int> seg1(n, [](int a, int b) { return min(a, b); }, INF);
    SegmentTree<int> seg2(n, [](int a, int b) { return min(a, b); }, INF);
    for (int i = 0; i < n; i++) { int a; cin >> a; seg1.set(i, a); }
    for (int i = 0; i < n; i++) { int b; cin >> b; seg2.set(i, b); }
    int q; cin >> q;
    vector<pair<int, int>> a_his, a_upd, b_his, b_upd;
    bool init = true;
    #define eb emplace_back
    while (q--) {
        int x, y, z; cin >> x >> y >> z; y--;
        if (x == 1) a_his.eb(y, seg1[y]), seg1.update(y, z), a_upd.eb(y, z);
        if (x == 2) b_his.eb(y, seg2[y]), seg2.update(y, z), b_upd.eb(y, z);
        if (x == 3) cout << seg1.get(y, z) << endl;
        if (x == 4) cout << seg2.get(y, z) << endl;
        if (x == 5) {
            if (init) {
                for (int i = 0; i < n; i++) seg1.update(i, seg2[i]);
                init = false;
                continue;
            }
            reverse(a_his.begin(), a_his.end());
            for (auto &p: a_his) seg1.update(p.first, p.second);
            for (auto &p: b_upd) seg1.update(p.first, p.second);
            a_his.clear(), a_upd.clear(), b_his.clear(), b_upd.clear();
        }
        if (x == 6) {
            if (init) {
                for (int i = 0; i < n; i++) seg2.update(i, seg1[i]);
                init = false;
                continue;
            }
            reverse(b_his.begin(), b_his.end());
            for (auto &p: b_his) seg2.update(p.first, p.second);
            for (auto &p: a_upd) seg2.update(p.first, p.second);
            a_his.clear(), a_upd.clear(), b_his.clear(), b_upd.clear();
        }
    }
    return 0;
}
accuracy: 0.125
time_ms: 260
memory_kb: 7000
final_rank: 18

code_snippet: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


struct Node{
    int val;
    Node* lhs, *rhs;
    Node(int val):val(val),lhs(nullptr),rhs(nullptr){}
};

Node* update(Node* t,int l, int r,int k,int x){
    if(k<l||r<=k)return t;
    if(l+1==r){
        Node* ret = new Node(x);
        return ret;
    }
    int mid=(l+r)/2;
    Node* ret = new Node(inf);
    ret->lhs = update(t->lhs,l,mid,k,x);
    ret->rhs = update(t->rhs,mid,r,k,x);
    ret->val = min(ret->lhs->val, ret->rhs->val);
    return ret;
}

int query(Node* t,int a,int b, int l, int r){
    if(b<=l||r<=a)return inf;
    if(a<=l&&r<=b)return t->val;
    int vl = query(t->lhs, a,b,l,(l+r)/2);
    int vr = query(t->rhs, a,b,(l+r)/2, r);
    return min(vl,vr);
}

Node* build(vector<int>& v, int l, int r){
    Node* ret = new Node(inf);
    if(l+1==r){
        ret->val=v[l];
        return ret;
    }
    ret->lhs = build(v,l,(l+r)/2);
    ret->rhs = build(v,(l+r)/2,r);
    ret->val = min(ret->lhs->val, ret->rhs->val);
    return ret;
}
int main(){
    int n;
    cin>>n;
    int m=1;
    while(m<n)m*=2;
    vector<int> a(m,inf), b(m,inf);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    Node* A = build(a,0,m);
    Node* B = build(b,0,m);
    int q;
    cin>>q;
    while(q--){
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        --y;
        if(x==1){
            A = update(A, 0, m, y, z);
        }
        if(x==2){
            B = update(B, 0, m, y, z);
        }
        if(x==5){
            A = B;
        }
        if(x==6){
            B = A;
        }
        if(x==3){
            printf("%d\n",query(A,y,z,0,m));
        }
        if(x==4){
            printf("%d\n",query(B,y,z,0,m));
        }
    }
    return 0;
}
accuracy: 1
time_ms: 290
memory_kb: 91380
final_rank: 11

code_snippet: #define NDEBUG 1
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template <typename T,typename E,typename F,typename G,typename H>
struct SegmentTree{
  //using F = function<T(T,T)>;
  //using G = function<T(T,E)>;
  //using H = function<E(E,E)>;
  int n,height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){init(n_);}
  void init(int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    dat.assign(2*n,ti);
    laz.assign(2*n,ei);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  T reflect(int k){
    return g(dat[k],laz[k]);
  }
  inline void eval(int k){
    if(laz[k]==ei) return;
    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
    dat[k]=reflect(k);
    laz[k]=ei;
  }
  void update(int a,int b,E x){
    a+=n;b+=n-1;
    for(int i=height;i;i--) eval(a>>i);
    for(int i=height;i;i--) eval(b>>i);
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
      if(l&1) laz[l]=h(laz[l],x),l++;
      if(r&1) --r,laz[r]=h(laz[r],x);
    }
    while(a>>=1)
      dat[a]=f(reflect((a<<1)|0),reflect((a<<1)|1));
    while(b>>=1)
      dat[b]=f(reflect((b<<1)|0),reflect((b<<1)|1));
  }
  T query(int a,int b){
    a+=n;b+=n-1;
    for(int i=height;i;i--) eval(a>>i);
    for(int i=height;i;i--) eval(b>>i);
    T vl=ti,vr=ti;
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,reflect(l++));
      if(r&1) vr=f(reflect(--r),vr);
    }
    return f(vl,vr);
  }
  T query(int k){
    k+=n;
    for(int i=height;i;i--) eval(k>>i);
    return reflect(k);
  }
  void update(int k,T x){
    k+=n;
    //for(int i=height;i;i--) eval(k>>i);
    dat[k]=x;
    laz[k]=ei;
    while(k>>=1)
      dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));      
  }
};

//INSERT ABOVE HERE
signed main(){
  int n;
  scanf("%d",&n);
  using P = pair<int,int>;
  vector<P> v(n);
  for(int i=0;i<n;i++) scanf("%d",&v[i].first);
  for(int i=0;i<n;i++) scanf("%d",&v[i].second);
  auto f=[](P a,P b){
	   return P(min(a.first,b.first),
		    min(a.second,b.second));
	 };
  auto g=[](P a,P b){
	   if(b.first<0){
	     if(b.second<0) return a;
	     return P(a.second,a.second);
	   }
	   if(b.second<0)
	     return P(a.first,a.first);
	   if(b.second<b.first)
	     return P(a.second,a.second);
	   return P(a.first,a.first);
	 };
  auto h=[](P a,P b){
	   int x=a.first,y=a.second;
	   if(x<0) x=b.first;
	   if(y<0) y=b.second;
	   return P(x,y);
	 };
  
  SegmentTree<P, P, decltype(f), decltype(g), decltype(h)> rmq(n,f,g,h,P(INT_MAX,INT_MAX),P(-1,-1));
  rmq.build(n,v);
  
  int q;
  scanf("%d",&q);
  for(int i=0;i<q;i++){
    int x,y,z;
    scanf("%d %d %d",&x,&y,&z);
    y--;
    if(x==1){
      assert(0<=y&&y<n);
      P c=rmq.query(y);
      c.first=z;
      rmq.update(y,c);
    }
    if(x==2){
      assert(0<=y&&y<n);
      P c=rmq.query(y);
      c.second=z;
      rmq.update(y,c);
    }
    if(x==3){
      assert(0<=y&&y<z);
      P c=rmq.query(y,z);
      printf("%d\n",c.first);
    }
    if(x==4){
      assert(0<=y&&y<z);
      P c=rmq.query(y,z);
      printf("%d\n",c.second);
    }
    if(x==5){
      rmq.query(0,n);
      rmq.update(0,n,P(-1,i));
    }
    if(x==6){
      rmq.query(0,n);
      rmq.update(0,n,P(i,-1));
    }
  }
  return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 14184
final_rank: 4

code_snippet: #define NDEBUG 1
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template <typename T,typename E,typename F,typename G,typename H>
struct SegmentTree{
  //using F = function<T(T,T)>;
  //using G = function<T(T,E)>;
  //using H = function<E(E,E)>;
  int n,height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){init(n_);}
  void init(int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    dat.assign(2*n,ti);
    laz.assign(2*n,ei);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  T reflect(int k){
    return g(dat[k],laz[k]);
  }
  inline void eval(int k){
    if(laz[k]==ei) return;
    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
    dat[k]=reflect(k);
    laz[k]=ei;
  }
  void update(int a,int b,E x){
    a+=n;b+=n-1;
    for(int i=height;i;i--) eval(a>>i);
    for(int i=height;i;i--) eval(b>>i);
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
      if(l&1) laz[l]=h(laz[l],x),l++;
      if(r&1) --r,laz[r]=h(laz[r],x);
    }
    while(a>>=1)
      dat[a]=f(reflect((a<<1)|0),reflect((a<<1)|1));
    while(b>>=1)
      dat[b]=f(reflect((b<<1)|0),reflect((b<<1)|1));
  }
  T query(int a,int b){
    a+=n;b+=n-1;
    for(int i=height;i;i--) eval(a>>i);
    for(int i=height;i;i--) eval(b>>i);
    T vl=ti,vr=ti;
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,reflect(l++));
      if(r&1) vr=f(reflect(--r),vr);
    }
    return f(vl,vr);
  }
  T query(int k){
    k+=n;
    for(int i=height;i;i--) eval(k>>i);
    return reflect(k);
  }
  void update(int k,T x){
    k+=n;
    for(int i=height;i;i--) eval(k>>i);
    dat[k]=x;
    laz[k]=ei;
    while(k>>=1)
      dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));      
  }
};

//INSERT ABOVE HERE
signed main(){
  int n;
  scanf("%d",&n);
  using P = pair<int,int>;
  vector<P> v(n);
  for(int i=0;i<n;i++) scanf("%d",&v[i].first);
  for(int i=0;i<n;i++) scanf("%d",&v[i].second);
  auto f=[](P a,P b){
	   return P(min(a.first,b.first),
		    min(a.second,b.second));
	 };
  auto g=[](P a,P b){
	   if(b.first<0){
	     if(b.second<0) return a;
	     return P(a.second,a.second);
	   }
	   if(b.second<0)
	     return P(a.first,a.first);
	   if(b.second<b.first)
	     return P(a.second,a.second);
	   return P(a.first,a.first);
	 };
  auto h=[](P a,P b){
	   int x=a.first,y=a.second;
	   if(x<0) x=b.first;
	   if(y<0) y=b.second;
	   return P(x,y);
	 };
  
  SegmentTree<P, P, decltype(f), decltype(g), decltype(h)> rmq(n,f,g,h,P(INT_MAX,INT_MAX),P(-1,-1));
  rmq.build(n,v);
  
  int q;
  scanf("%d",&q);
  for(int i=0;i<q;i++){
    int x,y,z;
    scanf("%d %d %d",&x,&y,&z);
    y--;
    if(x==1){
      assert(0<=y&&y<n);
      P c=rmq.query(y);
      c.first=z;
      rmq.update(y,c);
    }
    if(x==2){
      assert(0<=y&&y<n);
      P c=rmq.query(y);
      c.second=z;
      rmq.update(y,c);
    }
    if(x==3){
      assert(0<=y&&y<z);
      P c=rmq.query(y,z);
      printf("%d\n",c.first);
    }
    if(x==4){
      assert(0<=y&&y<z);
      P c=rmq.query(y,z);
      printf("%d\n",c.second);
    }
    if(x==5){
      rmq.query(0,n);
      rmq.update(0,n,P(-1,i));
    }
    if(x==6){
      rmq.query(0,n);
      rmq.update(0,n,P(i,-1));
    }
  }
  return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 14180
final_rank: 2

code_snippet: #define NDEBUG 1
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template <typename T,typename E,typename F,typename G,typename H>
struct SegmentTree{
  //using F = function<T(T,T)>;
  //using G = function<T(T,E)>;
  //using H = function<E(E,E)>;
  int n,height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){init(n_);}
  void init(int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    dat.assign(2*n,ti);
    laz.assign(2*n,ei);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  T reflect(int k){
    return g(dat[k],laz[k]);
  }
  inline void eval(int k){
    if(laz[k]==ei) return;
    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
    dat[k]=reflect(k);
    laz[k]=ei;
  }
  void update(int a,int b,E x){
    a+=n;b+=n-1;
    for(int i=height;i;i--) eval(a>>i);
    for(int i=height;i;i--) eval(b>>i);
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
      if(l&1) laz[l]=h(laz[l],x),l++;
      if(r&1) --r,laz[r]=h(laz[r],x);
    }
    while(a>>=1)
      dat[a]=f(reflect((a<<1)|0),reflect((a<<1)|1));
    while(b>>=1)
      dat[b]=f(reflect((b<<1)|0),reflect((b<<1)|1));
  }
  T query(int a,int b){
    a+=n;b+=n-1;
    for(int i=height;i;i--) eval(a>>i);
    for(int i=height;i;i--) eval(b>>i);
    T vl=ti,vr=ti;
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,reflect(l++));
      if(r&1) vr=f(reflect(--r),vr);
    }
    return f(vl,vr);
  }
  void update(int k,T x){
    dat[k+=n]=x;
    laz[k]=ei;
    while(k>>=1)
      dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));      
  }
};

//INSERT ABOVE HERE
signed main(){
  int n;
  scanf("%d",&n);
  using P = pair<int,int>;
  vector<P> v(n);
  for(int i=0;i<n;i++) scanf("%d",&v[i].first);
  for(int i=0;i<n;i++) scanf("%d",&v[i].second);
  auto f=[](P a,P b){
	   return P(min(a.first,b.first),
		    min(a.second,b.second));
	 };
  auto g=[](P a,P b){
	   if(b.first<0){
	     if(b.second<0) return a;
	     return P(a.second,a.second);
	   }
	   if(b.second<0)
	     return P(a.first,a.first);
	   if(b.second<b.first)
	     return P(a.second,a.second);
	   return P(a.first,a.first);
	 };
  auto h=[](P a,P b){
	   int x=a.first,y=a.second;
	   if(x<0) x=b.first;
	   if(y<0) y=b.second;
	   return P(x,y);
	 };
  
  SegmentTree<P, P, decltype(f), decltype(g), decltype(h)> rmq(n,f,g,h,P(INT_MAX,INT_MAX),P(-1,-1));
  rmq.build(n,v);
  
  int q;
  scanf("%d",&q);
  for(int i=0;i<q;i++){
    int x,y,z;
    scanf("%d %d %d",&x,&y,&z);
    y--;
    if(x==1){
      assert(0<=y&&y<n);
      P c=rmq.query(y,y+1);
      c.first=z;
      rmq.update(y,c);
    }
    if(x==2){
      assert(0<=y&&y<n);
      P c=rmq.query(y,y+1);
      c.second=z;
      rmq.update(y,c);
    }
    if(x==3){
      assert(0<=y&&y<z);
      P c=rmq.query(y,z);
      printf("%d\n",c.first);
    }
    if(x==4){
      assert(0<=y&&y<z);
      P c=rmq.query(y,z);
      printf("%d\n",c.second);
    }
    if(x==5){
      rmq.query(0,n);
      rmq.update(0,n,P(-1,i));
    }
    if(x==6){
      rmq.query(0,n);
      rmq.update(0,n,P(i,-1));
    }
  }
  return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 14180
final_rank: 2

code_snippet: #define NDEBUG 1
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template <typename T,typename E,typename F,typename G,typename H>
struct SegmentTree{
  //using F = function<T(T,T)>;
  //using G = function<T(T,E)>;
  //using H = function<E(E,E)>;
  int n,height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){init(n_);}
  void init(int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    dat.assign(2*n,ti);
    laz.assign(2*n,ei);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  T reflect(int k){
    return g(dat[k],laz[k]);
  }
  inline void eval(int k){
    if(laz[k]==ei) return;
    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
    dat[k]=reflect(k);
    laz[k]=ei;
  }
  void update(int a,int b,E x){
    a+=n;b+=n-1;
    for(int i=height;i;i--) eval(a>>i);
    for(int i=height;i;i--) eval(b>>i);
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
      if(l&1) laz[l]=h(laz[l],x),l++;
      if(r&1) --r,laz[r]=h(laz[r],x);
    }
    while(a>>=1)
      dat[a]=f(reflect((a<<1)|0),reflect((a<<1)|1));
    while(b>>=1)
      dat[b]=f(reflect((b<<1)|0),reflect((b<<1)|1));
  }
  T query(int a,int b){
    a+=n;b+=n-1;
    for(int i=height;i;i--) eval(a>>i);
    for(int i=height;i;i--) eval(b>>i);
    T vl=ti,vr=ti;
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,reflect(l++));
      if(r&1) vr=f(reflect(--r),vr);
    }
    return f(vl,vr);
  }
  void update(int k,T x){
    eval(k+=n);
    dat[k]=x;    
    while(k>>=1)
      dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));      
  }
};

//INSERT ABOVE HERE
signed main(){
  int n;
  scanf("%d",&n);
  using P = pair<int,int>;
  vector<P> v(n);
  for(int i=0;i<n;i++) scanf("%d",&v[i].first);
  for(int i=0;i<n;i++) scanf("%d",&v[i].second);
  auto f=[](P a,P b){
	   return P(min(a.first,b.first),
		    min(a.second,b.second));
	 };
  auto g=[](P a,P b){
	   if(b.first<0){
	     if(b.second<0) return a;
	     return P(a.second,a.second);
	   }
	   if(b.second<0)
	     return P(a.first,a.first);
	   if(b.second<b.first)
	     return P(a.second,a.second);
	   return P(a.first,a.first);
	 };
  auto h=[](P a,P b){
	   int x=a.first,y=a.second;
	   if(x<0) x=b.first;
	   if(y<0) y=b.second;
	   return P(x,y);
	 };
  
  SegmentTree<P, P, decltype(f), decltype(g), decltype(h)> rmq(n,f,g,h,P(INT_MAX,INT_MAX),P(-1,-1));
  rmq.build(n,v);
  
  int q;
  scanf("%d",&q);
  for(int i=0;i<q;i++){
    int x,y,z;
    scanf("%d %d %d",&x,&y,&z);
    y--;
    if(x==1){
      assert(0<=y&&y<n);
      P c=rmq.query(y,y+1);
      c.first=z;
      rmq.update(y,c);
    }
    if(x==2){
      assert(0<=y&&y<n);
      P c=rmq.query(y,y+1);
      c.second=z;
      rmq.update(y,c);
    }
    if(x==3){
      assert(0<=y&&y<z);
      P c=rmq.query(y,z);
      printf("%d\n",c.first);
    }
    if(x==4){
      assert(0<=y&&y<z);
      P c=rmq.query(y,z);
      printf("%d\n",c.second);
    }
    if(x==5){
      rmq.query(0,n);
      rmq.update(0,n,P(-1,i));
    }
    if(x==6){
      rmq.query(0,n);
      rmq.update(0,n,P(i,-1));
    }
  }
  return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 14184
final_rank: 5