求调双指针,我有点懵
查看原帖
求调双指针,我有点懵
940317
lightme楼主2024/1/29 11:59
// Problem: 
//     唯一的雪花 Unique Snowflakes
//   
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/UVA11572
// Memory Limit: 0 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
//#include<cstdio>
#include<map>
#define ll long long 
#define endl '\n'
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>(b);i--)
#define N 1000100 //1e6+100 
 
using namespace std;
int a[N];
map<int,int>m;
void solve(){
	int n;
	cin>>n;
	rep(i,1,n) cin>>a[i];
	m.clear();
	int l=1,r=1;
	m[a[l]]=1;
	int res=1;
	while(r<n){
		if(m[a[r+1]]==0)m[a[++r]]++;
		else {
			while(m[a[r+1]]!=0&&l<=r) m[a[l++]]--;
			r++;
		}

		res=max(res,r-l+1);
	}
	cout<<res<<endl;
}

int main(){
	int _;
	cin>>_;
	while(_--){
		solve();
	}
	
	return 0;
}

2024/1/29 11:59
加载中...