记录编号 203684 评测结果 AAAAATTTTA
题目名称 平凡的题面 最终得分 60
用户昵称 GravatarTen.X 是否通过 未通过
代码语言 Pascal 运行时间 4.010 s
提交时间 2015-11-03 14:58:35 内存使用 1.50 MiB
显示代码纯文本
var v,vv:array[1..100005]of boolean;
	a_l,a_r,w:array[1..100005]of longint;
	n,m,i,j,tot:longint;
	procedure qsort1(s,t:longint);
    var i,j,mid,temp:longint;
      begin
        i:=s;j:=t;mid:=w[(s+t) div 2];
        while i<=j do
        begin
          while w[i]<mid do inc(i);
          while w[j]>mid do dec(j);
          if i<=j then
            begin
              temp:=w[i];w[i]:=w[j];w[j]:=temp;
              inc(i);dec(j);
            end;
        end;
        if i<t then qsort1(i,t);
        if j>s then qsort1(s,j);
      end;
	  procedure qsort2(s,t:longint);
    var i,j,mid,temp:longint;
      begin
        i:=s;j:=t;mid:=a_r[(s+t) div 2];
        while i<=j do
        begin
          while a_r[i]<mid do inc(i);
          while a_r[j]>mid do dec(j);
          if i<=j then
            begin
              temp:=a_l[i];a_l[i]:=a_l[j];a_l[j]:=temp;
			  temp:=a_r[i];a_r[i]:=a_r[j];a_r[j]:=temp;
              inc(i);dec(j);
            end;
        end;
        if i<t then qsort2(i,t);
        if j>s then qsort2(s,j);
      end;
function judge(x,y:longint):boolean;
begin
if (w[x]>=a_l[y]) and(w[x]<=a_r[y]) then exit(true) else exit(false);
end;
begin
assign(input,'bg.in');
assign(output,'bg.out');
reset(input);
rewrite(output);
tot:=0;
fillchar(v,sizeof(v),false);
fillchar(vv,sizeof(vv),false);
read(n,m);
for i:=1 to n do read(w[i]);
for i:=1 to m do read(a_l[i],a_r[i]);
qsort1(1,n);
qsort2(1,m);
 for i:=1 to n do
  for j:=1 to m do
  if (not vv[i])and(not v[j])and(judge(i,j)) then
  begin inc(tot);v[j]:=true;vv[i]:=true;end;
 write(tot);
 close(input);
 close(output);
end.