What if you're trying to solve a block and someone else solves at first, was all your time wasted?
Effectively, yes. Mining is a race, winner (of the block) takes all.
Fascinating discussion. I was not aware of this.
Now, I feel like I'm at the racetrack.

It is incorrect (and a common misconception). Nothing is wasted when someone else solves a block because there is no "progress" towards a block. Each hash is like a lottery ticket. It either wins or it loses. Nothing more. Having a thousand losing tickets means they are still losers regardless of if someone else wins or not.
If you mine a quadrillion hashes that fail to meet the difficulty target, you are no "closer" to solving a block then when you first started. Each hash is an independent roll of the dice. It either solves the block or it doesn't.