The Preliminary Contest for ICPC China Nanchang National Invitational I : Max answer

https://nanti.jisuanke.com/t/38228

给你一个序列,让你求出一个连续子序列,序列最小值 乘 序列和最大, n5e5, a[i] : [-1e5, 1e5];

只有正数就直接单调栈了,不会看这https://blog.youkuaiyun.com/swunHJ/article/details/89441597

考虑存在负数的情况:

如果a[i]是正的,那就在[l[i] - 1, i-1]这段找个最小的前缀和,在[i, r[i]]这段找个最大的前缀和,相减乘一下维护答案就好了

如果a[i]是负的,那就在[l[i] - 1, i -1]这段找个最大的前缀和,在[i, r[i]]这段找个最小的前缀和,相减乘一下维护答案就好了

没了

转换成了单调栈+RMQ问题,显然可以用线段树,但是直接st做更好写一点

int a[maxn], l[maxn], r[maxn];
ll sum[maxn], stmx[maxn][23], stmn[maxn][23];
int n;

stack<int> st;

void init(){
	rep(i, 0, n) stmx[i][0] = stmn[i][0] = sum[i];
	for(int j = 1; (1 << j) <= n + 1; j++){
		for(int i = 0; i + (1 << j) - 1 <= n; i++){
			stmx[i][j] = max(stmx[i][j-1], stmx[i+(1<<(j-1))][j-1]);
			stmn[i][j] = min(stmn[i][j-1], stmn[i+(1<<(j-1))][j-1]);
		}
	}
	rep(i, 1, n){
		while(!st.empty() && a[i] <= a[st.top()]) st.pop();
		if(st.empty()) l[i] = 1;
		else l[i] = st.top() + 1;
		st.push(i);
	}
	while(!st.empty()) st.pop();
	Rep(i, n, 1){
		while(!st.empty() && a[i] <= a[st.top()]) st.pop();
		if(st.empty()) r[i] = n;
		else r[i] = st.top() - 1;
		st.push(i);
	}
}

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

ll askmn(int l,int r){
	int k=log2(r-l+1);
	return min(stmn[l][k],stmn[r-(1<<k)+1][k]);
}

int main()
{
	scanf("%d",&n);
	rep(i, 1, n) scanf("%d", a + i), sum[i] = sum[i-1] + a[i];
	init();
	ll ans = -INF;
	rep(i, 1, n){
		if(a[i] < 0){
			ll l2 = askmx(l[i] - 1, i - 1), r2 = askmn(i, r[i]);
			ans = max(ans, 1ll * (r2 - l2) * a[i]);
		} else if(a[i] > 0){
			ll l2 = askmn(l[i] - 1, i - 1), r2 = askmx(i, r[i]);
			ans = max(ans, 1ll * (r2 - l2) * a[i]);
		} else ans = max(ans, 0ll);
	}
	printf("%lld\n", ans);
	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、付费专栏及课程。

余额充值