/*
Petar 'PetarV' Velickovic
Task: Pijaca
*/

#include <stdio.h>
#define MAX_TREE 65537
#define MAX_N 50001
#define MID (left+right)/2

//ideja: segment tree, once again
//pri svakom upitu tipa 2 updatujemo od dna ka vrhu
//pri upitima tipa 1 odsecamo nemoguce puteve

int maxVal[MAX_TREE];
int minVal[MAX_TREE];
int poz[MAX_N]; //pozicija i-tog elementa u stablu
int n,q,x;
int kom,L,R,A,B;

inline int min1(int a, int b)
{
       if (a<b) return a;
       return b;
}

inline int max1(int a, int b)
{
       if (a>b) return a;
       return b;
}

inline void UpdateTree(int idx, int pos, int left, int right)
{
       if (x>maxVal[idx]) maxVal[idx]=x;
       if (minVal[idx]==0||x<minVal[idx]) minVal[idx]=x;
       if (left==right) { poz[pos]=idx; return; }
       if (pos<=MID) UpdateTree(2*idx,pos,left,MID);
       else UpdateTree(2*idx+1,pos,MID+1,right);
}

inline void BottomUp(int pos)
{
       minVal[pos]=x;
       maxVal[pos]=x;
       int idx=pos;
       while (idx!=1)
       {
             idx/=2;
             minVal[idx]=min1(minVal[2*idx],minVal[2*idx+1]);
             maxVal[idx]=max1(maxVal[2*idx],maxVal[2*idx+1]);
       }
}             
             
inline int query(int idx, int l, int r, int left, int right)
{
       if (minVal[idx]>B) return 0;
       if (maxVal[idx]<A) return 0;
       int ret=0;
       if (l<=left && right<=r)
       {
         if (minVal[idx]>=A && maxVal[idx]<=B) return right-left+1;
       } 
       if (left==right) return 0;
       if (l<=MID) ret+=query(2*idx,l,r,left,MID);
       if (r>MID) ret+=query(2*idx+1,l,r,MID+1,right);
       return ret;
}

int main()
{
    freopen("pijaca.in","r",stdin);
    freopen("pijaca.out","w",stdout);
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        UpdateTree(1,i,1,MAX_TREE-1);
    }
    scanf("%d",&q);
    for (int i=0;i<q;i++)
    {
        scanf("%d",&kom);
        if (kom==1)
        {
          scanf("%d%d%d%d",&L,&R,&A,&B);
          printf("%d\n",query(1,L,R,1,MAX_TREE-1));
        }
        else if (kom==2)
        {
          scanf("%d%d",&L,&x);
          BottomUp(poz[L]);
        }
    }         
    return 0;
}
