#include<stdio.h>
#include<math.h>
#include<algorithm>

using namespace std;

FILE *fin,*fout;

int n,q,u,i,j,kn,c[100000],sdk[100000],br,gl,gd;

int nadji(int p,int a,int b)
{
 int l,d,pa,pb,r;
 l=p;
 d=p+kn-1;
 pa=-1;
 pb=-1;
 r=0;
 while(d-l>1)
 {
  if(a>sdk[(l+d)/2])
  {
   l=(l+d)/2;
  }
  if(a<sdk[(l+d)/2])
  {
   d=(l+d)/2;
  }
  if(a==sdk[(l+d)/2])
  {
   pa=(l+d)/2;
   r++;
   break;
  }
 }
 if(pa==-1)
 {
   pa=l;
   if(a==sdk[d])
   {
    r++;
    pa=d;
   }
 }
  
 l=p;
 d=p+kn-1;  
 while(d-l>1)
 {
  if(b>sdk[(l+d)/2])
  {
   l=(l+d)/2;
  }
  if(b<sdk[(l+d)/2])
  {
   d=(l+d)/2;
  }
  if(b==sdk[(l+d)/2])
  {
   pb=(l+d)/2;
   r++;
   break;
  }
 }
 if(pb==-1)
 {
  pb=l;
  if(b==sdk[d])
  {
   r++;
   pb=d;
  }
 }
    
 if(pa!=pb)
  r+=pb-pa-1;
 if(pa==pb && sdk[pa]==a && sdk[pb]==b) 
  r--;
   
 return r;
}

int main()
{
 fin=fopen("pijaca.in", "r");
 fout=fopen("pijaca.out", "w");
 fscanf(fin,"%d",&n);
 for(kn=1;kn*kn<n;kn++);
 for(i=0;i<n;i++)
 {
  fscanf(fin,"%d",&c[i]);
  sdk[i]=c[i];
 }
 for(i=0;i+kn<n;i+=kn)
 {
  sort(sdk+i,sdk+i+kn);
 }
 sort(sdk+i,sdk+n);
 fscanf(fin,"%d",&q);
 for(i=0;i<q;i++)
 {
  fscanf(fin,"%d",&u);
  if(u==1)
  {
   int a,b,l,r;
   fscanf(fin,"%d%d%d%d",&l,&r,&a,&b);
   if(a>b)
   {
    int p=a;
    a=b;
    b=p;
   }
   br=0;
   gl=((l-1)/kn+1)*kn;
   gd=(r/kn)*kn;
   for(j=l-1;j<gl;j++)
   {
    if(c[j]>=a && c[j]<=b)
    {
     br++;
    }
   }
   for(j=gd;j<r;j++)
   {
    if(c[j]>=a && c[j]<=b)
    {
     br++;
    }
   }
   for(j=gl;j<gd;j+=kn)
   {
    br+=nadji(j,a,b);
   }
   fprintf(fout,"%d\n",br);
  }
  if(u==2)
  {
   int a,b,p;
   fscanf(fin,"%d%d",&a,&b);
   c[a-1]=b;
   p=(a-1)/kn*kn;
   if(p+kn<n)
   {
    for(j=p;j<p+kn;j++)
    {
     sdk[j]=c[j];
    }
    sort(sdk+p,sdk+p+kn);
   }
   else
   {
    for(j=p;j<n;j++)
    {
     sdk[j]=c[j];
    }
    sort(sdk+p,sdk+n); 
   }
  }
 }
 return 0;
}
