莫队模板

function check(x1,y1,x2,y2:longint):boolean;
begin
  if (trunc(x1/sqrt(n))>trunc(y1/sqrt(n)))or(trunc(x1/sqrt(n))=trunc(y1/sqrt(n)))and(x2>y2) then
  exit(true)
  else
  exit(false);
end;
procedure sort(ll,rr:longint);
var i,j,x,y,z:longint;
begin
  i:=ll;
  j:=rr;
  x:=l[(ll+rr) div 2];
  z:=r[(ll+rr) div 2];
  repeat
  while check(l[i],x,r[i],z) do
  inc(i);
  while check(x,l[j],z,r[j]) do
  dec(j);
  if not(i>j) then
  begin
    y:=l[i];
    l[i]:=l[j];
    l[j]:=y;
    y:=r[i];
    r[i]:=r[j];
    r[j]:=y;
    y:=num[i];
    num[i]:=num[j];
    num[j]:=y;
    inc(i);
    dec(j);
  end;
  until i>j;
  if ll<j then
  sort(ll,j);
  if i<rr then
  sort(i,rr);
end;

 

posted @ 2018-02-04 15:43  qbwhtc  阅读(154)  评论(0编辑  收藏  举报