#include<bits/stdc++.h>
#define int long long
using namespace std;
struct node
{
int l,r;
int lazy;
}tr[1000010];
void push_down(int p)
{
if(tr[p].lazy==0)
return;
tr[p*2].lazy^=tr[p].lazy;
tr[p*2+1].lazy^=tr[p].lazy;
}
void build(int l,int r,int p)
{
tr[p].l=l,tr[p].r=r;
int mid=(l+r)/2;
build(l,mid,p*2);
build(mid+1,r,p*2+1);
}
void update(int l,int r,int k,int p)
{
if(tr[p].l>=l&&tr[p].r<=r)
{
tr[p].lazy^=1;
return;
}
push_down(p);
int mid=(tr[p].l+tr[p].r)/2;
if(mid>=l)
update(l,r,k,p*2);
if(mid<r)
update(l,r,k,p*2+1);
}
int query(int l,int r,int p)
{
if(tr[p].l>=l&&tr[p].r<=r)
{
if(tr[p].lazy==0)
return 0;
else
return tr[p].r-tr[p].l+1;
}
push_down(p);
int mid=(tr[p].l+tr[p].r)/2,sum=0;
if(mid>=l)
sum+=query(l,r,p*2);
if(mid<r)
sum+=query(l,r,p*2+1);
return sum;
}
signed main()
{
int n,m;
cin>>n>>m;
build(1,n,1);
while(m--)
{
int op,x,y;
cin>>op>>x>>y;
if(op==0)
{
int k;
cin>>k;
update(x,y,k,1);
}
else
{
cout<<query(x,y,1)<<endl;
}
}
return 0;
}