Using multiple Mega controllers on a large model railway

Certainly, I'd like to have as much in common as possible to make coding easier. So let's start with the termini.

If I have, for example, six terminus platforms plus another 20 or so sidings, I'd need 26 IR sensors and 26 LEDs on my control panel. Then, when a track is occupied the LED would illuminate and stay illuminated until the train vacates the section.

So presumably I'd write the code once and wire up the necessary IR sensors and LEDs?

Tell me, do the Megas remember their programming when the power is turned off and back on again, or do they need to remain powered continuously?

Ideally, I'd like to turn off the power after an operating session then turn it back on and have all the sensors identify which tracks are occupied and illuminate the required LEDs on the panel.