题解:首先对这个出题人表示严重吐槽——假如存在两个并列第一多的城市,那么不是不应该第一第二都取这个值么?我这么做结果WA得很惨,然后我再加了个等号让第一第二可以取一样的值,然后就AC了!?!?对这题的题目表述表示不解。。。汗
1 type vet=record
2 a1,a0:longint;
3 end;
4 var
5 i,j,k,l,m,n:longint;
6 a2:vet;
7 a:array[0..500050] of vet;
8 d:array[0..500050] of longint;
9 c:array[0..10] of longint;
10 procedure swap(var x,y:longint);inline;
11 var z:longint;
12 begin
13 z:=x;x:=y;y:=z;
14 end;
15 function max(x,y:longint):longint;inline;
16 begin
17 if x>y then max:=x else max:=y;
18 end;
19 function min(x,y:longint):longint;inline;
20 begin
21 if x<y then min:=x else min:=y;
22 end;
23
24 function merge(a2,a3:vet):vet;inline;
25 var i,j,k,l:longint;a4:vet;
26 begin
27 c[1]:=a2.a0;c[2]:=a2.a1;
28 c[3]:=a3.a0;c[4]:=a3.a1;
29 a4.a0:=0;a4.a1:=0;
30 for i:=1 to 4 do
31 begin
32 if c[i]>=a4.a0 then
33 begin
34 a4.a1:=a4.a0;
35 a4.a0:=c[i];
36 end
37 else
38 begin
39 if (c[i]>a4.a1) and (c[i]<a4.a0) then a4.a1:=c[i];
40 end;
41 end;
42 exit(a4);
43 end;
44 procedure built(z,x,y:longint);inline;
45 begin
46 if x=y then
47 d[x]:=z
48 else
49 begin
50 built(z*2,x,(x+y) div 2);
51 built(z*2+1,(x+y) div 2+1,y);
52 end;
53 a[z].a0:=0;a[z].a1:=0;
54 end;
55 procedure doit(x,y:longint);
56 begin
57 x:=d[x];
58 a[x].a0:=a[x].a0+y;a[x].a1:=0;
59 while x>1 do
60 begin
61 a[x div 2]:=merge(a[x],a[x+1-2*(x mod 2)]);
62 x:=x div 2;
63 end;
64 end;
65 function cal(z,x,y,l,r:longint):vet;
66 var a3,a2:vet;
67 begin
68 if l>r then
69 begin
70 a2.a0:=0;
71 a2.a1:=0;
72 exit(a2);
73 end;
74 if (x=l) and (y=r) then exit(a[z]);
75 exit(merge(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)));
76 end;
77 begin
78 readln(n);
79 built(1,1,n);
80 while not(eof) do
81 begin
82 readln(j,k,l);
83 case j of
84 1:doit(k,l);
85 2:begin
86 a2:=cal(1,1,n,k,l);
87 writeln(a2.a0-a2.a1);
88 end;
89 end;
90 end;
91 readln;
92 end.