#include <bits/stdc++.h>
using namespace std;
long long st[int(8e5)], lz[int(8e5)];
long long cons(int i, int l, int r, int a[]){
lz[i] = -1;
if(l == r){
return st[i] = 1LL << a[l];
}
int mid = (l+r)/2;
return st[i] = cons(i*2, l, mid, a) | cons(i*2+1, mid+1, r, a);
}
void prop(int i, int l, int r){
if(lz[i] == -1) return;
st[i] = lz[i];
if(l != r){
lz[i*2] = lz[i];
lz[i*2+1] = lz[i];
}
lz[i] = -1;
}
long long get(int i, int l, int r, int a, int b){
prop(i, l, r);
if(b < l || r < a) return 0;
if(a <= l && r <= b) return st[i];
int mid = (l+r)/2;
return get(i*2, l, mid, a, b) | get(i*2+1, mid+1, r, a, b);
}
void upd(int i, int l, int r, int a, int b, int v){
prop(i, l, r);
if(b < l || r < a) return;
if(a <= l && r <= b) {
st[i] = 1LL << v;
if(l != r){
lz[i*2+1] = lz[i*2] = 1LL << v;
}
return;
}
int mid = (l+r)/2;
upd(i*2, l, mid, a, b, v);
upd(i*2+1, mid+1, r, a, b, v);
st[i] = st[i*2] | st[i*2+1];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q, t, l, r, v;
cin >> n >> q;
int a[n];
for(int i = 0;i < n;i++) cin >> a[i];
cons(1, 0, n-1, a);
while(q--){
cin >> t;
if(t == 1){
cin >> l >> r >> v;
upd(1, 0, n-1, l-1, r-1, v);
} else {
cin >> l >> r;
cout << __builtin_popcountll(get(1, 0, n-1, l-1, r-1)) << '\n';
}
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmxvbmcgbG9uZyBzdFtpbnQoOGU1KV0sIGx6W2ludCg4ZTUpXTsKbG9uZyBsb25nIGNvbnMoaW50IGksIGludCBsLCBpbnQgciwgaW50IGFbXSl7CglseltpXSA9IC0xOwoJaWYobCA9PSByKXsKCQlyZXR1cm4gc3RbaV0gPSAxTEwgPDwgYVtsXTsKCX0KCWludCBtaWQgPSAobCty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