Existence of a special kind of continuous injective function $f\colon A \to \mathbb R$, where $A$ is countable, relating to connectedness Let $A \subseteq \mathbb R$ be a countable set ($A$ induced with usual subspace topology), then does there necessarily exist a continuous injective function $f\colon A \to \mathbb R$ such that for every $a \in A$, there exist a connected subset $S\subseteq \mathbb R$ (with more than one point) such that $\{a\}=f^{-1}(S)$ ?I can prove the existence of such function if continuity is not required; if continuity is also required I am totally stuck. Please help. Thanks in advance
 A: Let $A=\{a_1,a_2,\ldots\}$ be a countable metric space.
Let $D=\{\,d(a_i,a_j):i,j\in\Bbb N\,\}$.
For functions $g\colon \Bbb N\to\Bbb R$, $r\colon \Bbb N\to (0,\infty)$ consider the following predicates:
$$\begin{align}\alpha(n,m)&\iff  n\ne m\to g(m)\notin \bigl(g(n)-(1+\tfrac1m)r(n),g(n)\bigr]\\  
\beta(n,m)&\iff 0<d(a_m,a_n)<r(n)\to |g(m)-g(n)|<d(a_m,a_n)\\
\gamma(n)&\iff r(n)\notin D\\
\delta(n,m)&\iff  m>n\to r(m)<|d(a_n,a_m)-r(n)|
\end{align}$$
We shall try below to find $g,r$ such that 
$$ \tag1\forall n\in \Bbb N\colon \forall m\in\Bbb N\colon \alpha(n,m)\land \beta(n,m)\land \gamma(n)\land \delta(n,m).$$
After that we can define $f\colon A\to \Bbb R$, $a_n\mapsto g(n)$.
Then $\alpha$  guarantees that $f$ is injective and has the special property required in the OP (where for $a_n\in A$ we can let $S=(g(n)-r(n),g(n)]$).
Then $\beta$ implies that $f$ is continuous. The properties $\gamma$ and $\delta$ are used only to facilitate the construction.
Note that the conditions on $r$ are such that it is always possible to make $r(n)$ a bit smaller mostly without violating any of the conditions that held for the larger value: For $\gamma$ note that it is always possible to avoid the countable set $D$; for  $\alpha(n,m)$ and $\beta(n,m)$, decreasing $r(n)$ only makes the statement weaker; likewise $\delta(\cdot,n)$ gets weaker if we decrease $r(n)$ and only $\delta(n,m)$ with $m>n$ might be affected negatively.
We shall use this observation in our recursive construction.
(The appropriate way to do the following recursion would be to define sequences of functions that agree on initial segments and so on, but I'll stick to the suggestive "modify the function value" parlance). Assume we have already defined $g,r$ for all arguments $<N$ and that the listed properties hold at least when $n,m<N$, i.e., 
$$\tag2 \forall n<N\colon \forall m<N\colon \alpha(n,m)\land \beta(n,m)\land \gamma(n)\land \delta(n,m).$$
We want to define $r(N)$ and $g(N)$ in such a way that 
$$\tag3 \forall n\le N\colon \forall m\le N\colon \alpha(n,m)\land \beta(n,m)\land \gamma(n)\land \delta(n,m).$$
According to the remark above, it is safe to start with a tentative value for $r(N)$ and decrease it repeatedly (finitely many times).
So let us first impose the condition that
$$ 0<r(N)<d(a_i,a_N)\quad \text{for }i=1,\ldots,N-1.$$
This grants us that (no matter how we will pick $g(N)$ later)
$$ \beta(N,i)\quad\text{for }i=1,\ldots,N.$$
Next let us impose
$$ 0<r(N)<|d(a_i,a_N)-r(i)|\quad \text{for }i=1,\ldots,N-1.$$
(Note that the right hand side is positive per $\gamma(i)$).
This grants us
$$ \delta(N,i)\land \delta(i,N)\quad\text{for }i=1,\ldots,N.$$
Before we decrease $r(N)$ further, we shall pick an appropriate $g(N)$.
Let $$J=\{\,j:1\le j<N, d(a_N,a_j)<r(j)\,\}.$$
We automatically have $\beta(j,N)$ for $j<N$ with $j\notin J$.
So in particular if $J=\emptyset$, we are done with $\beta$ and can pick $g(N)$ arbitrarily, say (in order to avoid problems with $\alpha(i,N)$ for $1\le i<N$) we let $g(N)=1+\max\{g(1),\ldots,g(N-1)\}$ in that case.
So suppose $J\ne \emptyset$ and let $k = \max J$.
Consider $j\in J$ with $j< k$.
Then $r(k)<|d(a_j,a_k)-r(j)|$ per $\delta(j,k)$, i.e., $r(j)+r(k)<d(a_j,a_k)$ or $r(j)>r(k)+d(a_j,a_k)$.
Because (and this the only place where we really use that $d$ is a metric) $d(a_j,a_k)\le d(a_N,a_j)+d(a_N,a_k)<r(j)+r(k)$, it must be the case that  $r(j)>r(k)+d(a_j,a_k)$. Thus from $\beta(j,k)$, 
$$\tag 4|g(k)-g(j)|<d(a_j,a_k)<r(j)$$ and hence from $\alpha(j,k)$ we get 
$$\tag 5g(j)<g(k).$$
Thus $$g(j)\stackrel{(5)}<g(k)\stackrel{(4)}<g(j)+r(j).$$
As a consequence, if we pick $g(N)$ from the non-empty open interval $(g(k),\min\{\,g(j)+r(j):j\in J\,\})$ (and different from $g(1),\ldots, g(N-1)$), we obtain
$$\beta(i,N)\quad\text{for }i=1,\ldots, N.$$
Additionally, let us pick $g(N)$ so close to $g(k)$ that 
$$ g(N)-g(k)<(\tfrac 1k-\tfrac 1N)r(n)\quad \text{for }n=1,\ldots, N-1.$$
By this, for any $n<N$ with $g(n)-(1+\tfrac 1N)r(n)<g(N)$ we would also have $g(n)-(1+\tfrac 1k)r(n)<g(k)$, hence $g(N)>g(k)\ge g(n)$ per $\alpha(n,k)$. 
We conclude that by this choice we have
$$ \alpha(n,N)\quad \text{for }n=1,\ldots, N.$$
Now that we have determined $g(N)$, we impose the additional constraints
$$ 0<r(N)<\frac m{m+1}(g(N)-g(m))\quad\text{for }m=1,\ldots,N-1\text{ with }g(m)<g(N)$$
and achieve
$$ \alpha(N,m)\quad \text{for }m=1,\ldots,N-1.$$
Finally, decrease $r(N)$ a bit more if necessary in order to avoid $D$ and thus make $\gamma(N)$ come true.
This concludes the recursive definition of $g$ and $r$ such that $(3)$ holds, given $(2)$.
Thus ultimately $(1)$ holds.
As remarked above, this proves

Theorem. Let $(A,d)$ be a countable metric space. Then there exists a continuous map $f\colon A\to\Bbb R$ such that for each $a\in A$ there exists a half-open interval $S=(u,v]\subset\Bbb R$ with $f^{-1}(S)=\{a\}$.

A: Disclaimer: I mixed up $∀a$ and $∃a$. But I decided to post anyway since it was already written and hey, maybe it isn't useless.
Assume w.l.o.g. that $0\in A$. (Otherwise shift it by an offset)
Then we can define $$f_λ:A → ℝ, a ↦ \begin{cases}a, &\text{if $a<0$}\\
0, &\text{if $a=0$}\\
-λa, &\text{if $a>0$}\end{cases}$$
for some $λ > 0$. This map is always continuous, and has $f^{-1}([0, ∞)) = {0}.$
But it fails to be injective for some $λ$. For how many does it fail? There are countable × countable ways to map on of the points of A to some other point of A using a λ stretching factor. This means, almost all real $λ$ will do the job and yield a continuous injective map from $A$ to $ℝ$.
A: Look at $ℚ \subset ℝ$, there is no continuous injective map $f:ℚ →ℝ$ which fulfills your conditions.
Lemma: If $f^{-1}(S) = \{a \in ℚ\}$ and $f(a), f(a)+ε \in S$ for $ε > 0$ and $S$ connected then $f(A) \subset (-∞, f(a)]$.
Proof: As both $(-∞, a)\cap ℚ$ and $(a, ∞)\cap ℚ$ are connected, their images must each lay in one connected component of $ℚ$. Some number larger than $a$ and some number smaller than $a$ must have it's image under f closer than $ε$ to a, thus in $(-∞, f(a))$. Consequently, $f(A) \subset (-∞, f(a)]$.
A similar statement holds for $f(a'), f(a')-ε \in S$, then $f(A) \subset [f(a'), ∞)$.
In conclusion, any continuous map $f:ℚ → ℝ$ has at most two values $q, q' \in ℚ$ for which your condition holds.
A: Maybe someone can finish this: It's not hard to show, based on the sort of incomplete proofs we've seen, that every point of $A$ must be a strict local extremum for $f$ (note that an isolated point of $A$ is vacuously a local extremum).
That seems impossible for a continuous function on $\Bbb Q$ ???
If that's not clearly impossible, note that the union of two nowhere dense sets is nowhere dense. So (perhaps replacing $f$ by $-f$) we could obtain a countable set $A\subset (a,b)$ with $A$ dense in $(a,b)$ and a continuous function $g$ defined on $A$ so that every point of $A$ is a strict local maximum. Surely that's impossible?
A: Okay, this is incomplete and hand wavy but:
For a dense real subset A (wolog $\mathbb Q$) I think we can prove a quasi Intermediate value Thereom: If continuous $f: \mathbb Q \rightarrow \mathbb R$. for $q, r \in A$ for any real $t$ between  $f(q)$ and $f(r)$ and any real $\epsilon > 0$, there exists a $v \in A$ between $q$ and $r$ where $|f(v) - t| < \epsilon$
Then an immediate corollary is that any continuous injective function is either increasing or decreasing.
Then ......
Let $f:\mathbb Q \rightarrow \mathbb R$ be continuous with the condition.
Let $r \in \mathbb Q$ Let $f(r) \in S_r$; a connected set such the $f^{-1}(S_r) = \{r\}$ with an element $y \in S_r; y \ne f(r)$. 
Wolog $f(r) < y$ so $[f(r), y] \subset S_r$ and this interval contains no $f(q); q \in A; q \ne r$.
Let $\epsilon = |f(r) - y|$.  As f is continuous, there is a $\delta > 0$ such that $q \in (r - \delta, r + \delta)\cap \mathbb Q$ (of which there are infinite) then $f(q) \in (f(r)-\epsilon, f(r) + \epsilon = y)$ but $f(q) \not \in [f(r), y]$ so $f(q)  \in (f(r)-\epsilon, f(r))\subset S_r$.  
That will apply for  $q_1 \in (r - \delta, r)$ and $q_2 \in (r, r + \delta); q_1, q_2 \in \mathbb Q$. 
Thus we have the contradiction: $q_1 < r < q_2$ but $f(q_1)$ and $f(q_2)$ are both less than $f(r)$ so $f$ is not increasing nor decreasing.
