1 //code by drizzle
2 #include<iostream>
3 #include<cstring>
4 #include<cstdio>
5 #include<algorithm>
6 #include<vector>
7 #define ll __int64
8 #define PI acos(-1.0)
9 #define mod 1000000007
10 using namespace std;
11 int n,m;
12 int flag,x,y;
13 struct node
14 {
15 int l;
16 int r;
17 int add;
18 int sum;
19 }tree[400005];
20 void buildtree(int root,int left,int right)
21 {
22 tree[root].l=left;
23 tree[root].r=right;
24 tree[root].add=0;
25 if(left==right)
26 {
27 tree[root].sum=0;
28 return;
29 }
30 int mid=(left+right)>>1;
31 buildtree(root<<1,left,mid);
32 buildtree(root<<1|1,mid+1,right);
33 tree[root].sum=tree[root<<1].sum+tree[root<<1|1].sum;
34 }
35 void pushdown(int root,int m)
36 {
37 tree[root<<1].add++;
38 tree[root<<1].add=tree[root<<1].add%2;
39 tree[root<<1|1].add++;
40 tree[root<<1|1].add=tree[root<<1|1].add%2;
41 tree[root<<1].sum=(m-(m>>1))-tree[root<<1].sum;
42 tree[root<<1|1].sum=(m>>1)-tree[root<<1|1].sum;
43 tree[root].add=0;
44 }
45 void updata(int c,int left,int right,int root)
46 {
47 if(tree[root].l==left&&tree[root].r==right)
48 {
49 tree[root].add++;
50 tree[root].add=tree[root].add%2;
51 tree[root].sum=right-left+1-tree[root].sum;
52 return ;
53 }
54 if(tree[root].l==tree[root].r)
55 return ;
56 if(tree[root].add)
57 pushdown(root,tree[root].r-tree[root].l+1);
58 int mid=(tree[root].l+tree[root].r)>>1;
59 if(right<=mid)
60 updata(c,left,right,root<<1);
61 else
62 {
63 if(left>mid)
64 updata(c,left,right,root<<1|1);
65 else
66 {
67 updata(c,left,mid,root<<1);
68 updata(c,mid+1,right,root<<1|1);
69 }
70 }
71 tree[root].sum=tree[root<<1].sum+tree[root<<1|1].sum;
72 }
73 int query(int root ,int left,int right)
74 {
75 if(tree[root].l==left&&tree[root].r==right)
76 {
77 return tree[root].sum;
78 }
79 if(tree[root].add)
80 pushdown(root,tree[root].r-tree[root].l+1);
81 int mid=(tree[root].l+tree[root].r)>>1;
82 if(right<=mid)
83 return query(root<<1,left,right);
84 else
85 {
86 if(left>mid)
87 return query(root<<1|1,left,right);
88 else
89 return (query(root<<1,left,mid)+query(root<<1|1,mid+1,right));
90 }
91 }
92 int main()
93 {
94 while(scanf("%d %d",&n,&m)!=EOF)
95 {
96 buildtree(1,1,n);
97 for(int i=1;i<=m;i++)
98 {
99 scanf("%d %d %d",&flag,&x,&y);
100 if(flag==0)
101 {
102 updata(1,x,y,1);
103 }
104 else
105 {
106 printf("%d
",query(1,x,y));
107 }
108 }
109 }
110 return 0;
111 }