Title Address: UVa 11572
Such a method has been approached, defining two pointers, constantly sliding from left to right, to infer whether the pointer is in compliance with the requirements.
In order to be able to infer at a high speed whether there is this number, you can use the set in STL.
The code is as follows:
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include < stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #include <map> #include < Set> #include <algorithm>using namespace Std;int a[1100000];int main () { int t, N, L, R, I, Max1; scanf ("%d", &t); while (t--) { scanf ("%d", &n); Max1=-1; for (i=0;i<n;i++) { scanf ("%d", &a[i]); } l=r=0; set<int>q; while (r!=n) { while (Q.count (A[r])) { q.erase (a[l++]); } Q.insert (a[r++]); if (max1<r-l) max1=r-l; } printf ("%d\n", max1); } return 0;}
(Petition training Plan) UVa 11572 Unique Snowflakes (form sliding)