1 uses math;
2 const maxn=100000+1000;
3 type node=record
4 l,r,mid,sum0,sum1:longint;
5 mark:boolean;
6 end;
7 var t:array[0..4*maxn] of node;
8 i,n,m,x,y,ch:longint;
9 procedure swap(var x,y:longint);
10 var t:longint;
11 begin
12 t:=x;x:=y;y:=t;
13 end;
14
15 procedure build(k,x,y:longint);
16 begin
17 with t[k] do
18 begin
19 l:=x;r:=y;mid:=(l+r)>>1;sum0:=r-l+1;sum1:=0;mark:=false;
20 if l=r then exit;
21 build(k<<1,l,mid);build(k<<1+1,mid+1,r);
22 end;
23 end;
24 procedure rever(k:longint);
25 begin
26 with t[k] do
27 begin
28 mark:=not(mark);
29 swap(sum0,sum1);
30 end;
31 end;
32
33 procedure pushdown(k:longint);
34 begin
35 with t[k] do
36 begin
37 if not(mark) then exit;
38 rever(k<<1);rever(k<<1+1);
39 mark:=false;
40 end;
41 end;
42 procedure pushup(k:longint);
43 begin
44 t[k].sum0:=t[k<<1].sum0+t[k<<1+1].sum0;
45 t[k].sum1:=t[k<<1].sum1+t[k<<1+1].sum1;
46 end;
47
48 procedure change(k,x,y:longint);
49 begin
50 with t[k] do
51 begin
52 if (l=x) and (r=y) then
53 begin
54 rever(k);exit;
55 end;
56 pushdown(k);
57 if y<=mid then change(k<<1,x,y)
58 else if x>mid then change(k<<1+1,x,y)
59 else
60 begin
61 change(k<<1,x,mid);change(k<<1+1,mid+1,y);
62 end;
63 pushup(k);
64 end;
65 end;
66 function query(k,x,y:longint):longint;
67 begin
68 with t[k] do
69 begin
70 if (l=x) and (r=y) then exit(sum1);
71 pushdown(k);
72 if y<=mid then exit(query(k<<1,x,y))
73 else if x>mid then exit(query(k<<1+1,x,y))
74 else exit(query(k<<1,x,mid)+query(k<<1+1,mid+1,y));
75 end;
76 end;
77
78 begin
79 assign(input,‘input.txt‘);assign(output,‘output.txt‘);
80 reset(input);rewrite(output);
81 readln(n,m);build(1,1,n);
82 for i:=1 to m do
83 begin
84 readln(ch,x,y);
85 case ch of
86 0:change(1,x,y);
87 1:writeln(query(1,x,y));
88 end;
89 end;
90 close(input);close(output);
91 end.