#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

struct upit0{
   bool resen;
   int l,r,sol,a,b;
}; //to su pravi upiti iz zadatka. a i b su reindeksirani ASAP

struct upit1{
   int x,orig;
}; //to su upiti koje sortiram i resavam

struct tezga{
   int x,vr;
};

upit0 U[200005];
upit1 V[200005];
tezga A[200005];
int Reindex[200005];
int N,Q,K;
int C[200005];
int T[200005];

void ubaci(int p){
   while (p<200005){
      C[p]++;
      p+=p&(-p);
   }
}

int citaj(int p){
   if (p==0) return 0;
   int r=0;
   while (p>0){
      r+=C[p];
      p-=p&(-p);
   }
   return r;
}

bool cmptezga(tezga a,tezga b){
   return a.vr < b.vr;
}

bool cmpupit(upit1 a,upit1 b){
   return a.x < b.x;
}

void ucitajtezge(){
   scanf("%d",&N);
   int i;
   for (i=1; i<=N; i++){
      scanf("%d",&A[i].vr);
      A[i].x = i;
   }
}

void ucitajupite(){
   int i,j;
   for (i=1; i<=Q; i++){
      scanf("%d%d%d%d%d",&j,&U[i].l,&U[i].r,&U[i].a,&U[i].b);

      A[N+2*i-1].x = N+2*i-1;
      A[N+2*i-1].vr = U[i].a;

      A[N+2*i].x = N+2*i;
      A[N+2*i].vr = U[i].b;

      V[2*i-1].orig = i;
      V[2*i-1].x = U[i].l - 1;
      V[2*i].orig = i;
      V[2*i].x = U[i].r;
   }
   sort(V+1,V+2*Q+1,cmpupit);
   sort(A+1,A+N+2*Q+1,cmptezga);
   for (i=1; i<=N+2*Q; i++){
      if (A[i].vr != A[i-1].vr) K++;
      if (A[i].x > N){
         if ((A[i].x - N)%2 == 0){
            U[(A[i].x-N) / 2].b = K;
         } else {
            U[(A[i].x-N+1) / 2].a = K;
         }
      } else {
         Reindex[A[i].x] = K;
      }
   }
   //for (i=1; i<=Q; i++) printf("%d %d\n",U[i].a,U[i].b);
   //for (i=1; i<=2*Q; i++) printf("%d %d iki\n",V[i].orig,V[i].x);
   //for (i=1; i<=N; i++) printf("%d\n",Reindex[i]);
}

void resiQ(){
   ucitajupite();
   int i,j,k;
   j=0;
   for (i=1; i<=2*Q; i++){
      //naguraj tacke:
      while (j<N && (j+1 <= V[i].x)){
         j++;
         //printf("lol %d %d\n",i,j);
         ubaci(Reindex[j]);
         //printf("ubacen %d\n",Reindex[j]);
      }
      //resi:
      k = V[i].orig;
      //printf("  %d %d %d\n",j,k,U[k].a);
      if (U[k].resen){
         U[k].sol += -citaj(U[k].a-1) + citaj(U[k].b);
         //printf("povecam %d %d %d\n",-citaj(U[k].a-1) + citaj(U[k].b) , U[k].a-1 , U[k].b);
      } else {
         U[k].resen = true;
         U[k].sol -= -citaj(U[k].a-1) + citaj(U[k].b);
         //printf("smanjim %d %d %d\n",-citaj(U[k].a-1) + citaj(U[k].b) , U[k].a-1 , U[k].b);
      }
   }
   for (i=1; i<=Q; i++) printf("%d\n",U[i].sol);
}

void resiS(){
   int l,r,a,b,i,j,k,sl;
   for (i=1; i<=N; i++) T[i] = A[i].vr;
   for (i=1; i<=Q; i++){
      scanf("%d",&k);
      if (k==1){
         scanf("%d%d%d%d",&l,&r,&a,&b);
         sl=0;
         for (j=l; j<=r; j++) if (a <= T[j] && T[j] <= b) sl++;
         printf("%d\n",sl);
      } else {
         scanf("%d%d",&a,&b);
         T[a] = b;
      }
   }
}

int main(){
   freopen("pijaca.in","r",stdin);
   freopen("pijaca.out","w",stdout);
   ucitajtezge();
   scanf("%d",&Q);
   if (Q%2==1) resiQ(); else resiS();
   return 0;
}


