#include <bits/stdc++.h>
using namespace std;

constexpr int LV = 20, M = (1 << LV) - 1;
int n, q;

struct D {
    D* c[2] = {nullptr, nullptr};
    // bx: bits that differ,  by: not in bx, the same bit
    int bx = 0, by = 0, num = 0, lz = 0;

    void down(int lv) {
        if (lv < 0) return;
        if (lz >> lv & 1) {
            swap(c[0], c[1]);
            lz ^= 1 << lv;
        }
        for (int i = 0; i < 2; ++i)
            if (c[i]) {
                c[i]->lz ^= lz;
                c[i]->by = ~c[i]->bx & (c[i]->by ^ lz);
            }
        lz = 0;
    }

    void up(int lv) {
        if (!c[0] && !c[1]) {
            bx = by = 0;
            num = lv < 0;
        } else if (c[0] && c[1]) {
            bx = c[0]->bx | c[1]->bx | (c[0]->by ^ c[1]->by) | 1 << lv;
            by = ~bx & (c[0]->by | c[1]->by);
            num = c[0]->num + c[1]->num;
        } else {
            int t = !c[0];
            bx = c[t]->bx;
            by = c[t]->by | t << lv;
            num = c[t]->num;
        }
        by = ~bx & (by ^ lz);
    }
} * root;

void dbg(D* a, int lv, int l = 0, int r = M) {
    return;
    vector<int> s;
    function<void(D*, int, int, int)> dfs = [&](D* a, int lv, int l, int r) {
        if (!a) return;
        a->down(lv);
        if (a->num <= 0) {
            cout << "ERROR A "
                 << " " << lv << " " << l << " " << r << " " << a->num << endl;
            exit(0);
        };
        if (l == r) {
            s.push_back(l);
            return;
        }
        dfs(a->c[0], lv - 1, l, (l + r + 1) / 2 - 1);
        dfs(a->c[1], lv - 1, (l + r + 1) / 2, r);
    };
    dfs(a, lv, l, r);
    // DEBUG(s);
    /*
    if (lv == LV - 1) {
        cerr << l << "~" << r << endl;
    }
    if (!a) return;
    string pad((LV - lv) * 2, ' ');
    cerr << pad << "num,bx,by,lz = " << a->num << "," << a->bx << "," << a->by << "," << a->lz
         << "\n";
    int mid = (l + r + 1) / 2;
    if (lv < 0) return;
    cerr << pad << "0: " << l << "~" << mid - 1 << "\n";
    dbg(a->c[0], lv - 1, l, mid - 1);
    cerr << pad << "1: " << mid << "~" << r << "\n";
    dbg(a->c[1], lv - 1, mid, r);*/
}

// [0,x) [x,M]
pair<D*, D*> splt(D* a, int lv, int x, int l, int r) {
    if (!a) return {nullptr, nullptr};
    a->down(lv);
    if (r < x) return {a, nullptr};
    if (l >= x) return {nullptr, a};
    D *p[2] = {nullptr, nullptr}, *pt;
    int mid = (l + r + 1) / 2;  // l,mid-1 | mid,r
    if (x < mid) {
        tie(pt, a->c[0]) = splt(a->c[0], lv - 1, x, l, mid - 1);
        p[1] = a;
        if (pt) p[0] = new D, p[0]->c[0] = pt;
    } else {
        tie(a->c[1], pt) = splt(a->c[1], lv - 1, x, mid, r);
        p[0] = a;
        if (pt) p[1] = new D, p[1]->c[1] = pt;
    }
    for (int t : {0, 1})
        if (p[t]) {
            p[t]->up(lv);
            if (!p[t]->num) {
                delete p[t];
                p[t] = nullptr;
            }
        }
    return {p[0], p[1]};
}

D* mrg(D* a, D* b, int lv) {
    if (!a || !b) return a ? a : b;
    a->down(lv);
    b->down(lv);
    a->c[0] = mrg(a->c[0], b->c[0], lv - 1);
    a->c[1] = mrg(a->c[1], b->c[1], lv - 1);
    a->up(lv);
    delete b;
    return a;
}

D* ins(D* a, int lv, int z) {
    if (!a) a = new D();
    if (lv < 0) {
        a->lz = a->bx = a->by = 0;
        a->num = 1;
        return a;
    }
    a->down(lv);
    int b = z >> lv & 1;
    a->c[b] = ins(a->c[b], lv - 1, z);
    a->up(lv);
    return a;
}

void dxor(D* a, int lv, int x) {
    if (!a) return;
    a->lz ^= x;
    a->by ^= ~a->bx & x;
}

void dor(D* a, int lv, int x) {
    if (!a) return;
    a->down(lv);
    if (!(a->bx & x)) {
        dxor(a, lv, x & ~a->by);
    } else {
        if (x >> lv & 1) {
            a->c[1] = mrg(a->c[0], a->c[1], lv - 1);
            a->c[0] = nullptr;
            a->up(lv);
            x ^= 1 << lv;
        }
        dor(a->c[0], lv - 1, x);
        dor(a->c[1], lv - 1, x);
    }
    a->up(lv);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> q;
    for (int i = 0, x; i < n; ++i) {
        cin >> x;
        root = ins(root, LV - 1, x);
    }
    for (int tc = 0; tc < q; ++tc) {
        dbg(root, LV - 1);
        int t, l, r, x;
        cin >> t >> l >> r;
        auto [r1, rt] = splt(root, LV - 1, l, 0, M);
        auto [r2, r3] = splt(rt, LV - 1, r + 1, 0, M);

        dbg(r2, LV - 1);
        if (t < 4) cin >> x;
        if (t == 1) {
            dxor(r2, LV - 1, M);
            dor(r2, LV - 1, M ^ x);
            dxor(r2, LV - 1, M);
        } else if (t == 2) {
            dor(r2, LV - 1, x);
        } else if (t == 3) {
            dxor(r2, LV - 1, x);
        } else {
            cout << (r2 ? r2->num : 0) << endl;
        }
        r2 = mrg(r2, r3, LV - 1);
        root = mrg(r1, r2, LV - 1);
    }
}