#include <iostream> #include <algorithm> using namespace std; const int M=65536; int d[2*M]; struct xxx{ int x1, y1, x2, y2; int index; }p[M], k[M]; int tab[M]; void insert(int x, int war){ x+=M; d[x]=war; x/=2; while(x!=0){ d[x]=max(d[2*x], d[2*x+1]); x/=2; } } int query(int a, int b){ int wyn=0; int va=a+M; int vb=b+M; wyn=max(d[va], d[vb]); while(va/2!=vb/2){ if(va%2==0) wyn=max(wyn, d[va+1]); if(vb%2==1) wyn=max(wyn, d[vb-1]); va/=2; vb/=2; } return wyn; } bool cmp(xxx a, xxx b){ return a.x1<b.x1; } int t, n, h; bool ok; int main(){ ios_base::sync_with_stdio(0); cin>>t; while(t--){ ok=true; cin>>n>>h; for(int i=0; i<n; i++){ cin>>p[i].x1>>p[i].y1>>p[i].x2>>p[i].y2; p[i].index=i; } for(int i=0; i<n; i++){ cin>>k[i].x1>>k[i].y1>>k[i].x2>>k[i].y2; k[i].index=i; } sort(p, p+n, cmp); sort(k, k+n, cmp); for(int i=0; i<n; i++){ insert(i, p[i].y2-p[i].y1); tab[p[i].index]=i; } for(int i=0; i<n; i++){ if((query(0, tab[k[i].index]-1) + (k[i].y2-k[i].y1) > h ) && (tab[k[i].index] > 0)) ok=false; insert(tab[k[i].index], 0); } if(ok) cout<<"TAK\n"; else cout<<"NIE\n"; //wyczyscic wszystko } 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 | #include <iostream> #include <algorithm> using namespace std; const int M=65536; int d[2*M]; struct xxx{ int x1, y1, x2, y2; int index; }p[M], k[M]; int tab[M]; void insert(int x, int war){ x+=M; d[x]=war; x/=2; while(x!=0){ d[x]=max(d[2*x], d[2*x+1]); x/=2; } } int query(int a, int b){ int wyn=0; int va=a+M; int vb=b+M; wyn=max(d[va], d[vb]); while(va/2!=vb/2){ if(va%2==0) wyn=max(wyn, d[va+1]); if(vb%2==1) wyn=max(wyn, d[vb-1]); va/=2; vb/=2; } return wyn; } bool cmp(xxx a, xxx b){ return a.x1<b.x1; } int t, n, h; bool ok; int main(){ ios_base::sync_with_stdio(0); cin>>t; while(t--){ ok=true; cin>>n>>h; for(int i=0; i<n; i++){ cin>>p[i].x1>>p[i].y1>>p[i].x2>>p[i].y2; p[i].index=i; } for(int i=0; i<n; i++){ cin>>k[i].x1>>k[i].y1>>k[i].x2>>k[i].y2; k[i].index=i; } sort(p, p+n, cmp); sort(k, k+n, cmp); for(int i=0; i<n; i++){ insert(i, p[i].y2-p[i].y1); tab[p[i].index]=i; } for(int i=0; i<n; i++){ if((query(0, tab[k[i].index]-1) + (k[i].y2-k[i].y1) > h ) && (tab[k[i].index] > 0)) ok=false; insert(tab[k[i].index], 0); } if(ok) cout<<"TAK\n"; else cout<<"NIE\n"; //wyczyscic wszystko } return 0; } |