The comments and the cited wiki page on decreasing rearrangement give
an expression for $g$ but little hints as to why it works.
In the following I will try to provide an explanation.
Assuming $f:[a,b]\rightarrow [c,d]$,
we define first the repartition function
$F: [c,d] \rightarrow [a,b]$:
$$ F(x) = a + m \{t\in [a,b] : f(t) >x \}, \; \; x\in [c,d].$$
(I have added $a$ to the result to map into the interval $[a.b]$).
$F$ is monotone decreasing and, what is crucial here,
right-continuous, since by
$\sigma$-additivity of the measure:
$$ F(x^+)-F(x)=\lim_{n\rightarrow \infty} F(x+\frac{1}{n}) -F(x) =
\lim_{n\rightarrow \infty} m \{t\in [a,b] : x+\frac{1}{n}\geq f(t) >x \}
= 0 .$$
The goal is to construct
a monotone decreasing function,
$g: [a,b]\rightarrow [c,d]$,
having the same partition function as $f$:
$$F(x) = a+ m\{ t\in [a,b]: g(t)>x\}, \; \; x\in [c,d].$$
Note first that when
$g$ is decreasing, $g(t)>x$ implies $g(s)>x$ for every
$s\in [a,t]$ so
the above condition is equivalent to:
$$ F(x) = \sup \{ t\in [a,b]: g(t)>x\}.$$
In the case that $F$ is a bijection from $[c,d]$ onto $[a,b]$,
we may as $g$ in the above just take the inverse of $F$.
Problems arise, however, when $F$ is not continuous or not
injective.
We claim that $g$ in any case
may be constructed in the completely symmetric fashion:
$$g(t) := \sup \{ x\in [a,b]: F(x)>t\}, \; \; t\in [a,b].$$
One may verify by $\epsilon$-$\delta$ argument that it satifies the
wanted relation but the logic may (in my opinon) be difficult
to digest for human beings.
So instead let me describe a different
conceptual approach, in which
the use of right-continuity will appear naturally:
Write $R=[a,b]\times [c,d]$ and define
$$ \Omega = \{ (t,x) \in R : F(x) \leq t \}$$
It is a subset of the rectangle having the properties:
(1) It is directed, i.e.:
$ (t,x)\in \Omega \Rightarrow [t,b]\times [x,d]\subset \Omega$. (Make a drawing!)
(2) It is a closed subset of $R$. (This follows from the
right-continuity of $F$).
Conversely, given a directed closed subset $\Omega$ of $R$ (i.e. having the above
two properties)
we may reconstruct a corresponding
$F$ (which becomes right-continuous because $\Omega$ is closed) by setting:
$$ F(x) = \sup\{t\in [a,b] : (t,x)\notin \Omega\}.$$
There is thus a bijection between a closed directed set $\Omega$ and
a corresponding decreasing right-continuous map $F: [c,d]\rightarrow [a,b]$.
The properties of the
set $\Omega$ is, however, completely symmetric in the way the
two coordinates are treated. So it is equally well in unique correspondance
with a function $g: [a,b]\rightarrow [c,d]$ where coordinates
have been exchanged and which therefore may
be constructed through:
$$g(t) =
\sup\{ x\in [c,d] : (t,x) \notin \Omega \} =
\sup\{ x\in [c,d] : F(x)>t \} $$
Because of the symmetry, the procedure for going from $g$ to $F$
is the very same with the variables exchanged, i.e.:
$$F(x) = \sup \{ t\in [a,b] : g(t)>x\} $$
But this was precisely
the wanted property of the partition function. Magic?