传送门 显然一个数最多对5个位置产生影响。 直接匹配,并且用树状数组求出前缀最大值就可以实现了
uses math;
var
a,b:
array [
0..
100005]
of longint;
f:
array [
0..
100005,
0..
5]
of longint;
n,i,x,j:longint;
function low(x:longint):longint;
begin exit(x
and (x
xor (x-
1)));
end;
function get(x:longint):longint;
var s:longint;
begin
s:=
0;
while (x<>
0)
do begin s:=max(s,b[x]); x:=x-low(x);
end;
exit(s);
end;
procedure ins(x,y:longint);
begin while (x<=n*
5)
do begin b[x]:=max(b[x],y); x:=x+low(x);
end;
end;
begin
read(n);
for i:=
1 to n*
5 do read(a[i]);
for i:=
1 to n*
5 do begin read(x); inc(f[x,
0]); f[x,f[x,
0]]:=i;
end;
for i:=
1 to n*
5 do
for j:=
5 downto 1 do
ins(f[a[i],j],get(f[a[i],j]-
1)+
1);
write(get(n*
5));
end.
转载请注明原文地址: https://ju.6miu.com/read-673575.html