#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define FOR(i,m,n) for (int i = m; i < n; i++) using namespace std; struct Bod { int x; int typ; int y; bool operator<(const Bod &b) const { return (xb.typ)); } }; int M, Q; vector body; vector seq2; vector seq; vector sorted; vector > interval; vector > sint; int posl[1200000]; int vysl[1200000]; int aktivni[1200000]; bool porovnej_pair(const pair &a, const pair &b) { return (a.first(a, b)); sint.push_back(pair(a, b)); Bod A; A.x = a; A.typ = 3; Bod B; B.x = b; B.typ = 4; A.y = B.x; B.y = A.x; body.push_back(A); body.push_back(B); } sort(sint.begin(), sint.end(), porovnej_pair); sort(body.begin(), body.end()); //FOR (i, 0, body.size()) printf("%d (%d) - %d\n", body[i].x, body[i].y, body[i].typ); // Sweep line vector heap; int K = 0; FOR (i, 0, body.size()) { switch(body[i].typ) { case 1: //printf("1\n"); while (heap.size()>0 && heap[0].x >= body[i].y) { int a = heap[0].y; int b = heap[0].x; int index = lower_bound(sint.begin(), sint.end(), pair(a,b), porovnej_pair) - sint.begin(); //printf("index %d\n", index); if (aktivni[index]) { //printf("interval %d,%d je spatny, protoze %d,%d\n", a, b, body[i].x, body[i].y); // vysledek pro tento interval //printf("x %d\n", body[i].x); vysl[index] = seq2[body[i].x]; aktivni[index] = false; } pop_heap(heap.begin(), heap.end()); heap.pop_back(); K--; } break; case 2: //printf("2\n"); break; case 3: //printf("3\n"); heap.push_back((Bod){body[i].y, 4, body[i].x}); push_heap(heap.begin(), heap.end()); K++; break; case 4: //printf("4\n"); int a = body[i].y; int b = body[i].x; int index = lower_bound(sint.begin(), sint.end(), pair(a,b), porovnej_pair) - sint.begin(); aktivni[index] = false; break; } } FOR (i, 0, interval.size()) { int index = lower_bound(sint.begin(), sint.end(), interval[i], porovnej_pair) - sint.begin(); if (vysl[index]==-1) printf("OK\n"); else printf("%d\n", vysl[index]); } printf("\n"); return true; } int main() { while (solve()); return 0; }