#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#define vi vector<int>
#define pb push_back
#define vvi vector<vector<int> >
#define pii pair<int,int>
#define ll long long
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector<pair<int,int> >
#define mp make_pair
#define all(a) a.begin(), a.end()
#define inf 0x7fffffff
#define lfc(a) 2*a+1
#define rfc(a) 2*a+2
#define s(i) scanf("%d",&i)
using namespace std;
ll tree[200005];
ll lazy[200005];
void build_tree(ll *arr,int b,int e,int node)
{
if(b==e)
{
tree[node]=arr[b];
return ;
}
int mid=(b+e)/2;
build_tree(arr,b,mid,2*node+1);
build_tree(arr,mid+1,e,2*node+2);
tree[node]=(tree[2*node+1]+tree[2*node+2]);
}
//increment range [i,j] by v
void update_tree(ll *arr,int b,int e,int i,int j,int node)
{
if(lazy[node]!=0)
{
tree[node]=((e-b+1)-tree[node]);//update it
if(b!=e)
{
//pushes the lazy to its child
lazy[lfc(node)]+=lazy[node];
lazy[lfc(node)]%=2;
lazy[rfc(node)]+=lazy[node];
lazy[rfc(node)]%=2;
}
lazy[node]=0;//reset lazy of node
}
if(e<i||b>j)
{
return ;
}
if(b>=i&&e<=j)
{
tree[node]=((e-b+1)-tree[node]);
if(b!=e)
{
lazy[lfc(node)]+=1;
lazy[lfc(node)]%=2;
lazy[rfc(node)]+=1;
lazy[rfc(node)]%=2;
}
return ;
}
int mid=(b+e)/2;
update_tree(arr,b,mid,i,j,lfc(node));
update_tree(arr,mid+1,e,i,j,rfc(node));
tree[node]=(tree[lfc(node)]+tree[rfc(node)]);
}
ll query_tree(ll *arr,int b,int e,int i,int j,int node)
{
if(lazy[node]!=0)
{
tree[node]=((e-b+1)-tree[node]);//update it
if(b!=e)
{
//pushes the lazy to its child
lazy[lfc(node)]+=lazy[node];
lazy[lfc(node)]%=2;
lazy[rfc(node)]+=lazy[node];
lazy[rfc(node)]%=2;
}
lazy[node]=0;//reset lazy of node
}
if(e<i||b>j)
{
return 0 ;
}
if(b>=i&&e<=j)
{
return tree[node];
}
int mid=(b+e)/2;
ll p1=query_tree(arr,b,mid,i,j,lfc(node));
ll p2=query_tree(arr,mid+1,e,i,j,rfc(node));
return (p1+p2);
}
int main()
{
// freopen("i.txt","r",stdin);
int n;
s(n);
ll arr[n];
memset(arr,0,8*n);
memset(lazy,0,sizeof(lazy));
memset(tree,0,sizeof(tree));
int e;
s(e);int a,b,c,d;
for (int i = 0; i < e; ++i)
{
s(a);
if(a==0)
{
s(b);s(c);
update_tree(arr,0,n-1,b-1,c-1,0);
}
else
{
s(b);s(c);
cout<<query_tree(arr,0,n-1,b-1,c-1,0)<<"\n";
}
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPGNzdHJpbmc+CgojZGVmaW5lIHZpICAgdmVjdG9yPGludD4KI2RlZmluZSBwYiAgIHB1c2hfYmFjawojZGVmaW5lIHZ2aSAgdmVjdG9yPHZlY3RvcjxpbnQ+ID4KI2RlZmluZSBwaWkgIHBhaXI8aW50LGludD4KI2RlZmluZSBsbCAgIGxvbmcgbG9uZyAKI2RlZmluZSB2bCAgIHZlY3RvcjxsbD4KI2RlZmluZSB2dmwgIHZlY3Rvcjx2ZWN0b3I8bGw+ID4gCiNkZWZpbmUgbWlpICBtYXA8aW50LGludD4gCiNkZWZpbmUgbXNpICBtYXA8c3RyaW5nLGludD4gCiNkZWZpbmUgdnBpaSB2ZWN0b3I8cGFpcjxpbnQsaW50PiA+CiNkZWZpbmUgbXAgICBtYWtlX3BhaXIKI2RlZmluZSBhbGwoYSkgIGEuYmVnaW4oKSwgYS5lbmQoKQojZGVmaW5lIGluZiAweDdmZmZmZmZmCiNkZWZpbmUgbGZjKGEpIDIqYSsxCiNkZWZpbmUgcmZjKGEpIDIqYSsyCiNkZWZpbmUgcyhpKSBzY2FuZigiJWQiLCZpKQp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKbGwgdHJlZVsyMDAwMDVdOwpsbCBsYXp5WzIwMDAwNV07CnZvaWQgYnVpbGRfdHJlZShsbCAqYXJyLGludCBiLGludCBlLGludCBub2RlKQp7CiAgICBpZihiPT1lKQogICAgewogICAgICAgIHRyZWVbbm9kZV09YXJyW2JdOwogICAgICAgIHJldHVybiA7CiAgICB9CiAgICBpbnQgbWlkPShiK2UpLzI7CiAgICBidWlsZF90cmVlKGFycixiLG1pZCwyKm5vZGUrMSk7CiAgICBidWlsZF90cmVlKGFycixtaWQrMSxlLDIqbm9kZSsyKTsKICAgIHRyZWVbbm9kZV09KHRyZWVbMipub2RlKzFdK3RyZWVbMipub2RlKzJdKTsKCn0KCi8vaW5jcmVtZW50IHJhbmdlIFtpLGpdIGJ5IHYKdm9pZCB1cGRhdGVfdHJlZShsbCAqYXJyLGludCBiLGludCBlLGludCBpLGludCBqLGludCBub2RlKQp7CiAgICBpZihsYXp5W25vZGVdIT0wKQogICAgewogICAgICAgIHRyZWVbbm9kZV09KChlLWIrMSktdHJlZVtub2RlXSk7Ly91cGRhdGUgaXQKICAgICAgICBpZihiIT1lKQogICAgICAgIHsKICAgICAgICAgICAgLy9wdXNoZXMgdGhlIGxhenkgdG8gaXRzIGNoaWxkCiAgICAgICAgICAgIGxhenlbbGZjKG5vZGUpXSs9bGF6eVtub2RlXTsKICAgICAgICAgICAgbGF6eVtsZmMobm9kZSldJT0yOwogICAgICAgICAgICBsYXp5W3JmYyhub2RlKV0rPWxhenlbbm9kZV07CiAgICAgICAgICAgIGxhenlbcmZjKG5vZGUpXSU9MjsKICAgICAgICB9CiAgICAgICAgbGF6eVtub2RlXT0wOy8vcmVzZXQgbGF6eSBvZiBub2RlCiAgICB9CiAgICBpZihlPGl8fGI+aikKICAgIHsKICAgICAgICByZXR1cm4gOwoKICAgIH0KICAgIGlmKGI+PWkmJmU8PWopCiAgICB7CiAgICAgICB0cmVlW25vZGVdPSgoZS1iKzEpLXRyZWVbbm9kZV0pOwogICAgICAgIGlmKGIhPWUpCiAgICAgICAgewogICAgICAgICAgICBsYXp5W2xmYyhub2RlKV0rPTE7CiAgICAgICAgICAgIGxhenlbbGZjKG5vZGUpXSU9MjsKICAgICAgICAgICAgbGF6eVtyZmMobm9kZSldKz0xOwogICAgICAgICAgICBsYXp5W3JmYyhub2RlKV0lPTI7CiAgICAgICAgfQogICAgICAgIHJldHVybiA7CiAgICB9CiAgICBpbnQgbWlkPShiK2UpLzI7CiAgICB1cGRhdGVfdHJlZShhcnIsYixtaWQsaSxqLGxmYyhub2RlKSk7CiAgICB1cGRhdGVfdHJlZShhcnIsbWlkKzEsZSxpLGoscmZjKG5vZGUpKTsKICAgIHRyZWVbbm9kZV09KHRyZWVbbGZjKG5vZGUpXSt0cmVlW3JmYyhub2RlKV0pOwoKfQoKbGwgcXVlcnlfdHJlZShsbCAqYXJyLGludCBiLGludCBlLGludCBpLGludCBqLGludCBub2RlKQp7CiAgICAgaWYobGF6eVtub2RlXSE9MCkKICAgIHsKICAgICAgICB0cmVlW25vZGVdPSgoZS1iKzEpLXRyZWVbbm9kZV0pOy8vdXBkYXRlIGl0CiAgICAgICAgaWYoYiE9ZSkKICAgICAgICB7CiAgICAgICAgICAgIC8vcHVzaGVzIHRoZSBsYXp5IHRvIGl0cyBjaGlsZAogICAgICAgICAgICBsYXp5W2xmYyhub2RlKV0rPWxhenlbbm9kZV07CiAgICAgICAgICAgIGxhenlbbGZjKG5vZGUpXSU9MjsKICAgICAgICAgICAgbGF6eVtyZmMobm9kZSldKz1sYXp5W25vZGVdOwogICAgICAgICAgICBsYXp5W3JmYyhub2RlKV0lPTI7CiAgICAgICAgfQogICAgICAgIGxhenlbbm9kZV09MDsvL3Jlc2V0IGxhenkgb2Ygbm9kZQogICAgfQogICAgaWYoZTxpfHxiPmopCiAgICB7CiAgICAgICAgcmV0dXJuIDAgOwoKICAgIH0KICAgIGlmKGI+PWkmJmU8PWopCiAgICB7CiAgICAgICByZXR1cm4gdHJlZVtub2RlXTsKICAgICAgICAKICAgIH0KICAgIGludCBtaWQ9KGIrZSkvMjsKICAgIGxsIHAxPXF1ZXJ5X3RyZWUoYXJyLGIsbWlkLGksaixsZmMobm9kZSkpOwogICAgbGwgcDI9cXVlcnlfdHJlZShhcnIsbWlkKzEsZSxpLGoscmZjKG5vZGUpKTsKICAgIHJldHVybiAocDErcDIpOwoKfQppbnQgbWFpbigpCnsKICAgLy8gZnJlb3BlbigiaS50eHQiLCJyIixzdGRpbik7CiAgICBpbnQgbjsKICAgIHMobik7CiAgICBsbCBhcnJbbl07CiAgICBtZW1zZXQoYXJyLDAsOCpuKTsKICAgIG1lbXNldChsYXp5LDAsc2l6ZW9mKGxhenkpKTsKICAgIG1lbXNldCh0cmVlLDAsc2l6ZW9mKHRyZWUpKTsKICAgIGludCBlOwogICAgcyhlKTtpbnQgYSxiLGMsZDsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgZTsgKytpKQogICAgewogICAgICAgIHMoYSk7CiAgICAgICAgaWYoYT09MCkKICAgICAgICB7CiAgICAgICAgICAgIHMoYik7cyhjKTsKICAgICAgICAgICAgdXBkYXRlX3RyZWUoYXJyLDAsbi0xLGItMSxjLTEsMCk7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIHMoYik7cyhjKTsKICAgICAgICAgICAgY291dDw8cXVlcnlfdHJlZShhcnIsMCxuLTEsYi0xLGMtMSwwKTw8IlxuIjsKICAgICAgICB9CiAgICB9CgoKCgoKCiAgICAKfQoK