I am a slow thinker, but had been moderately successful in competitive programming during high school days.
The trick is to code a lot outside of the competitions and know all these tricks, as well as to have common snippets of code in your fingertips.
I still find that experience quite useful in my day-to-day programming.