Cramps? During National XCM Championship

Sep 16, 2016
Today I raced in my country's XCM championships and the whole time I felt great but then after around 45 kilometers out of nowhere I got this insane pain in my right leg then after a couple seconds it was also in my left leg, I couldn't pedal at all, I just got off my bike and tried walking the short climb up but even walking was such a pain, I think it was a cramp and it was caused by dehydration since at about 3/4 of the second lap (25km per lap) I ran out of water, can anyone confirm this or tell me what it might be caused by? During the whole race I had 3 energy gels and only drank water. Fortunately someone came right by me and gave me water and helped me on but the pain kept coming back every couple minutes for the rest of the race. (Finished 7th after I was 3rd before the pain)

Also I do 4-5 hour rides from time to time so I think a 2.5 hour race shouldn't be a problem in terms of time/distance