保龄求助
查看原帖
保龄求助
263414
Sktic楼主2024/10/28 23:58

考场代码寄掉了(悲

#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
*/


2024/10/28 23:58
加载中...