#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
const int MAX_N = int(1e6) + 10;
const long long int MOD=1e9+7;
const long long int INF=1e18;
typedef long long int ll;
typedef unsigned long long int llu;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int arr[100005];
map<int,pbds>mp[25];
int count2=0;
void add(int y,int z){
int val=arr[y];
int mask=0;
for(int j=0;j<23;j++){
mask=(mask<<1)+(((val>>j))&1);
mp[j][mask].erase(y);
}
arr[y]=z;
mask=0;
for(int j=0;j<23;j++){
mask=(mask<<1)+(((z>>j))&1);
mp[j][mask].insert(y);
}
}
ll l_r(int y,int z,int v){
ll ans=0;
int mask=(v&1);
count2=mp[0][mask].order_of_key(z+1)-mp[0][mask].order_of_key(y);
for(int j=1;j<=23;j++){
mask=(mask<<1)+(((v>>j))&1);
int count=mp[j][mask].order_of_key(z+1)-mp[j][mask].order_of_key(y);
ans+=(count2-count)*j;
count2=count;
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("f.in","r",stdin);
// #endif
int n,q;
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>arr[i];
int mask=0;
for(int j=0;j<23;j++){
mask=(mask<<1)+((arr[i]>>j)&1);
//cout<<mask<<endl;
// cout<<mp[mask].size()<<endl;
mp[j][mask].insert(i);
}
}
for(int i=1;i<=q;i++){
int x,y,z;
cin>>x>>y>>z;
if(x==1){
add(y,z);
}else{
int v;
cin>>v;
cout<<l_r(y,z,v)<<endl;
}
}
return 0;
}
I3ByYWdtYSBHQ0Mgb3B0aW1pemUoIk9mYXN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KICAgIG1wW2pdW21hc2tdLmVyYXNlKHkpOwogIH0KICBhcnJbeV09ejsKICBtYXNrPTA7CiAgZm9yKGludCBqPTA7ajwyMztqKyspewogICAgbWFzaz0obWFzazw8MSkrKCgoej4+aikpJjEpOwogICAgbXBbal1bbWFza10uaW5zZXJ0KHkpOwogIH0KfQpsbCBsX3IoaW50IHksaW50IHosaW50IHYpewogICBsbCBhbnM9MDsKICAgaW50IG1hc2s9KHYmMSk7CiAgIGNvdW50Mj1tcFswXVttYXNrXS5vcmRlcl9vZl9rZXkoeisxKS1tcFswXVttYXNrXS5vcmRlcl9vZl9rZXkoeSk7CiAgIGZvcihpbnQgaj0xO2o8PTIzO2orKyl7CiAgICBtYXNrPShtYXNrPDwxKSsoKCh2Pj5qKSkmMSk7CiAgICBpbnQgY291bnQ9bXBbal1bbWFza10ub3JkZXJfb2Zfa2V5KHorMSktbXBbal1bbWFza10ub3JkZXJfb2Zfa2V5KHkpOwogICAgYW5zKz0oY291bnQyLWNvdW50KSpqOwogICAgY291bnQyPWNvdW50OwogICB9CgogICByZXR1cm4gYW5zOwp9CmludCBtYWluKCkKewogIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogIGNpbi50aWUoTlVMTCk7CiAgCiAgLy8gI2lmbmRlZiBPTkxJTkVfSlVER0UKICAvLyBmcmVvcGVuKCJmLmluIiwiciIsc3RkaW4pOwogIC8vICNlbmRpZgoKICBpbnQgbixxOwogIGNpbj4+bj4+cTsKCiAgZm9yKGludCBpPTE7aTw9bjtpKyspewogICAgY2luPj5hcnJbaV07CiAgICBpbnQgbWFzaz0wOwogICAgZm9yKGludCBqPTA7ajwyMztqKyspewogICAgICAgIG1hc2s9KG1hc2s8PDEpKygoYXJyW2ldPj5qKSYxKTsKICAgICAgICAvL2NvdXQ8PG1hc2s8PGVuZGw7CiAgICAgLy8gICBjb3V0PDxtcFttYXNrXS5zaXplKCk8PGVuZGw7CiAgICAgICAgbXBbal1bbWFza10uaW5zZXJ0KGkpOwogICAgfQogIH0KCiAgZm9yKGludCBpPTE7aTw9cTtpKyspewogICAgaW50IHgseSx6OwogICAgY2luPj54Pj55Pj56OwogICAgaWYoeD09MSl7CiAgICAgIGFkZCh5LHopOwogICAgfWVsc2V7CiAgICAgIGludCB2OwogICAgICBjaW4+PnY7CiAgICAgIGNvdXQ8PGxfcih5LHosdik8PGVuZGw7CiAgICB9CiAgfQoKICByZXR1cm4gMDsKCiAgCgoKICAKICAKfQ==