#include #include #include using namespace std; int max(int a, int b) { return (a>b)?a:b; } /* void dump(const char* pref, vector& asd) { //printf("%s.size(): %d\n",pref,asd.size()); for(int i=0; i raw; for(int i=0; i last; vector > maxTree; maxTree.push_back(vector()); vector& X = maxTree[0]; for(int i=0; i::iterator it = last.find(raw[i]); if(it == last.end()) { last[raw[i]] = -1; } X.push_back(last[raw[i]] + 1); last[raw[i]] = i; } int l = M; while(l!=1) { l=l/2; maxTree.push_back(vector()); vector& after = maxTree[maxTree.size()-1]; vector& before = maxTree[maxTree.size()-2]; //dump("maxTree[maxTree.size()-2]",maxTree[maxTree.size()-2]); //dump("before",before); int k = before.size(); for(int i=0; i0; --j) { int z=(ay+ax)/2; if(a=z && b>=z) { ax = z; apos = 2*apos+1; } else { start=j; by=ay; ay = bx = z; apos = 2*apos; bpos = apos+1; //printf("%d bpos %d\n",__LINE__,bpos); break; } //printf("(c)pos: %d\n",apos); //printf("(c)level: %d, size: %d\n",j-1,maxTree[j-1].size()); //printf("(c)x: %d, y: %d\n",ax,ay); } //printf("(q)Apos: %d\n",apos); //printf("(q)Bpos: %d\n",bpos); //printf("(q)level: %d, size: %d\n",start-1,maxTree[start-1].size()); //printf("(q)ax: %d, ay: %d\n",ax,ay); //printf("(q)bx: %d, by: %d\n",bx,by); for(int j=start-1; j>0; --j) { int z=(ay+ax)/2; if(a0; --j) { int z=(by+bx)/2; if(b>=z) { bx = z; m = max(maxTree[j-1][2*bpos],m); //printf("%d: %d\n",__LINE__,m); bpos = 2*bpos+1; //printf("%d bpos %d\n",__LINE__,bpos); } else { by = z; bpos = 2*bpos; //printf("%d bpos %d\n",__LINE__,bpos); } //printf("(b)pos: %d\n",bpos); //printf("(b)m: %d\n",m); //printf("(b)level: %d, size: %d\n",j-1,maxTree[j-1].size()); //printf("(b)x: %d, y: %d\n",bx,by); } //printf("bpos at %d: %d\n",__LINE__,bpos); //printf("M: %d\n",M); m = max(maxTree[0][bpos],m); //printf("%d: %d\n",__LINE__,m); ////printf("m: %d\n",m); //printf("m: %d\n",m); if(m>a) printf("%d\n",raw[m-1]); else printf("OK\n"); } printf("\n"); } return 0; }