Intermediate Value Property + BV nearly everywhere = continuous? It is well known that a function $f:[a,b]\to\mathbb R$ which has the intermediate value property (i.e. if $a',b'\in[a,b]$, then for each $c$ between $f(a')$ and $f(b')$ there is some $x$ between $a'$ and $b'$ such that $f(x)=c$) cannot have jump discontinuities, and that a function $g:[a,b]\to\mathbb R$ of bounded variation can only have jump discontinuities. Therefore, a function having the intermediate value property and being of bounded variation must be continuous. I wonder if the BV-condition can be relaxed a little, so my question is:
Is there a discontinuous function $f:[a,b]\to\mathbb R$ and a function $g:[a,b]\to\mathbb R$ of bounded variation, such that $f$ has the intermediate value property and agrees with $g$ at every point of $[a,b]$ except at countably many?
Any hints/help is highly appreciated. Thanks in advance!
 A: Let $x\in[a,b]$ be a discontinuity of $f$.
We assume without loss of generality that $x\in(a,b)$, the case of the boundary can be dealt with similarly.
Since $g$ is of bounded variation, the limits $l=\lim_{y\to x^-}g(y)$ and $L=\lim_{y\to x^+}g(y)$ exist and are finite.
On the other hand, since $f$ is Darboux and discontinuous at $x$, at least one of $\lim_{y\to x^-}f(y)$ and $\lim_{y\to x^+}f(y)$ must not exist, say the latter.
We hence have that
\begin{align}\forall \epsilon>0,\,&\exists\delta>0,\,\forall y \in(x,x+\delta),\,\,|g(y)-L|<\epsilon\tag{1}\\
\exists \epsilon_0>0,\,&\forall\delta>0,\,\exists y \in(x,x+\delta),\,\,|f(y)-L|\geq\epsilon_0\tag{2}\end{align}
Take $\epsilon=\frac{\epsilon_0}{2}$ in $(1)$, so that there is some $\delta_0>0$ with the property that $|g(y)-L|<\frac{\epsilon_0}{2}$ whenever $y \in (x,x+\delta_0)$.
By $(2)$, there is some $y_1\in (x,x+\delta_0)$ with $|f(y_1)-L|\geq \epsilon_0$.
If $g=f$ except on a countable subset of $(x,x+\epsilon)$, there must be some $y_2\in(x,y_1)$ with $g(y_2)=f(y_2)$.
Hence, $|g(y_2)-L|=|f(y_2)-L|<\frac{\epsilon_0}{2}$.
Now, since $f$ is Darboux, it must assume all values between $f(y_1)$ and $f(y_2)$ on $(y_1,y_2)$.
In particular, it must assume an uncountable range of values $v$ with $\frac{\epsilon_0}{2}\leq |v-L|\leq \epsilon_0$.
This means there is some $y_3\in(y_2,y_1)\subset(x,x+\delta_0)$ with $\frac{\epsilon_0}{2}\leq |g(y_3)-L|\leq \epsilon_0$, which contradicts the defining property of $\epsilon_0$. $\square$
A: A function with IVP agreeing with a BV function except on a countable set must be continuous.  
Suppose that $f$ has IVP and agrees with a function $g$ except on a countable set, and that $f$ is discontinuous at some point $c\in[a,b]$.  It will eventually be shown that $g$ does not have BV.  
It can't be the case that both one-sided limits of $f$ exist at $c$ and equal $f(c)$; WLOG let's say $c>a$ and it's the left-hand side.  Then the negation of $\lim\limits_{x\to c-}f(x)=f(c)$ holds.  That is, there exists $\varepsilon>0$ such that for all $\delta>0$ there exists $x\in(c-\delta,c)$ with $|f(x)-f(c)|\geq \varepsilon$.    For such $x$, either $f(x)\geq f(c)+\varepsilon$, in which case $f((c-\delta,c))$ must contain $(f(c),f(c)+\varepsilon]$, or $f(x)\leq f(c)-\varepsilon$ and $f((c-\delta,c))$ contains $[f(c)-\varepsilon,f(c))$, by the IVP. In either case, after removing any countably infinite set from $(c-\delta,c)$, this still leaves infinitely many $t$ in that interval with $|f(t)-f(c)|>\frac23\varepsilon$, and infinitely many $t$ such that $|f(t)-f(c)|<\frac13\varepsilon$. (The image of a countable set is countable, and intervals in $\mathbb R$ are uncountable.)
Hence the same property must hold for $g$, namely that in every interval of the form $(c-\delta,c)$ there are points $s$ and $t$ such that $|g(s)-f(c)|>\frac23\varepsilon$, and $|g(t)-f(c)|<\frac13\varepsilon$.  By taking successively smaller $\delta$, we can arrange sequences of such $s$ and $t$, $(s_n)$ and $(t_n)$, with $s_1<t_1<s_2<t_2<s_3<\cdots$.  By taking partitions of $[a,b]$ including arbitrarily many of the $s_n$s and $t_ns$, it can be shown that the total variation of $g$ is larger than any arbitrary multiple of $\frac13\varepsilon$, hence must be infinite.
