#include<stdio.h>
#include<set>
#include<vector>


using namespace std;

const int MAXN=50000;
const int MAXQ=50000;



int a[MAXN];
vector<int> b[MAXN];
int n,q;
vector<int> v;

int bin(int x)
{
    int i=0;
    int j=v.size()-1;
    while(j-i>1)
    {
                int p=(i+j)/2;
                if(v[p]<x) i=p;
                else j=p;            
    }   
    if(v[i]==x) return i; 
    return j;
}

int main()
{
    FILE *f,*g;
    f=fopen("pijaca.in","r");
    g=fopen("pijaca.out","w");
    
    fscanf(f,"%d",&n);
    for(int i=0; i<n; i++) fscanf(f,"%d",&a[i]);
    fscanf(f,"%d",&q);
    set<int> s (a,a+n);
    v=vector<int> (s.begin(),s.end());
    for(int i=0; i<n; i++)
    {
            for(int j=0; j<v.size(); j++)
            {
                    if(i>0) b[i].push_back(b[i-1][j]+(int)(a[i]==v[j]));        
                    else b[i].push_back((int)(a[i]==v[j]));
            }        
    }
    for(int i=0; i<q; i++)
    {
            int x;
            fscanf(f,"%d",&x);
            if(x==1)
            {
                    int _l,_r,_a,_b;
                    fscanf(f,"%d %d %d %d",&_l,&_r,&_a,&_b);  
                    _l--;_r--;
                    int _i,_j;
                    _i=bin(_a);
                    _j=bin(_b);
                    if(v[_j]!=_b) _j--;
                    //printf("%d %d\n",_i,_j);
                   
                    int res=0;
                    for(int k=_i; k<=_j; k++)
                    {
                            if(_l==0) res+=b[_r][k];
                            else res+=b[_r][k]-b[_l-1][k];
                    }
                    fprintf(g,"%d\n",res);
                    
            }
            else
            {
                int _i,_j;
                fscanf(f,"%d %d",&_i,&_j);
                _i--;
                int x=bin(a[_i]);
                int y=bin(_j);
                //printf("%d %d\n",x,y);
                for(int k=_i; k<n; k++)
                {
                        b[k][x]--;
                        b[k][y]++;        
                }
            }
    }
    
    
    
    /*
    
    for(int i=0; i<v.size(); i++)
    {
            for(int j=0; j<n; j++) printf("%d ",b[j][i]);
            printf("\n");        
    }
    
    
    
    
    scanf("%d",&n);
    */
    
    fclose(f);
    fclose(g);    
}
