Is there any technique (encoding/compression/etc.) that can improve the quality of the foreground elements when such a background is present in the shot?
I don't know of any encoding algorithm that can differentiate between objects in a video and allocate different amounts of bits for those objects based on how important they are. That's not really how compression algorithms work. Maybe with machine learning we will get there eventually, but I'm pretty sure no such thing exists.
Those videos are uploaded by the original TV broadcaster (with access to the highest quality original video), and more or less top out looking like 480p, even when viewing at 720p or 1080p. The same quality issues appear in videos on the broadcaster's own site, so it's not just YouTube's compression going overboard:
The bad quality is caused by the low bitrate in combination with video content that can't be compressed very good (as explained in the video by Tom Scott). Another way to put this is the video has high entropy, i.e. more information than a regular video (without confetti, snow or something similar). To save a video with high entropy in the same quality as a video with low quality, you need a higher bitrate. So if you have control over the final video, just raise the bitrate and you will be fine. Another possibility is to use a variable bitrate. This way, the encoder can allocate a higher bitrate to the parts of the video with high entropy and a lower one for the parts with low entropy, thus raising the overall quality significantly.
If you upload to Youtube, there's nothing you can do. No matter how high the bitrate and quality of your original video, Yotube will compress it upon upload, making it look bad again. You could export your video in 4k, this might help since Youtube uses a higher bitrate for 4k video, ergo better quality. But if your original footage isn't shot in 4k, I wouldn't recommend that.
And I'm sure some people would also be interesting in any techniques that can be done at the time of filming that would produce better results, when they cannot change the content of the shot and have to deal with snow/confetti/animated LCD in the background.
What can you control?
If you want to avoid this mess, get the confetti out of the shot. Turn the LCD screen off. If you can't do that, change the composition and/or pespective so that less of that stuff is in your shot. Zoom in closer on the actors/dancers so they fill more of the screen, ergo less background noise.
But honestly, this is really a Youtube-specific problem because they use a terribly low bitrate for their encoding. I wouldn't compromise my video composition or content to avoid this problem. Just use a different hoster that encodes uploaded videos with higher bitrates such as Vimeo.