求助,wa了qaq
查看原帖
求助,wa了qaq
361592
histcat楼主2022/3/26 22:17
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<unordered_map>
using namespace std;

const int N = 1e6 + 10,null = 0x3f3f3f3f;

int t,n;
int a[N];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> t;
	unordered_map<int,int> s;
	while(t--)
	{
		cin >> n;
		for(int i = 1;i <= n;i++)
		{
			cin >> a[i];
		}
		long long res = 0;
		for(long long i = 1, j = 1;i <= n;i++)
		{
			s[a[i]]++;
			/*cout << "`````````````" << s[a[i]] << endl;*/
			while(s[a[i]] > 1)
			{
				j++;
				s[a[i]]--;
			}
			res = max(res,i - j + 1);
		}
		cout << res << endl;
		memset(a, 0, sizeof a);
		s.clear();
	}
	
	return 0;
}

2022/3/26 22:17
加载中...