The cramps can be caused due to anaerobic respiration in the muscles and lactic acid formation.
During intense physical activity the muscles become deprived of oxygen, in this condition, anaerobic respiration takes place in the muscle cells causes the formation of the lactic acid.
The physical training increases the strength of the muscles, which can help the muscles not to get tired easily. that is why, physical training is required before any marathon.