#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

const int MAX_N = 50000;
const int GROUP_SIZE = 230;
const int GROUP_NUM = MAX_N / GROUP_SIZE + 5;

int n, q, m;
int A[MAX_N];
vector<int> group[GROUP_NUM];
vector<int> original[GROUP_NUM];

int binary(int group_id, int val) {
    int low = 0;
    int high = group[group_id].size();
    while (low < high) {
        int mid = (low + high) / 2;
        if (group[group_id][mid] <= val) low = mid + 1;
        else high = mid;
    }
    return low;
}

int go_group(int group_id, int pos, int dir, int a, int b, int end = -1) {
    if (group_id == -1 || group_id == m) return 0;
    int ret = 0;
    int sz = original[group_id].size();
    if (end == -1) end = sz - 1;
    for (int i = pos; i != -1 && i != end + 1; i += dir) {
        if (original[group_id][i] >= a && original[group_id][i] <= b)
            ++ret;
    }
    return ret;
}

int find_in_group(int group_id, int val) {
    for (int i = 0; i < group[group_id].size(); ++i)
        if (group[group_id][i] == val)
            return i;
    return -1;
}

int main() {
    for (int i = 0; i < GROUP_NUM; ++i) group[i].clear();
    freopen("pijaca.in", "r", stdin);
    freopen("pijaca.out", "w", stdout);
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int x; scanf("%d", &x);
        A[i] = x;
        group[i / GROUP_SIZE].push_back(x);
        original[i / GROUP_SIZE].push_back(x);
    }
    m = (n + GROUP_SIZE - 1) / GROUP_SIZE;
    for (int i = 0; i < m; ++i) sort(group[i].begin(), group[i].end());
    scanf("%d", &q);
    for (int query = 0; query < q; ++query) {
        int type; scanf("%d", &type);
        if (type == 2) {
            int pos, val;
            scanf("%d%d", &pos, &val);
            --pos;
            int group_id = pos / GROUP_SIZE;
            int pos_id = find_in_group(group_id, A[pos]);
            A[pos] = val;
            original[group_id][pos % GROUP_SIZE] = val;
            group[group_id][pos_id] = val;
            int sz = group[group_id].size();
            while (pos_id < sz && group[group_id][pos_id] > group[group_id][pos_id + 1]) {
                swap(group[group_id][pos_id], group[group_id][pos_id + 1]);
                ++pos_id;
            }
            while (pos_id > 0 && group[group_id][pos_id] < group[group_id][pos_id - 1]) {
                swap(group[group_id][pos_id], group[group_id][pos_id - 1]);
                --pos_id;
            }
        } else {
            int l, r;
            int a, b;
            scanf("%d%d%d%d", &l, &r, &a, &b);
            --l; --r;
            int res = 0;
            int first_group = (l + GROUP_SIZE - 1) / GROUP_SIZE;
            int last_group = (r - 1) / GROUP_SIZE;
            for (int group_id = first_group; group_id <= last_group; ++group_id) {
                int t1 = binary(group_id, b);
                int t2 = binary(group_id, a - 1);
                res += t1 - t2;
            }
            if (first_group == last_group + 1) {
                res += go_group(first_group - 1, l % GROUP_SIZE, 1, a, b, r % GROUP_SIZE);
            } else {
                res += go_group(first_group - 1, l % GROUP_SIZE, 1, a, b);
                res += go_group(last_group + 1, r % GROUP_SIZE, -1, a, b);
            }
            printf("%d\n", res);
        }
    }
    return 0;
}
