【Updated: 】
The amount the gauge increases depends on the number of people that participated in the race or battle.
Due to this, if there were not many people in the race or battle, even if you end up in 3rd place, it does not count as being in one of the top spots, and your grade may even decrease.
Also, in Team Games, members of the winning team will have their grade increase more easily, whereas the losing team will have their grade decrease more easily.
If your team loses, there are circumstances in which your grade will not change or decrease even if you yourself were in one of the top spots.
Please see the below as well for how grade works.
What factors affect my multiplayer grade?
How is my grade affected when I play a Team Game?