// Karol Różycki Zadanie Parking #include<cstdio> #include<algorithm> #include<climits> #define MAX 50100 #define MAXI 131071 using namespace std; int M = 65536; struct car{ int x1, y1, x2, y2, index; int height(){ return abs(y2 - y1); } }; bool mf(const car & x, const car & y){ return min(x.x1, x.x2) < min(y.x1, y.x2); } car B[MAX]; car C[MAX]; int P[MAX]; int W[MAXI]; void insert(int x, int val){ int v = M + x; W[v] = val; while(v != 1){ v /= 2; W[v] = max(W[2 * v], W[2 * v + 1]); } } int query(int a, int b){ int va = M + a, vb = M + b; int wyn = W[va]; if(va != vb){ wyn = max(wyn, W[vb]); } while(va / 2 != vb / 2){ if(va % 2 == 0) wyn = max(wyn, W[va + 1]); if(vb % 2 == 1) wyn = max(wyn, W[vb - 1]); va /= 2; vb /= 2; } return wyn; } int main(){ int t; scanf("%d", &t); while(t--){ int n, w; scanf("%d %d", &n, &w); for(int i = 0; i < MAXI; i++){ W[i] = 0; } for(int i = 0; i < n; i++){ scanf("%d %d %d %d", &B[i].x1, &B[i].y1, &B[i].x2, &B[i].y2); B[i].index = i; } for(int i = 0; i < n; i++){ scanf("%d %d %d %d", &C[i].x1, &C[i].y1, &C[i].x2, &C[i].y2); C[i].index = i; } sort(B, B + n, mf); for(int i = 0; i < n; i++){ P[B[i].index] = i; insert(i, B[i].height()); } sort(C, C + n, mf); bool result = true; for(int i = 0; i < n; i++){ if(i < P[C[i].index] && query(i, P[C[i].index]) + C[i].height() > w){ result = false; break; } } if(result){ printf("TAK\n"); }else{ printf("NIE\n"); } } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | // Karol Różycki Zadanie Parking #include<cstdio> #include<algorithm> #include<climits> #define MAX 50100 #define MAXI 131071 using namespace std; int M = 65536; struct car{ int x1, y1, x2, y2, index; int height(){ return abs(y2 - y1); } }; bool mf(const car & x, const car & y){ return min(x.x1, x.x2) < min(y.x1, y.x2); } car B[MAX]; car C[MAX]; int P[MAX]; int W[MAXI]; void insert(int x, int val){ int v = M + x; W[v] = val; while(v != 1){ v /= 2; W[v] = max(W[2 * v], W[2 * v + 1]); } } int query(int a, int b){ int va = M + a, vb = M + b; int wyn = W[va]; if(va != vb){ wyn = max(wyn, W[vb]); } while(va / 2 != vb / 2){ if(va % 2 == 0) wyn = max(wyn, W[va + 1]); if(vb % 2 == 1) wyn = max(wyn, W[vb - 1]); va /= 2; vb /= 2; } return wyn; } int main(){ int t; scanf("%d", &t); while(t--){ int n, w; scanf("%d %d", &n, &w); for(int i = 0; i < MAXI; i++){ W[i] = 0; } for(int i = 0; i < n; i++){ scanf("%d %d %d %d", &B[i].x1, &B[i].y1, &B[i].x2, &B[i].y2); B[i].index = i; } for(int i = 0; i < n; i++){ scanf("%d %d %d %d", &C[i].x1, &C[i].y1, &C[i].x2, &C[i].y2); C[i].index = i; } sort(B, B + n, mf); for(int i = 0; i < n; i++){ P[B[i].index] = i; insert(i, B[i].height()); } sort(C, C + n, mf); bool result = true; for(int i = 0; i < n; i++){ if(i < P[C[i].index] && query(i, P[C[i].index]) + C[i].height() > w){ result = false; break; } } if(result){ printf("TAK\n"); }else{ printf("NIE\n"); } } return 0; } |