The Preliminary Contest for ICPC China Nanchang National Invitational(Max answer)

本文深入探讨了倍增算法在解决特定类型数据结构问题中的应用,包括预处理和查询优化技术。通过实例讲解了如何利用倍增算法进行区间查询,以及如何结合栈结构处理序列中的元素,实现高效的最大值和最小值查询。文章详细介绍了算法的实现过程,包括初始化数组、更新状态和查询操作,为读者提供了完整的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接 https://nanti.jisuanke.com/t/38228

倍增nb

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const ll maxn = 5e5 + 10;
const ll mod = 1e9 + 7;

ll bl[maxn],br[maxn];
stack<pair<ll,ll> >s;
ll summi[maxn][30],summx[maxn][30],a[maxn];
ll askmi(ll l,ll r)
{
	ll len = log2(r - l + 1);
	return min(summi[l][len],summi[r - (1 << len) + 1][len]);
}

ll askmx(ll l,ll r)
{
	ll len = log2(r - l + 1);
	return max(summx[l][len],summx[r - (1 << len) + 1][len]);
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	
	ll n;
	cin >> n;
	for(int i = 1; i <= n; i ++)
	{
		cin >> a[i];
		summx[i][0] = summx[i - 1][0] + a[i];
		summi[i][0] = summx[i][0];
	}
	
	ll len = log2(n);
	for(int i = 1; i <= len; i ++)
	{
		for(int j = 1; j + (1 << i) - 1 <= n; j ++)
		{
			summx[j][i] = max(summx[j][i - 1],summx[j + (1 << (i - 1))][i - 1]);
			summi[j][i] = min(summi[j][i - 1],summi[j + (1 << (i - 1))][i - 1]);
		}
	}
	
	for(int i = 1; i <= n; i ++)
	{
		while(!s.empty() && s.top().second >= a[i])s.pop();
		if(s.empty())bl[i] = 1;
		else bl[i] = s.top().first + 1;
		s.push(make_pair(i,a[i]));
	}
	
	while(!s.empty())s.pop();
	
	for(int i = n; i >= 1; i --)
	{
		while(!s.empty() && s.top().second >= a[i])s.pop();
		if(s.empty())br[i] = n;
		else br[i] = s.top().first - 1;
		s.push(make_pair(i,a[i]));
	}
	
	ll ma = -1e18;
	for(int i = 1; i <= n; i ++)
	{
		if(a[i] > 0)
		{
			ll l = askmi(bl[i] - 1,i - 1);
			ll r = askmx(i,br[i]);
			ma = max((r - l) * a[i],ma); 
		}
		else if(a[i] < 0)
		{
			ll l = askmx(bl[i],i - 1);
			ll r = askmi(i,br[i]);
			ma = max((r - l) * a[i],ma);
		}
		else
		{
			ma = max((ll)0,ma);
		}
	}
	
	cout << ma << '\n';;
	
	return 0;
}

 

Sure, I'd be happy to give you some ideas for organizing a speech contest. Here are some suggestions: 1. Determine the theme and rules: Decide on the theme of the contest and the rules for participants. Will it be an open topic, or will there be a specific theme? What is the maximum length of the speech? Will there be any specific guidelines for language or content? 2. Decide on the judging criteria: Determine how the speeches will be evaluated. Will judges be looking for content, delivery, or both? Will there be a score sheet or rubric that judges will use to score the speeches? 3. Recruit judges: Find people who are qualified to judge the speeches. Ideally, they should have experience in public speaking or have a background in the theme of the contest. 4. Promote the contest: Advertise the contest to potential participants, such as students, professionals, or members of a specific community. Use social media, flyers, and other methods to get the word out. 5. Registration and selection: Set a deadline for registration and selection of participants. Consider having a preliminary round to narrow down the field before the final competition. 6. Prepare the venue: Ensure that the venue is suitable for the contest. Make sure that there is adequate seating, sound equipment, and lighting for the speakers. 7. Hold the contest: Set a date and time for the contest, and make sure that all participants and judges are aware of the schedule. Encourage audience participation and provide refreshments. 8. Award ceremony: After the contest, hold an award ceremony to recognize the winners and participants. Provide certificates or other prizes to the top performers. I hope these ideas help you in organizing a successful speech contest!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值