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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


const int POOL_SIZE=10000000;
struct node{
    int v;
    node *l,*r;
    node(){v=0;l=r=NULL;};
}pool[POOL_SIZE];
int uku=0;
node *aloc(){
    assert(uku<POOL_SIZE);
    return &pool[uku++];
}

const int SEG=1<<18;
const int INF=1001001001001001001ll;
int N;
int A[SEG*2];
int B[SEG*2];


node *build(int k,int l,int r,int A[]){
    if(l+1==r){
        node *t=aloc();
        t->v=A[l];
        return t;
    }

    node *x=build(k*2+1,l,(l+r)/2,A);
    node *y=build(k*2+2,(l+r)/2,r,A);

    node *t=aloc();
    t->v=min(x->v,y->v);
    t->l=x;
    t->r=y;

    return t;
}

int getmin(int a,int b,node *t,int l=0,int r=SEG){
    if(r<=a||b<=l)return INF;
    if(a<=l&&r<=b)return t->v;
    return min(getmin(a,b,t->l,l,(l+r)/2),getmin(a,b,t->r,(l+r)/2,r));
}

node *update(int p,int v,node *t,int l=0,int r=SEG){

    if(!(l<=p&&p<r))return t;
    if(l+1==r){
        t=aloc();
        t->v=v;
        return t;
    }

    node *s=aloc();
    s->l=update(p,v,t->l,l,(l+r)/2);
    s->r=update(p,v,t->r,(l+r)/2,r);
    s->v=min(s->l->v,s->r->v);
    return s;
}

signed main(){
    fill_n(A,SEG,INF);
    fill_n(B,SEG,INF);
    scanf("%lld",&N);
    rep(i,N){
        scanf("%lld",&A[i]);
    }
    rep(i,N){
        scanf("%lld",&B[i]);
    }

    node *rootA=build(0,0,SEG,A);
    node *rootB=build(0,0,SEG,B);


    int Q;scanf("%lld",&Q);
    while(Q--){
        int x,y,z;
        scanf("%lld%lld%lld",&x,&y,&z);
        y--;

        if(x==1){
            rootA=update(y,z,rootA);
        }
        if(x==2){
            rootB=update(y,z,rootB);
        }
        if(x==3){
            printf("%lld\n",getmin(y,z,rootA));
        }
        if(x==4){
            printf("%lld\n",getmin(y,z,rootB));
        }
        if(x==5){
            rootA=rootB;
        }
        if(x==6){
            rootB=rootA;
        }


    }
    return 0;
}
### Prompt

Please create a solution in Cpp to the following problem:

Problem

Given two sequences of length $ N $, $ A $ and $ B $. First, the $ i $ item in the sequence $ A $ is $ a_i $, and the $ i $ item in the sequence $ B $ is $ b_i $.

Since a total of $ Q $ of statements of the following format are given, create a program that processes in the given order.

Each statement is represented by three integers $ x, y, z $.

* Set the value of the $ y $ item in the sequence $ A $ to $ z $. (When $ x = 1 $)
* Set the value of the $ y $ item in the sequence $ B $ to $ z $. (When $ x = 2 $)
* Find and report the smallest value in the $ z $ item from the $ y $ item in the sequence $ A $. (When $ x = 3 $)
* Find and report the smallest value in the $ z $ item from the $ y $ item in the sequence $ B $. (When $ x = 4 $)
* Change the sequence $ A $ to be exactly the same as the sequence $ B $. (When $ x = 5 $)
* Change the sequence $ B $ to be exactly the same as the sequence $ A $. (When $ x = 6 $)

Constraints

The input satisfies the following conditions.

* $ 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 $ (when $ 1 \ le x_i \ le 4 $)
* $ y_i = -1 $ (when $ x_i = 5, 6 $)
* $ 1 \ le z_i \ le 10 ^ 9 $ (when $ x_i = 1, 2 $)
* $ y_i \ le z_i \ le N $ (when $ x_i = 3, 4 $)
* $ z_i = -1 $ (when $ x_i = 5, 6 $)
* All inputs are integers

Input

The input is given in the following format.

$ 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 $

Output

Every time a statement of $ x = 3 $ or $ x = 4 $ is given by input, the found value is output on one line.

Example

Input

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


Output

7
2
2
8
1

### Response

```cpp

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


const int POOL_SIZE=10000000;
struct node{
    int v;
    node *l,*r;
    node(){v=0;l=r=NULL;};
}pool[POOL_SIZE];
int uku=0;
node *aloc(){
    assert(uku<POOL_SIZE);
    return &pool[uku++];
}

const int SEG=1<<18;
const int INF=1001001001001001001ll;
int N;
int A[SEG*2];
int B[SEG*2];


node *build(int k,int l,int r,int A[]){
    if(l+1==r){
        node *t=aloc();
        t->v=A[l];
        return t;
    }

    node *x=build(k*2+1,l,(l+r)/2,A);
    node *y=build(k*2+2,(l+r)/2,r,A);

    node *t=aloc();
    t->v=min(x->v,y->v);
    t->l=x;
    t->r=y;

    return t;
}

int getmin(int a,int b,node *t,int l=0,int r=SEG){
    if(r<=a||b<=l)return INF;
    if(a<=l&&r<=b)return t->v;
    return min(getmin(a,b,t->l,l,(l+r)/2),getmin(a,b,t->r,(l+r)/2,r));
}

node *update(int p,int v,node *t,int l=0,int r=SEG){

    if(!(l<=p&&p<r))return t;
    if(l+1==r){
        t=aloc();
        t->v=v;
        return t;
    }

    node *s=aloc();
    s->l=update(p,v,t->l,l,(l+r)/2);
    s->r=update(p,v,t->r,(l+r)/2,r);
    s->v=min(s->l->v,s->r->v);
    return s;
}

signed main(){
    fill_n(A,SEG,INF);
    fill_n(B,SEG,INF);
    scanf("%lld",&N);
    rep(i,N){
        scanf("%lld",&A[i]);
    }
    rep(i,N){
        scanf("%lld",&B[i]);
    }

    node *rootA=build(0,0,SEG,A);
    node *rootB=build(0,0,SEG,B);


    int Q;scanf("%lld",&Q);
    while(Q--){
        int x,y,z;
        scanf("%lld%lld%lld",&x,&y,&z);
        y--;

        if(x==1){
            rootA=update(y,z,rootA);
        }
        if(x==2){
            rootB=update(y,z,rootB);
        }
        if(x==3){
            printf("%lld\n",getmin(y,z,rootA));
        }
        if(x==4){
            printf("%lld\n",getmin(y,z,rootB));
        }
        if(x==5){
            rootA=rootB;
        }
        if(x==6){
            rootB=rootA;
        }


    }
    return 0;
}
```