题解:这是个比较有趣的线段树问题——将一般的区间加上一个数字变成了区间反转,不过这样也并么有难多少,还是一样的打lazytag,别的没了(phile:看样子你这次程序又偷懒狂用ext往下推呵呵呵 HansBug:那是那是,不过其实不用看样子也能搞,只是繁一点)
1 var
2 i,j,k,l,m,n:longint;
3 a,b:array[0..1000000] of longint;
4 function max(x,y:longint):longint;inline;
5 begin
6 if x>y then max:=x else max:=y;
7 end;
8 function min(x,y:longint):longint;inline;
9 begin
10 if x<y then min:=x else min:=y;
11 end;
12 procedure built(z,x,y:longint);inline;
13 begin
14 if x=y then
15 a[z]:=0
16 else
17 begin
18 built(z*2,x,(x+y) div 2);
19 built(z*2+1,(x+y) div 2+1,y);
20 a[z]:=a[z*2]+a[z*2+1];
21 end;
22 b[z]:=0;
23 end;
24 procedure ext(z,x,y:longint);inline;
25 begin
26 if b[z]=0 then exit;
27 a[z]:=(y-x+1)-a[z];
28 if x<>y then
29 begin
30 b[z*2]:=1-b[z*2];
31 b[z*2+1]:=1-b[z*2+1];
32 end;
33 b[z]:=0;
34 end;
35 function op(z,x,y,l,r:longint):longint;inline;
36 var a1,a2,a3,a4:longint;
37 begin
38 if l>r then exit(0);
39 ext(z,x,y);
40 if (x=l) and (y=r) then
41 begin
42 b[z]:=1;
43 exit(((r-l+1)-a[z])-a[z]);
44 end;
45 a2:=op(z*2,x,(x+y) div 2,l,min(r,(x+y) div 2));
46 a3:=op(z*2+1,(x+y) div 2+1,y,max(l,(x+y) div 2+1),r);
47 a[z]:=a[z]+a2+a3;
48 exit(a2+a3);
49 end;
50 function cal(z,x,y,l,r:longint):longint;inline;
51 var a1,a2,a3,a4:longint;
52 begin
53 if l>r then exit(0);
54 ext(z,x,y);
55 if (x=l) and (y=r) then exit(a[z]);
56 exit(cal(z*2,x,(x+y) div 2,l,min(r,(x+y) div 2))+cal(z*2+1,(x+y) div 2+1,y,max(l,(x+y) div 2+1),r));
57 end;
58 begin
59 readln(n,m);
60 built(1,1,n);
61 for i:=1 to m do
62 begin
63 readln(j,k,l);
64 case j of
65 0:begin
66 op(1,1,n,k,l);
67 end;
68 1:begin
69 writeln(cal(1,1,n,k,l));
70 end;
71 end;
72 end;
73 readln;
74 end.
75