Created
August 27, 2015 18:20
-
-
Save nomarlo/d3f680a8eeb7e00ee254 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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