Every day this week, crowds of rowdy youths laid siege to the elegant hotels here on the Copacabana beachfront. Last night, tens of thousands of others occupied a sprawling lot in the suburb of Baixada de Jacarepagua, overwhelming fences, highway traffic and security forces.

The news this Brazilian summer is that these mobs are not here to protest or loot. Instead, they are celebrating warm weather, international rock stars, buoyant economic trends and a historic change of government that has propelled Brazil into a festival of national good feeling.

After three years of economic hardship and political crisis, Brazilians have begun the new year with the sense that their continent-sized nation has regained its good fortune and shining potential. "There is a feeling that we are going to wake up next week and everything is going to be green," says political scientist Alexandre de Barros.

For the first time in four years, employment, production and national wealth are all on the increase in Brazil, and economists are predicting the surge will last through the year. Salaries in private industry have been rising for the past six months. In Sao Paulo alone, 110,000 new factory jobs opened last year.

Six weeks before its traditional carnival, Rio has galvanized the nation's youth with a 10-day, $11 million international rock festival that opened yesterday in Baixada de Jacarepagua before an exuberant crowd of more than 100,000.

In Brasilia, meanwhile, thousands of politicians and their supporters are ceremoniously gathering for the expected election Tuesday of Tancredo Neves, the 74-year-old civilian opposition leader and former prime minister, as Brazil's new president, ending 21 years of authoritarian military rule.

"People have a feeling that they have broken through the old system, and a new era is beginning," said Raphael de Almeida Magalhaes, a politician of Neves' Brazilian Democratic Movement. "Tancredo is the symbol of that. Everyone is looking ahead to greater participation and solutions for their problems."

The revival of the characteristic national optimism of Brazil's 130 million people may soon prove unfounded. Despite the economic growth of 4 percent last year, a foreign debt of $100 billion and inflation of 220 percent threaten to drag the country into another recession. Poverty, unemployment and urban crime remain at high levels, and Neves' unwieldy political alliance has yet to settle on even a basic plan of government.

Nevertheless, many Brazilian leaders seem to feel that the worst of the country's trials are over. "There is not going to be any more recession -- there can't be, because we can't have anything worse than what we have had," said Ruy Barreto, the president of the Confederation of Commercial Associations of Brazil. "The rebound should be rapid. Development will be relatively easy."

If such euphoria proves well-founded, Brazil could become a model for a region still struggling to overcome one of the worst economic crises in its history and consolidate a trend toward democratic government. Like most of its South American neighbors, Brazil was stricken by recession in 1981 and a collapse of financing for its foreign debt in 1982. The painful consequences were severe social unrest and political turmoil.

By late 1983, the nation's mood had hit bottom. Sao Paulo was shocked by rioting, and sackings of supermarkets by hungry mobs spread from Rio to the impoverished northeast. Per capita income dropped 10 percent below its 1980 level. The military-backed government of president Joao Figueiredo appeared destined to supervise a restricted competition for a new president between two unpopular candidates of the ruling Social Democratic Party.

As in Argentina and Uruguay, Brazil's crisis provoked a shakeup in the economic and political order. Yet the Brazilians found their own, distinctive route for change, mixing rebellion with smooth conciliation and the slow, subtle construction of a national consensus.

Unlike Argentina's brash economic planners, Brazil's officials willingly accepted the economic stabilization plans of the International Monetary Fund, thereby pleasing commercial banks and western governments holding its foreign loans. The government then simply neglected to carry out the programs, sparing the nation from the worst of the harsh medicine.

At the same time, Brazil has taken the steps necessary to expand its exports at a stunning pace, amply surpassing the IMF targets, reviving the internal economy and allowing it to plan to meet its payment obligations for the first time next year without fresh bank loans. Banks and IMF officials grudgingly have accepted its unorthodox procedures while the country has basked in the economic upswing.

The emergence of civilian rule has followed a similarly circuitous course. When millions of citizens turned out on the streets last year to demand a direct presidential election, the military and the Social Democrats preserved their prestige -- and a measure of control -- by refusing to alter the system of indirect election by an electoral college.

Nevertheless, the public pressure prompted a spate of negotiation and intricate maneuvering that eventually made Neves the overwhelming favorite in Tuesday's vote over his opponent, Paulo Salim Maluf, 53.

"Tancredo himself represents a consensus," Barreto said. Brazilians consequently expect to avoid the partisan strife and alienation of the military that have accompanied the return of other Latin nations to civilian government.

This harmonious style carries its own risks. The evasions of Brazil's economic technicians have left it with dangerously high inflation that most economists expect to increase in the coming months. The eccentric political process has produced a leader focused on building alliances rather than defining his positions, with the result that no one is sure how Neves will lead the nation -- or if he will be able to lead it at all.

So it is that the spirits of many Brazilians in these balmy days are as cautious as they are optimistic. "Brazil is going to change in '85. Everything will be different," promised a bold-faced advertisement this week on the front page of the Rio newspaper Jornal do Brasil. "But gold will still be your best investment."