#include <cstdio>

using namespace std;

const int MaxN = 50000 + 5;
const int MaxQ = 50000 + 5;

int N, Q, X[MaxN];

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

    scanf ( "%d", &N );

    for ( int i = 0; i < N; i++ ) scanf ( "%d", &X[i] );

    scanf ( "%d", &Q );

    while ( Q-- )
    {
        int Command;

        scanf ( "%d", &Command );

        if ( Command % 2 )
        {
            int L, R, A, B;

            scanf ( "%d %d %d %d" , &L, &R, &A, &B );

            L--;
            R--;

            int Sol = 0;

            for ( int i = L; i <= R; i++ ) if ( ( A <= X[i] ) && ( X[i] <= B ) ) Sol++;

            printf ( "%d\n", Sol );
        }
        else
        {
            int I, J;

            scanf ( "%d %d", &I, &J );

            I--;

            X[I] = J;
        }
    }

    return 0;
}
