标签:一起 var int read else div span code 方法
肥肠神奇的方法 :先把两个子序列‘合在一起’,再利用单调性求解。查找用二分
1 var 2 n,i,t,k:longint; 3 a,b,c,q,id:array[0..100005]of longint; 4 function find(l,r:longint):longint; 5 var mid:longint; 6 begin 7 while l<r do 8 begin 9 mid:=(l+r) div 2; 10 if q[mid]>c[i] then r:=mid else l:=mid+1; 11 end; 12 exit(l); 13 end; 14 begin 15 readln(n); 16 for i:=1 to n do begin read(a[i]);id[a[i]]:=i;end; 17 for i:=1 to n do begin read(b[i]);c[i]:=id[b[i]];end; 18 for i:=1 to n do 19 begin 20 if q[t]<c[i] then begin inc(t); q[t]:=c[i]; end 21 else begin k:=find(0,t); q[k]:=c[i];end; 22 end; 23 writeln(t); 24 end.
标签:一起 var int read else div span code 方法
原文地址:https://www.cnblogs.com/brilliant107/p/9404987.html