Skip to content

Instantly share code, notes, and snippets.

@dudelson
Created January 7, 2017 01:55
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 dudelson/c15c84bbd78d9e14b875cab0e07181fa to your computer and use it in GitHub Desktop.
Save dudelson/c15c84bbd78d9e14b875cab0e07181fa to your computer and use it in GitHub Desktop.
My solution for UVA 11572
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
#define maxn (int)(1e9)+1
int t, n, x, ans, cnt, block;
map<int, int> lastseen;
int main() {
cin >> t;
while(t--) {
cin >> n;
lastseen.clear();
ans = 0, cnt = 0, block = 0;
for(int i=1; i<=n; i++) {
cin >> x;
int lx = lastseen[x];
if(lx != 0) {
block = max(block, lx);
cnt = i-block-1;
}
cnt++;
lastseen[x] = i;
ans = max(ans, cnt);
}
cout << ans << '\n';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment