Skip to content

Instantly share code, notes, and snippets.

@nomarlo
Created August 27, 2015 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nomarlo/d3f680a8eeb7e00ee254 to your computer and use it in GitHub Desktop.
Save nomarlo/d3f680a8eeb7e00ee254 to your computer and use it in GitHub Desktop.
/**
El punto clave del problema es verlo como un barrido
**/
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <sstream>
#include <map>
using namespace std;
vector <int> V;
map <int,int> M;
int t,n,ax,maxi,aux;
vector<int>::iterator i;
int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
maxi=ax=aux=0;
for(int e=0;e<n;e++){
scanf("%d",&ax);
if(M[ax]){
maxi=max(maxi, aux);
while(1){
i=V.begin();
if(*i!=ax){
M.erase(*i);
V.erase(i);
aux--;
}
else{
V.erase(i);
V.push_back(ax);
break;
}
}
}
else{
M[ax]=1;
V.push_back(ax);
aux++;
}
maxi=max(maxi,aux);
}
M.clear();
V.clear();
printf("%d\n",maxi);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment