#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int MaxN = 5e4 + 45;
const int MaxQ = 5e4 + 45;
const int MaxSqrt = 250;
const int MaxVal = 1e9;

int n, q, tip, x, y, l, r, sz, niz[ MaxN ];
vector< int > bucket[ MaxSqrt ];

int main()
{
  freopen( "pijaca.in", "r", stdin );
  freopen( "pijaca.out", "w", stdout );
  scanf( "%d", &n );
  while ( sz * sz <= n ) sz++;
  for ( int i = 0; i < n; i++ )
  {
    scanf( "%d", niz + i );
    bucket[ i / sz ].push_back( niz[ i ] );
  }
  for ( int i = 0; i < sz; i++ ) sort( bucket[ i ].begin(), bucket[ i ].end() );
  scanf( "%d", &q );
  while ( q-- )
  {
    scanf( "%d", &tip );
    if ( tip - 1 )
    {
      scanf( "%d %d", &x, &y );
      --x;
      int idx = x / sz;
      bucket[ idx ].erase( lower_bound( bucket[ idx ].begin(), bucket[ idx ].end(), niz[ x ] ) );
      bucket[ idx ].insert( lower_bound( bucket[ idx ].begin(), bucket[ idx ].end(), y ), y );
      niz[ x ] = y;
    }
    else
    {
      scanf( "%d %d %d %d", &l, &r, &x, &y );
      --l, --r;
      int ret = 0;
      for ( ; l <= r && l % sz != 0; l++ ) if ( x <= niz[ l ] && niz[ l ] <= y ) ret++;
      for ( ; l <= r && r % sz != ( sz - 1 ); r-- ) if ( x <= niz[ r ] && niz[ r ] <= y ) ret++;
      int A = l / sz;
      int B = r / sz;
      if ( l < r )
        for ( int i = A; i <= B; i++ )
          ret += upper_bound( bucket[ i ].begin(), bucket[ i ].end(), y ) - lower_bound( bucket[ i ].begin(), bucket[ i ].end(), x );
      printf( "%d\n", ret );
    }
  }
  return 0;
}
