# BZOJ1609: [Usaco2008 Feb]Eating Together麻烦的聚餐

## 1609: [Usaco2008 Feb]Eating Together麻烦的聚餐

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 938  Solved: 562
[Submit][Status]

5
1
3
2
1
1

1

## Source

 1 uses math;
2 var a,sta:array[0..100001] of longint;
3     i,top,n,j:longint;
4 function search1(x:longint):longint;
5  var l,r,mid:longint;
6  begin
7  l:=1;r:=top;
8  while l<>r do
9   begin
10   mid:=(l+r) div 2;
11   if sta[mid]>x then r:=mid else l:=mid+1;
12   end;
13  exit(l);
14  end;
15 function lis1:longint;
16   begin
17   top:=1;sta[1]:=a[1];
18   for i:=2 to n do
19    begin
20    if a[i]<sta[1] then j:=1
21    else if a[i]>=sta[top] then j:=top+1
22    else j:=search1(a[i]);
23    if j>top then begin inc(top);sta[top]:=a[i];end;
24    if a[i]<sta[j] then sta[j]:=a[i];
25    end;
26   exit(top);
27  end;
28 function search2(x:longint):longint;
29  var l,r,mid:longint;
30  begin
31  l:=1;r:=top;
32  while l<>r do
33   begin
34   mid:=(l+r) div 2;
35   if sta[mid]<x then r:=mid else l:=mid+1;
36   end;
37  exit(l);
38  end;
39 function lis2:longint;
40   begin
41   top:=1;sta[1]:=a[1];
42   for i:=2 to n do
43    begin
44    if a[i]>sta[1] then j:=1
45    else if a[i]<=sta[top] then j:=top+1
46    else j:=search2(a[i]);
47    if j>top then begin inc(top);sta[top]:=a[i];end;
48    if a[i]>sta[j] then sta[j]:=a[i];
49    end;
50   exit(top);
51  end;
52 begin
53   assign(input,'input.txt');assign(output,'output.txt');
54   reset(input);rewrite(output);
59 end.