//In the name of God
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct node
{
node *l,*r;
int st,en;
int val;
bool revch;
node(int x,int y)
{
st=x;
en=y;
}
void change(int begin,int end)
{
begin=max(begin,st);
end=min(end,en);
if(begin>end) return;
if(begin==st and end==en)
{
revch=1-revch;
val=(en-st+1)-val;
}
else if(st!=en)
{
if(l==NULL)
l=new node(st,(st+en)/2);
l->change(begin,end);
if(r==NULL)
r=new node((st+en)/2+1,en);
r->change(begin,end);
val=l->val+r->val;
if(revch)
val=(en-st+1)-val;
}
}
int query(int begin,int end)
{
begin=max(begin,st);
end=min(end,en);
if(begin>end) return 0;
if(begin==st and end==en)
return val;
else if(st!=en)
{
int sum=0;
if(l!=NULL)
sum+=l->query(begin,end);
if(r!=NULL)
sum+=r->query(begin,end);
if(revch)
sum=(end-begin+1)-sum;
return sum;
}
return 0;
}
};
int main()
{
vector<node *> st(20);
for(int i=0;i<st.size();++i)
st[i]=new node(0,1e5+10);
int n;
cin>>n;
for(int i=1;i<=n;++i)
{
int a; cin>>a;
for(int j=0;a!=0;j++)
{
if(a%2)
st[j]->change(i,i);
a/=2;
}
}
int m;
cin>>m;
while(m--)
{
int t,sst,en,xo;
cin>>t>>sst>>en;
if(t==1)
{
//sum
int ans=0;
for(int j=0;j<st.size();++j)
{
int c=st[j]->query(sst,en);
c<<=j;
ans+=c;
}
cout<<fixed<<ans<<endl;
}
else
{
cin>>xo;
for(int j=0;xo!=0;j++)
{
if(xo%2)
st[j]->change(sst,en);
xo/=2;
}
}
}
return 0;
}
Ly9JbiB0aGUgbmFtZSBvZiBHb2QKI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IG5vZGUKewogIG5vZGUgKmwsKnI7CiAgaW50IHN0LGVuOwogIGludCB2YWw7CiAgYm9vbCByZXZjaDsKICBub2RlKGludCB4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