RIO DE JANEIRO — In the hills that hug Maracana Stadium, many Brazilians saw the flash and glitz of the opening ceremony for the Olympics from rooftops with exposed wiring and water pipes, amid trash-filled streets separated from the spectacle by a highway and train tracks.

Mangueira is but one of the thousand favelas in Rio de Janeiro, a slum marred by gang violence and poverty that sits squarely in the shadow of the pageantry of South America’s first Olympic Games. In this neighborhood of tattered homes, the next two weeks are a visceral reminder of the lines dividing the city’s haves and have-nots, and the opening gala just down the road punctuated those differences with every crackle and pop.

“The poor, we don’t really get to experience the Olympics. We are close in distance, but far away,” said Luiz Alberto Araujo, a 30-year-old doorman who works in the posh Ipanema beach but lives in the slums. “We still have fun, but this party is for foreigners, for the rich.”

Araujo watched the gala from the rooftop of a lime green house high on a hill in Mangueira, occasionally staring in silence at the stadium where, inside, athletes and fans cheered a supermodel strolling across a stage and Grammy-winning musicians performing samba.

Even from afar, the party was a momentary distraction for many of Mangueira’s 40,000 or so souls, offering a brief respite from the country’s persistent economic and political woes.

But they warned: Don’t confuse temporary joy with lasting satisfaction.

“I like having my family over. Of course, it would be a lot better to be right there,” Sandra Prado, a teacher, said as she pointed toward the Maracana. “But those prices are impossible for us.”

Prado and her family invited Araujo and others to gather to watch the ceremony from a distance. They drank beer and shared fried snacks while their children stayed glued to a television screen, awed by the special effects and the acrobatics of the performers. At one point during the show, dancers jumped over colorful shacks — meant to represent the city’s slums — and Araujo shouted: “It’s favela time! Now, we have to duck when there’s a shooting.”

When a song they all knew was performed inside the stadium, the women gathered at Prado’s sang along: “All I want is to be happy/ to roam free in the favela where I was born/ and to be proud/ and feel like us poor people have our own place.”

For the poor, the celebration that launched the coming competition was far out of reach financially. Ticket prices for the opening ceremony ranged from about $63 to $1,400. A minimum-wage worker in Brazil takes home some $55 a week.

“It is scandalous that ticket prices cater to very few higher-income residents and that the bulk of profits will leave the country,” said Bruno Carvalho, a Princeton University professor and author of the book “Porous City: A Cultural History of Rio de Janeiro.” ”It was as if many Brazilians found out that they were hosting a global party to which only a select few had been invited.”

From a balcony in Mangueira, Adriana Santos, a 34-year-old dental secretary, celebrated the opening of the games with her sister’s family and mother. Like many Brazilians who have protested for improvements in education and health care, Santos said her country’s leaders should focus on fixing economic woes rather than staging mega sporting events.

Brazil is suffering its worst economic crisis in decades. Only two years ago, the nation also hosted the 2014 FIFA World Cup.

“It’s not worth it,” said Santos.

Still, others couldn’t help but feel a touch of pride when the stadium that serves as their backyard lit up in a stunning fireworks display. Many grabbed their smartphones and tried to shoot selfies with Maracana sparkling in the background, but most of the photos were too blurry or dark.

Deisi Alves, a 46-year-old maid, said she would forever cherish watching the ceremony. She took it all in with her 19-year-old son and nieces in the living room of a home where half of the floor is tile, and the rest concrete or dirt.

“I know I am not there. With the money of one ticket, I could finish my home,” she said. “But at least I can watch it from here, with this view and my loved ones.”

Watch: Rio opens the Olympics with rubber bullets and tear gas