vijos p1737(选择客栈)
不知道是什么算法
1 program p1737; 2 var 3 i,j,k,l,h,w,left,right,b,ans,n,x,y,num,pmin:longint; 4 c,p,s:array[0..200010] of longint; 5 q:array[0..51,1..200010] of longint; 6 function haha(a,b:longint):boolean; 7 var 8 i:longint; 9 begin 10 for i:=a to b do 11 if p[i]<=pmin then begin haha:=true; break; end; 12 if p[i]>pmin then haha:=false; 13 end; 14 begin 15 ans:=0; 16 read(n,num,pmin); 17 for i:=1 to n do 18 begin 19 read(c[i],p[i]); 20 inc(s[c[i]]); 21 q[c[i],s[c[i]]]:=i; 22 end; 23 for i:=0 to num-1 do 24 for j:=1 to s[i]-1 do 25 begin 26 for b:=j+1 to s[i] do 27 begin 28 x:=q[i,j]; 29 y:=q[i,b]; 30 if (x<>y)and (haha(x,y)=true) then begin inc(ans); break; end; 31 end; 32 ans:=ans+s[i]-b; 33 end; 34 write(ans); 35 end.