They use computers for the effect you're talking about. Nascar has done it for years (no need to paint logos on the grass when you can have a computer just place one on the screen, and even change it every lap). My father's old company makes the semiconductors used in the computers that do all that fancy stuff, and he tried explaining to me once how these work, so I'll try to remember:
On the field or track, there are several devices that serve as reference points in a computer program that is being fed the broadcast picture. The position of these devices is kept track of geometrically, in 3d space. The computer then applies a texture map to a representative polygon, with the vertexes being the little devices on the track. This way, as the camera pans left and right, the computer rotates the polygon in its program, while applying/masking it to the broadcast image. The effect is seamless. Now concerning the manner in which the skaters can zoom over the flags and not have the image be pasted on top of them.... If I remember correctly, the vertex devices can also emit a signal or a type of electromagnetic radiation on a plane. Naturally, the light cannot penetrate solid objects. This way, the computer only fills in the texture where it detects the special "light".
Again, that's how I remember it being explained to me. I'm not sure that's the exact manner, but I think the general idea is the same. Not really my area of expertise. =) If anyone else can add to/correct me, please do. Thanks.