• 板块灌水区
  • 楼主wangyihao0411
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/11/23 22:34
  • 上次更新2024/11/24 09:55:29
查看原帖
540757
wangyihao0411楼主2024/11/23 22:34
#include<iostream>
#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;
const int N=2e5+5;
int t[N],a[N];
signed main(){
	int n;
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin >> a[i];
	}
	int maxx=0,now=0,s;
	for(int i=1;i<n;i++)
	{
		if(a[i]==a[i+1])
		{
			now+=2;
			t[a[i]]++;
			if(t[a[i]]>1)
			{
				maxx=max(maxx,now-2);
				for(int j=s;;j+=2)
				{
                    t[j]--;
                    now-=2;
                    if(a[i]==a[j])
                    {   
                        break;
                    }
				}
			}
			if(now==2)
			{
				s=i;
			}
			i++;
		}
		else
		{
			maxx=max(maxx,now);
			for(int j=s;j<=i-2;j+=2)
			{
				t[j]--;
			}
		}
	}
	maxx=max(maxx,now);
	cout << maxx;
	return 0;
}

this

求帮忙把WA的改过来,TLE的不用管

2024/11/23 22:34
加载中...