#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

struct node
{
    int min,max,l,r;
};

int n,L,N,Q;
node tree[100000];

int pow(int a, int n)
{
    if(n==0) return 1;
    int temp=pow(a,n/2);
    if(n%2==0) return temp*temp;
    return temp*temp*a;
}
int fix(int n)
{
    return pow(2,(int)(ceil(log2(n))));
}
void fixTree()
{
    for(int i=L-N-1; i>=0; i--)
     {
         int c1=i*2+1;
         int c2=i*2+2;
         if(tree[c1].min==-1) tree[i]=tree[c2];
         else if(tree[c2].min==-1) tree[i]=tree[c1];
         else
          {
             tree[i].min=min(tree[c1].min,tree[c2].min);
             tree[i].max=max(tree[c1].max,tree[c2].max);
             tree[i].l=tree[c1].l;
             tree[i].r=tree[c2].r;
          }
     }
}
void updateTree(int i)
{
    int c1=i*2+1;
    int c2=i*2+2;
    int mn,mx;
    if(tree[c1].min==-1) { mn=tree[c2].min; mx=tree[c2].max; }
    else if(tree[c2].min==-1) { mn=tree[c1].min; mx=tree[c1].max; }
    else
     {
         mn=min(tree[c1].min,tree[c2].min);
         mx=max(tree[c1].max,tree[c2].max);
         if(mn!=tree[i].min || mx!=tree[i].max)
          {
              tree[i].min=mn;
              tree[i].max=mx;
              updateTree((i-1)/2);
          }
     }
}

int getData(int i,int l, int r, int a, int b)
{
    //printf("getting...%d\n",i);
    if(tree[i].l>=l && tree[i].r<=r && tree[i].min>=a && tree[i].max<=b) return tree[i].r-tree[i].l+1;
    if(tree[i].min==-1) return 0;
    if(tree[i].r<l || tree[i].l>r || tree[i].min>b || tree[i].max<a) return 0;
    int c1=i*2+1;
    int c2=i*2+2;
    //printf("%d %d       %d\n",c1,c2,L-n);
    if(c1<L) return getData(c1,l,r,a,b)+getData(c2,l,r,a,b);
    return 0;
}

int main(int argc, char *argv[])
{
    FILE *in;
    FILE *out;
    in=fopen("pijaca.in","r");
    out=fopen("pijaca.out","w");
    fscanf(in,"%d",&n);
    N=fix(n);
    L=N*2-1;
    for(int i=0; i<n; i++)
     {
         fscanf(in,"%d",&tree[L-N+i].min);
         tree[L-N+i].max=tree[L-N+i].min;
         tree[L-N+i].l=tree[L-N+i].r=i;
     }
    for(int i=n; i<N; i++)
     {
         tree[L-N+i].min=-1;
         tree[L-N+i].max=-1;
         tree[L-N+i].l=-1;
         tree[L-N+i].r=-1;
     }
    fixTree();
    /*printf("\n");
    int cnt=1,cntr=0;
    for(int i=0; i<log2(L); i++)
     {
         for(int j=0; j<cnt; j++, cntr++) printf("%d-%d %d/%d   ",tree[cntr].l,tree[cntr].r,tree[cntr].min,tree[cntr].max);
         printf("\n");
         cnt*=2;
     }*/
    fscanf(in,"%d",&Q);
    for(int i=0; i<Q; i++)
     {
         int x;
         fscanf(in,"%d",&x);
         if(x==1)
          {
              int l,r,a,b;
              fscanf(in,"%d",&l);
              fscanf(in,"%d",&r);
              fscanf(in,"%d",&a);
              fscanf(in,"%d",&b);
              l--;
              r--;
              int data=getData(0,l,r,a,b);
              fprintf(out,"%d\n",data);
          }
         else if(x==2)
          {
              int a,b;
              fscanf(in,"%d",&a);
              a--;
              fscanf(in,"%d",&b);
              tree[L-N+a].min=tree[L-N+a].max=b;
              updateTree((L-N+a-1)/2);
              /*printf("\n");
              int cnt=1,cntr=0;
              for(int i=0; i<log2(L); i++)
               {
                   for(int j=0; j<cnt; j++, cntr++) printf("%d-%d %d/%d   ",tree[cntr].l,tree[cntr].r,tree[cntr].min,tree[cntr].max);
                   printf("\n");
                   cnt*=2;
               }*/
          }
     }
    fclose(in);
    fclose(out);
    system("PAUSE");
    return 0;
}
/*
4
1 2 3 4
1
1 0 3 1 4
*/

/*
6
3 2 1 2 5 5
3
1 2 5 2 3
2 3 2
1 2 6 2 3
*/
