首页 > 代码库 > Uva11572

Uva11572

读入可以不需要存入数组

#include<bits/stdc++.h>#define inf 0x3f3f3f3f//const int maxn=;using namespace std;int t;int n;int main(){      scanf("%d",&t);      while(t--){        map<int, int> m;        scanf("%d",&n);        int ans = -inf;        int cnt = 0;        int imax = 0;        int x;        for(int i = 1; i <= n; ++i){                scanf("%d",&x);                if(!m[x]){                    ++cnt;                } else {                        ans = max(ans, cnt);                        imax = max(imax, m[x] + 1);                        cnt = i - imax + 1;                }                m[x] = i;        }        ans = max(ans, cnt);        printf("%d\n",ans);      }    return 0;}

 

Uva11572