If you ride a bike, you should expect a flat. Maybe you don’t get a flat this year, but you could just as easily get three consecutive flats on your first three rides next year. It’s random, but one thing is for sure, it’s going to happen sooner or later.
For starters, you should prepare for flats by carrying all the tools necessary to change the tire, and you should practice changing flats until you feel comfortable with the process. And I recommend practicing with the back tire, because getting the chain back on the rear cassette can be tricky the first couple times. I recommend you carry a spare tube (2 if possible), 2 tire levers, and a CO2 kit. All this should fit nicely in most all bike saddle bags.
The only other advice I’ll offer up is that in a race situation flats are the worst. It’s really hard not to get frustrated. You just have to relax and change the tire quickly and smoothly. You won’t get your PR, and you will likely lose around 5 minutes minimum to your competitors, so just accept it and move on. Keep a positive mental attitude and finish strong. Don’t let a flat ruin your day. Your number just came up. It happens.
Here is a good video showing the proper way to change tire. FYI – the video is for clinchers, not tubulars.