For a proper representation of the causal structure of the world, it is adaptive to consider both evidence for and evidence against causality. To take punishment as an example, the causality of a stimulus is unlikely if there is a temporal gap before punishment is received, but causality is credible if the stimulus immediately precedes punishment. In contrast, causality can be ruled out if the punishment occurred first. At the behavioral level, this is reflected in the associative principle of timing-dependent valence reversal: aversive memories are formed when a stimulus occurs before the punishment, whereas memories of appetitive valence are formed when a stimulus is presented upon the relieving termination of punishment. We map the temporal profile of memories induced by optogenetic activation of the PPL1-01 neuron in the fly