社区讨论

保龄求助

P11233[CSP-S 2024] 染色参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@m2t7ewis
此快照首次捕获于
2024/10/28 23:59
去年
此快照最后确认于
2025/11/04 15:46
4 个月前
查看原帖
考场代码寄掉了(悲
CPP
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
const int maxm=1e6+10;
typedef long long ll;
int a[maxn],s[maxn],w[maxn],f[maxn],t[maxm];
int main()
{
	ios::sync_with_stdio(false);
//	freopen("color2.in","r",stdin);
	int tp;
	cin>>tp;
	while(tp--)
	{
		memset(s,0,sizeof(s));
		memset(w,0,sizeof(w));
		memset(f,0,sizeof(f));
		memset(t,-1,sizeof(t));
		int n;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			if(t[a[i]]!=-1)
				s[i]=t[a[i]];
			t[a[i]]=i;
			if(a[i]==a[i-1])
				w[i]=a[i];
			w[i]+=w[i-1];
			if(s[i]!=0)
				f[i]=max(f[i-1],f[s[i]+1]+w[i]-w[s[i]+1]+a[i]);
			else
				f[i]=f[i-1];
		}
		cout<<f[n]<<endl;
	}
	return 0;
}
/*
1
15
5 3 7 2 4 13 11 6 5 5 3 5 12 8 13




18
*/


回复

1 条回复,欢迎继续交流。

正在加载回复...