Axioma, 439 bytes
c:=0;s(x,y)==(free c;if x.1=%i and y.2=%i then(x.2<y.1=>return true;x.2>y.1=>return false;c:=1;return false);if x.2=%i and y.1=%i then(x.1<y.2=>return true;x.1>y.2=>return false;c:=1;return false);if x.1=%i and y.1=%i then(x.2<y.2=>return true;x.2>=y.2=>return false);if x.2=%i and y.2=%i then(x.1<y.1=>return true;x.1>=y.1=>return false);false);r(a,b)==(free c;c:=0;m:=[[%i,j] for j in a];n:=[[i,%i] for i in b];r:=merge(m,n);sort(s,r);c)
esto convierte la primera lista en una lista como [[i, 1], [i, 2] ...] la segunda lista en una lista como [[1, i], [0, i] ...] donde i es la variable imaginaria que fusiona la lista 2, y hace un tipo que encontraría si hay un elemento de la lista 1 en la lista 2, por lo que es al final O (N log N) donde N = longitud lista 1 + longitud lista 2
sin golf
-- i get [0,0,1,2,3] and [0,4,6,7] and build [[%i,0],[%i,0],[%i,1],[%i,2] [%i,3],[0,%i],..[7,%i]]
c:=0
s(x:List Complex INT,y:List Complex INT):Boolean==
free c -- [%i,n]<[n,%i]
if x.1=%i and y.2=%i then
x.2<y.1=> return true
x.2>y.1=> return false
c:=1
return false
if x.2=%i and y.1=%i then
x.1<y.2=>return true
x.1>y.2=>return false
c:=1
return false
if x.1=%i and y.1=%i then
x.2< y.2=>return true
x.2>=y.2=>return false
if x.2=%i and y.2=%i then
x.1< y.1=>return true
x.1>=y.1=>return false
false
r(a,b)==
free c
c:=0
m:=[[%i, j] for j in a]
n:=[[ i,%i] for i in b]
r:=merge(m,n)
sort(s, r)
c
resultados
(12) -> r([1,2,3,4,-5], [5,7,6,8]), r([],[0]), r([],[]), r([1,2],[3,3]), r([3,2,1],[-4,3,5,6]), r([2,3],[2,2])
Compiling function r with type (List PositiveInteger,List Integer)
-> NonNegativeInteger
Compiled code for r has been cleared.
Compiled code for s has been cleared.
Compiling function r with type (List PositiveInteger,List
PositiveInteger) -> NonNegativeInteger
Compiled code for r has been cleared.
Compiling function s with type (List Complex Integer,List Complex
Integer) -> Boolean
Compiled code for s has been cleared.
(12) [0,0,0,0,1,1]
Type: Tuple NonNegativeInteger
no entiendo por qué "borra" el código para r y s ...
O(n log n)
es factible en general, pero la aclaración sobre el manejo solo de enteros nativos significa que en algunos idiomas con rangos de enteros limitados es posible una solución lineal (por ejemplo, mediante una tabla de búsqueda de tamaño 2 ^ 64)