#include #include struct Pole{ int val; int pos; }; struct Rozsah{ int start; int end; int val; }; int cmp(const void * a, const void * b){ if( (*(Pole*)a).val < (*(Pole*)b).val) return -1; if( (*(Pole*)a).val > (*(Pole*)b).val) return 1; if( (*(Pole*)a).pos < (*(Pole*)b).pos) return -1; if( (*(Pole*)a).pos > (*(Pole*)b).pos) return 1; return 0; } int bs(Rozsah * pole, int len, int x){ bool found = false; int L = 1, R = len-1, mid; while(L<=R && !found){ mid = (L+R)/2; if(pole[mid].start == x) found = true; else{ if(pole[mid].start < x) L = mid+1; else R = mid-1; } } //printf("nalezeno: %d\n",pole[mid].start); if(found) return mid; else return mid+1; } int main () { Pole * pole; Rozsah * roz; int M, Q, j; int min, max, ps; //Rozsah p[5]; //for(int i=1;i<6;i++) p[i].start = i*2; //printf("pos: %d\n",bs(p,6,5)); //printf("pos: %d\n",bs(p,6,11)); while(scanf("%d%d",&M,&Q), M!=0){ M++; j = 1; pole = new Pole [M]; roz = new Rozsah [M/2+1]; roz[0].end = 0; for(int i=1;i= pole[i].pos){ roz[j-1].end = pole[i].pos; roz[j-1].start = pole[i-1].pos; roz[j-1].val = pole[i].val; }else{ roz[j].start = pole[i-1].pos; roz[j].end = pole[i].pos; roz[j].val = pole[i].val; j++; } } } for(int i=0;i= j) printf("OK\n"); else{ if(max >= roz[ps].end) printf("%d\n",roz[ps].val); else printf("OK\n"); } } printf("\n"); } return 0; }