// // Yukicoder // No.3009 //#include "stdafx.h" #include #include #include #include //list #include //tree #include //連想配列 #include //hash #include //hash #include #include #include #include using namespace std; typedef unsigned long long ULL; typedef signed long long SLL; typedef unsigned int UINT; #define START (0) #define RIGHT (1) #define UP (2) #define LEFT (3) #define DOWN (4) #define DATA_MAX (1000000) #define FMAX(a,b) ((a)>(b)?(a):(b)) #define FMIN(a,b) ((a)<(b)?(a):(b)) vector > memo2;//二次元可変配列 vector memo1; vector c; vector v; vector dp; SLL H ,A, B, T, F, N, M, Result; UINT hashtable; SLL hashTable[1000005]; int main(int argc, char *argv[]) { SLL a[100005]; cin >> N; v.resize(N + 1); for (int i = 0; i < N; i++) { cin >> a[i]; } //cout << "-----" << endl; SLL L, R, ans=0, max_ans = 0,max_ans2 = 0; //Nが1以下のとき if (N <= 1) { cout << N << endl; return 0; } //Nが2以上のとき const int search_complete = 1; const int search_break = 0; int flag; SLL i; L = 0; R = L; flag = search_complete; do { if (hashTable[a[R]] == 0) { //バケット配列にインデックスをいれる(インデックス0と何もないの0を区別するために1から始める) hashTable[a[R]] = R+1; if (max_ans < R - L + 1 ) max_ans = R - L + 1; } else { flag = search_break; } //cout << "L=" << L << ",R=" << R << ",ans=" << max_ans << endl; if (flag == search_break) { ans = 0; if(L < hashTable[a[R]]) L = hashTable[a[R]]; //予め+1しているのでそのまま入れる hashTable[a[R]] = R+1; flag = search_complete; } R++; } while (R < N); cout << max_ans << endl; /////////////////// //cout << endl; //getchar(); return 0; //end }