Don't know much about Rio, but what I have seen and heard elsewhere in Latin America over the years.
Often times organized crimes substitutes an absent government and enforce their own set of law and order in the community. They can't afford to just rob the people blind as sometimes portrayed in media. They rely on a somewhat sybmiotic relationship with the "citizens" to act as messengers, human surveillance cameras, warning them from unknown people entering, making false statements to the police etc. The gangs are often much more effective at crime prevention than the government, they often invest more locally than the government.
A big chunk of the violet crimes comes from conflicts between gangs. If you are part of the community and stay in line you can actually be pretty safe. As a tourist on the other hand, you are fair game.
Obviously, it is not everything is rosy and nice, but in my opinion one of the big challenges in facing organized crime, is that the governments don't actually have a believable improvement to offer to the people, so the locals will often defend the current situation.