Within each chain, assign positions from top to bottom. Let pos[v] be the position of node v in its chain, starting from 0. The topmost node in a chain has pos=0. As you DFS, maintain a counter chain_pos[c] for each chain c. When you visit node v in chain c, set pos[v] = chain_pos[c] and increment chain_pos[c].
Now each node has two coordinates: which chain it is in via chain[v], and where in that chain via pos[v]. This lets you map tree nodes to segment tree indices.