#include <iostream>
#include <algorithm>
typedef unsigned long long ull;
using namespace std;
class Samochod
{
public:
//pozycja przed zamiana
int x1, y1;
int x2, y2;
//pozycja po zamianie
int x3, y3;
int x4, y4;
void poprawPozycje()
{
if (x2 < x1)
{
swap(x1, x2);
swap(y1, y2);
}
if (x4 < x3)
{
swap(x3, x4);
swap(y3, y4);
}
if (h < 0)
h = -h;
}
//y2 - y1
int h;
int n;
};
bool operator < (Samochod a, Samochod b)
{
return a.h < b.h;
}
const int MAXN = 50000;
const int MAXH = 1000000000;
int bs (Samochod A[], int l, int p, int k)
{
//tablica l..p-1
while (l < p)
{
int s = (l+p)/2;
if (A[s].h >= k)
p = s;
else
l = s + 1;
}
return p;
}
int main()
{
ios_base::sync_with_stdio(0);
int t;
int n;
int w;
bool czyMozna;
Samochod samochody[MAXN];
cin>>t;
while(t--)
{
cin>>n;
cin>>w;
czyMozna = true;
for (int i = 0; i < n; i++)
{
cin>>samochody[i].x1;
cin>>samochody[i].y1;
cin>>samochody[i].x2;
cin>>samochody[i].y2;
samochody[i].h = samochody[i].y2 - samochody[i].y1;
}
for (int i = 0; i < n; i++)
{
cin>>samochody[i].x3;
cin>>samochody[i].y3;
cin>>samochody[i].x4;
cin>>samochody[i].y4;
samochody[i].poprawPozycje();
}
sort(samochody, samochody + n);
for (int i = 0; i < n; i++)
{
int j = bs(samochody, i + 1, n, w - samochody[i].h + 1);
while (j < n)
{
if (samochody[i].x1 < samochody[j].x1 && samochody[i].x3 > samochody[j].x3 ||
samochody[i].x1 > samochody[j].x1 && samochody[i].x3 < samochody[j].x3)
break;
else
j++;
}
if (j < n)
{
czyMozna = false;
break;
}
}
cout<< (czyMozna ? "TAK" : "NIE") <<endl;
}
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | #include <iostream> #include <algorithm> typedef unsigned long long ull; using namespace std; class Samochod { public: //pozycja przed zamiana int x1, y1; int x2, y2; //pozycja po zamianie int x3, y3; int x4, y4; void poprawPozycje() { if (x2 < x1) { swap(x1, x2); swap(y1, y2); } if (x4 < x3) { swap(x3, x4); swap(y3, y4); } if (h < 0) h = -h; } //y2 - y1 int h; int n; }; bool operator < (Samochod a, Samochod b) { return a.h < b.h; } const int MAXN = 50000; const int MAXH = 1000000000; int bs (Samochod A[], int l, int p, int k) { //tablica l..p-1 while (l < p) { int s = (l+p)/2; if (A[s].h >= k) p = s; else l = s + 1; } return p; } int main() { ios_base::sync_with_stdio(0); int t; int n; int w; bool czyMozna; Samochod samochody[MAXN]; cin>>t; while(t--) { cin>>n; cin>>w; czyMozna = true; for (int i = 0; i < n; i++) { cin>>samochody[i].x1; cin>>samochody[i].y1; cin>>samochody[i].x2; cin>>samochody[i].y2; samochody[i].h = samochody[i].y2 - samochody[i].y1; } for (int i = 0; i < n; i++) { cin>>samochody[i].x3; cin>>samochody[i].y3; cin>>samochody[i].x4; cin>>samochody[i].y4; samochody[i].poprawPozycje(); } sort(samochody, samochody + n); for (int i = 0; i < n; i++) { int j = bs(samochody, i + 1, n, w - samochody[i].h + 1); while (j < n) { if (samochody[i].x1 < samochody[j].x1 && samochody[i].x3 > samochody[j].x3 || samochody[i].x1 > samochody[j].x1 && samochody[i].x3 < samochody[j].x3) break; else j++; } if (j < n) { czyMozna = false; break; } } cout<< (czyMozna ? "TAK" : "NIE") <<endl; } return 0; } |
English