#include <cstdio>
// This solution is pathetic.

#define MAXN          50000
#define MAXNHARD      (MAXN & ~MAXN)

typedef long long Integer;

Integer nums[MAXN], N, Q;

int main()
{
  FILE *in = fopen("pijaca.in", "r"), *out = fopen("pijaca.out", "w");
  fscanf(in, "%d", &N);
  for (int i = 0; i < N; ++i) {
    fscanf(in, "%lld", nums + i);
  }
  
  fscanf(in, "%d", &Q);
  for (int i = 0; i < Q; ++i) {
    int type;
    fscanf(in, "%lld", &type);
    if (type == 1) {
      int L, R, q = 0;
      Integer A, B;
      fscanf(in, "%d %d %lld %lld", &L, &R, &A, &B);
      --L; --R;
      for (int j = L; j <= R; ++j) {
        if (nums[j] >= A && nums[j] <= B)
          ++q;
      }
      
      fprintf(out, "%d\n", q);
    } else {
      int I;
      Integer J;
      fscanf(in, "%d %lld", &I, &J);
      nums[I - 1] = J;
    }
  }
  fclose(in); fclose(out);
  return 0; 
}
