#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#define MAXN 50000

using namespace std;

int n,q,kom,l,r,a,b,ind1,ind2,ret,vece,pomind;

struct tezga
{
       int c;
       int poz;
};

tezga x[MAXN+1];

bool cmp(tezga x, tezga y)
{
     return x.c<y.c;
}

int binarnaa(int donja,int gornja,int query)
{
    int pivot;
    while(gornja>donja)
    {
              pivot=(gornja+donja)/2;
              if(x[pivot].c<query) donja=pivot+1;
              else if(x[pivot].c>query) gornja=pivot-1;
              else if(x[pivot].c==query) gornja=pivot;   
    }
    return gornja;
}

int binarnab(int donja,int gornja,int query)
{
    int pivot;
    while(gornja>donja)
    {
              pivot=(gornja+donja)/2;
              if(gornja-donja==1) pivot++;
              if(x[pivot].c<query) donja=pivot+1;
              else if(x[pivot].c>query) gornja=pivot-1;
              else if(x[pivot].c==query) donja=pivot;           
    }
    return gornja;
}

int main(int argc, char *argv[])
{
    freopen("pijaca.in","r",stdin);
    freopen("pijaca.out","w",stdout);
    
    scanf("%d",&n);
    for(int i=0;i<=n-1;i++)
    {
            scanf("%d",&x[i].c);
            x[i].poz=i+1;
    }
    sort(x,x+n,cmp);
    scanf("%d",&q);
    for(int i=1;i<=q;i++)
    {
            ret=0;
            scanf("%d",&kom);
            if(kom==1)
            {
                      scanf("%d %d %d %d",&l,&r,&a,&b);
                      ind1=binarnaa(0,n-1,a);
                      ind2=binarnab(0,n-1,b);
                      for(int j=ind1;j<=ind2;j++)
                      {
                              if( x[j].poz>=l && x[j].poz<=r ) ret++;
                      }
                              printf("%d\n",ret);
            }
            else{      //query tip 2, ruzna improvizacija koja nece raditi.
                      scanf("%d %d",&a,&b);
                      vece=2, pomind=0;
                      for(int j=0;j<=n-1;j++)
                      {
                              if( x[j].poz==a )
                              {
                                  if(b>x[j].c) vece=1;
                                  else if(b<x[j].c) vece=0;
                                  else vece=2;
                                  x[j].c=b;
                                  pomind=j;
                                  if(vece==1)
                                  {
                                            while(pomind<=n-2 && x[pomind].c>x[pomind+1].c)
                                            {  swap(x[pomind].c,x[pomind+1].c); pomind++; }
                                  }
                                  else if(vece==0)
                                  {
                                            while(pomind>=1 && x[pomind].c<x[pomind-1].c)
                                            {  swap(x[pomind].c,x[pomind-1].c); pomind--; }
                                  }
                                  break;
                              } 
                      }
                }
    }
    //system("PAUSE");
    return 0;
}
