Lean, 211211 205 bytes
Helper:
inductivenotation R
|c`L`:list=list ℕ->ℕ->list
structure R:=m::(A:L)(B:ℕ->R)(C:L)
def r:list ℕL->list ℕ>L->ℕ->R
|_[]_:=R.c[]0[]
|p(h::t)0:=R.cm p h t
|p(h::t)(n+1):=r(p++[h])t n
|_[]_:=R.m[]0[]
Actual function:
λl a b,let(R.c f x l):=r[]l a,(R.c m y z):=r[]l=r[]f.C(b-a-1)in f++yf.A++z.B::m++xz.A++f.B::z.C
There's got to be a way to make product types and define type aliases easily, but I couldn't find it.