#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int MAXN = 100000;
struct node{
int tail,flips,l,r;
node *LEFT,*RIGHT;
node(){
l = r = tail = flips = 0;
LEFT = NULL;
RIGHT = NULL;
}
node(int x,int y,int t=0)
{
l = x;
r = y;
flips = 0;
tail = t;
LEFT = RIGHT = NULL;
}
void merge()
{
tail = LEFT->tail + RIGHT->tail;
}
node* build(int L,int R)
{
if(L == R)
{
return new node(L,R,1);
}
int mid = (L + R)>>1;
if(LEFT == NULL)
{
LEFT = new node(L,mid);
LEFT = LEFT->build(L,mid);
}
if(RIGHT == NULL)
{
RIGHT = new node(mid+1,R);
RIGHT = RIGHT->build(mid+1,R);
}
merge();
return this;
}
void push()
{
if(LEFT != NULL)
LEFT->flips += flips;
if(RIGHT != NULL)
RIGHT->flips += flips;
if(flips != 0 && flips%2 != 0)
{
tail = r - l + 1 - tail;
}
flips = 0;
return;
}
void update(int x,int y)
{
push();
if(x > r || y < l)
return;
if(x <= l && r <= y)
{
tail = r - l + 1 - tail;
if(LEFT != NULL)
LEFT->flips += 1;
if(RIGHT != NULL)
RIGHT->flips += 1;
return;
}
LEFT->update(x,y);
RIGHT->update(x,y);
tail = RIGHT->tail + LEFT->tail;
}
int query(int x,int y)
{
push();
if(r < x || l > y)
return 0;
if(x <= l && r <= y)
{
return r - l + 1 - tail;
}
return LEFT->query(x,y) + RIGHT->query(x,y);
}
};
int main()
{
int n,m;
cin >> n ;
struct node root(0,n-1);
root.build(0,n-1);
cin >> m;
//cout << 1<< '\n';
for(int i = 0; i < m;++i)
{
int t,x,y;
cin >> t >> x >> y;
if(t == 0)
root.update(x,y);
else
cout << root.query(x,y) << '\n';
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnR5cGVkZWYgbG9uZyBsb25nIGxsOwp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBpbnQgTUFYTiA9IDEwMDAwMDsKc3RydWN0IG5vZGV7CglpbnQgdGFpbCxmbGlwcyx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