#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

const int N = 100000; // za svaki slucaj, zbog korenja i slicno
const int M = 500;
const int INF = 1 << 25;
int n, m; // m = (int)sqrt(n) + 1
int a[N], b[M][M]; // a - originalni, b - sortirani delovi duzine m

void update(int p, int x)
{
    int prev = a[p];
    int k = p / m;
    int i;
    for(i = 0; b[k][i] != prev; i++) ;
    a[p] = b[k][i] = x;
    if(x > prev)
        while(i < m - 1 && b[k][i] > b[k][i + 1])
        {
            swap(b[k][i], b[k][i + 1]);
            i++;
        }
    else
        while(i > 0 && b[k][i] < b[k][i - 1])
        {
            swap(b[k][i], b[k][i - 1]);
            i--;
        }
}

int ccount(int k, int x, int y) // count je izgleda zauzeo STL.
{
    if(b[k][0] > y || b[k][m - 1] < x) return 0;

    // poslednji manji
    int l = 0, r = m - 1;
    while(l - r > 1)
    {
        int s = (l + r) / 2;
        if(b[k][s] >= x) r = s - 1;
        else l = s;
    }
    int first = l;
    while(b[k][first] >= x && first >= 0) first--;
    while(b[k][first + 1] < x && first < m) first++;

    // prvi veci
    l = 0; r = m - 1;
    while(l - r > 1)
    {
        int s = (l + r) / 2;
        if(b[k][s] <= y) l = s + 1;
        else r = s;
    }
    int last = r;
    while(b[k][last] <= y && last < m) last++; // kalemljenje at its best ;) isto gore.
    while(last > 0 && b[k][last - 1] > y) last--;

    //printf("%3i: %i %i\n",k,first,last);

    return last - first - 1;
}

int query(int l, int r, int x, int y)
{
    int res = 0;
    while(l % m)
    {
        if(a[l] >= x && a[l] <= y) res++;
        l++;
    }
    while(r % m != m - 1 && r >= 0)
    {
        if(a[r] >= x && a[r] <= y) res++;
        r--;
    }

    for(int i = l / m; i <= r / m; i++)
        res += ccount(i, x,y);

    return res;
}

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

    scanf("%i",&n);
    m = sqrt(n) + 1;
    for(int i = 0; i < m * m; i++) a[i] = INF;
    for(int i = 0; i < m; i++)
        for(int j = 0; j < m; j++)
            b[i][j] = INF;

    for(int i = 0; i < n; i++)
    {
        scanf("%i",&a[i]);
        b[i / m][i % m] = a[i];
    }

    for(int i = 0; i < m; i++) sort(b[i], b[i] + m);

    int q;
    scanf("%i",&q);
    for(int i = 0; i < q; i++)
    {
        int c;
        scanf("%i",&c);
        if(c == 1)
        {
            int l,r,a,b;
            scanf("%i %i %i %i",&l,&r,&a,&b);
            l--; r--; // indeksiranje od 0
            printf("%i\n",query(l,r,a,b));
        }
        else
        {
            int p, x;
            scanf("%i %i",&p,&x);
            p--; // od 0
            update(p,x);
        }

        /*for(int i = 0; i < m; i++)
            for(int j = 0; j < m; j++) printf("%4i%c",b[i][j], j == m - 1 ? '\n' : ' ');*/
    }

    fclose(stdin);
    fclose(stdout);

    return 0;
}
