#include <iostream>
#include <cstring>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

#define INF 1000000001
#define MaxN 65536
#define MaxQ 50000

class SegmentTree {
public:
    vector<int> a[2*MaxN+10];

    SegmentTree() {
        for (int i = 0; i < 2*MaxN+10; ++i)
            a[i].clear();
    }

    void Update( int node, int left, int right, int id, int val ) {
        //printf("Update %d %d %d %d %d\n",node,left,right,id,val);

        if ( id < left || right < id ) return;
        if ( left == right ) {
            a[node].push_back(val);
            return;
        }

        a[node].push_back( val );
        int mid = ( left + right ) >> 1;
        Update( 2*node, left, mid, id, val );
        Update( 2*node+1, mid+1, right, id, val );
    }

    int Query( int node, int left, int right, int queryLeft, int queryRight, int A, int B )
    {
        //printf("Query %d %d %d %d %d %d %d\n",node,left,right,queryLeft,queryRight,A,B);

        if ( queryRight < left || right < queryLeft ) return 0;
        if ( queryLeft <= left && right <= queryRight ) {
            int p1, p2;

            int l,r,mid;
            l = 0;
            r = a[node].size();
            while ( r - l ) {
                mid = ( r + l ) >> 1;
                if ( a[node][mid] < A ) l = mid + 1;
                else                    r = mid;
            }
            --l;
            p1 = l;

            l = 0;
            r = a[node].size();
            while ( r - l ) {
                mid = ( r + l ) >> 1;
                if ( a[node][mid] <= B ) l = mid + 1;
                else                     r = mid;
            }
            l--;
            p2 = l;

            //printf("End Query %d %d %d %d %d %d %d | %d\n",node,left,right,queryLeft,queryRight,A,B,p2-p1);
            return p2 - p1;
        }

        int mid = ( left + right ) >> 1;
        int p1 = Query( 2*node, left, mid, queryLeft, queryRight, A, B );
        int p2 = Query( 2*node+1, mid+1, right, queryLeft, queryRight, A, B );

        //printf("End Query %d %d %d %d %d %d %d | %d\n",node,left,right,queryLeft,queryRight,A,B,p1+p2);
        return p1 + p2;
    }

    void Update2( int node, int left, int right, int id, int val, int prevVal ) {
        if ( id < left || right < id ) return;
        if ( left == right ) {
            a[node][0] = val;
            return;
        }

        for (int i = 0; i < a[node].size(); ++i) {
            if ( a[node][i] == prevVal ) {
                a[node][i] = val;
                int p = i;
                while ( p > 0 && a[node][p-1] > val ) {
                    a[node][p] = a[node][p-1];
                    a[node][p-1] = val;
                    p--;
                }

                p = i;
                while ( p < a[node].size()-1 && a[node][p+1] < val ) {
                    a[node][p] = a[node][p+1];
                    a[node][p+1] = val;
                    p++;
                }

                break;
            }
        }

        int mid = ( left + right ) >> 1;
        Update2( 2*node, left, mid, id, val, prevVal );
        Update2( 2*node+1, mid+1, right, id, val, prevVal );
    }
};

class broj {
public:
    int id, val;

    broj() {}
    broj( int _id, int _val ) { id = _id; val = _val; }

    bool operator < ( const broj &other ) const {
        return val < other.val;
    }
};

int n,q;
broj x[MaxN];
int prev[MaxN];

int o,l,r,a,b;
SegmentTree tree;

int main()
{
    freopen("pijaca.in","r",stdin);
    freopen("pijaca.out","w",stdout);

    scanf("%d",&n);
    for (int i = 0; i < n; ++i) {
        scanf("%d",&x[i].val);
        prev[i] = x[i].val;
        x[i].id = i;
    }
    sort( x, x+n );
    for (int i = 0; i < n; ++i) {
        tree.Update( 1, 0, MaxN, x[i].id, x[i].val );
    }

    scanf("%d",&q);
    for (int i = 0; i < q; ++i) {
        scanf("%d",&o);
        if ( o == 1 ) {
            scanf("%d%d%d%d",&l,&r,&a,&b);
            l--; r--;
            printf("%d\n",tree.Query( 1, 0, MaxN, l, r, a, b ) );
        }
        else {
            scanf("%d%d",&a,&b);
            a--;
            tree.Update2(1,0,MaxN,a,b,prev[a]);
            prev[a] = b;
        }
    }

    return 0;
}
