The only thing you can do in these cases is to focus on your work, and the tasks that you need done, and completely ignore these people. How easy this is, does depend on the type of job you have to do. Anyway, not much you can do about the situation you describe. Be professional, focus on your job and ignore what they say. If you need to work with them just focus on the professional part of the relationship, and avoid all sort of small talk on a personal level.
In addition, although in theory people and companies advertise teamwork mentality, in reality there is a lot of competition going on even within people that belong in the same team. In our world of selfishness, there is no selflessness at work.
I could tell you to set a good example and be the one that helps etc, but that does not work with people like that. They will never change, and you will never be a person they look up to.
Do not change to the worse because of them.