#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
int t;
cin>>t;
for(t; t>0; t--){
int n, h, x1, y1, x2, y2;
cin>>n>>h;
vector<pair<pair<int,int>, int> > v1;
pair<pair<int,int>, int> para;
for(int i=0; i<n; i++){
cin>>x1>>y1>>x2>>y2;
para=make_pair(make_pair(x1,y2-y1),i);
v1.push_back(para);
}
vector<int> gdzie(n);
sort(v1.begin(), v1.end());
for(int i=0; i<n; i++){
gdzie[i]=v1[i].second;
}
int ds=pow(2,(int)log2(n-1)+1);
vector<int> drzewo(2*ds);
for(int i=0; i<n; i++){
drzewo[ds+i]=v1[i].first.second;
}
for(int i=n; i<ds; i++){
drzewo[ds+i]=0;
}
for(int i=ds-1; i>0; i--){
drzewo[i]=max(drzewo[2*i], drzewo[2*i+1]);
}
vector<pair<pair<int,int>, int> > v2;
for(int i=0; i<n; i++){
cin>>x1>>y1>>x2>>y2;
para=make_pair(make_pair(x1,y2-y1),i);
v2.push_back(para);
}
sort(v2.begin(), v2.end());
bool spr=1;
int start, start2, maxh;
for(int i=0; i<n; i++){
start=ds+gdzie[v2[i].second]-1;
start2=ds;
if(gdzie[v2[i].second]!=0){
maxh=drzewo[start];
while(start!=start2){
start2/=2;
start/=2;
if(start%2==1)
{ maxh=max(maxh, drzewo[start*2]); }
}
if(maxh+v2[i].first.first>h) { spr=0; break; }
}
start=ds+gdzie[v2[i].second];
drzewo[start]=0;
while(start!=1){
start/=2;
drzewo[start]=max(drzewo[start*2], drzewo[start*2+1]);
}
}
if(spr) cout<<"TAK"<<endl;
else cout<<"NIE"<<endl;
}
}
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 | #include <iostream> #include <vector> #include <math.h> #include <algorithm> using namespace std; int main(){ int t; cin>>t; for(t; t>0; t--){ int n, h, x1, y1, x2, y2; cin>>n>>h; vector<pair<pair<int,int>, int> > v1; pair<pair<int,int>, int> para; for(int i=0; i<n; i++){ cin>>x1>>y1>>x2>>y2; para=make_pair(make_pair(x1,y2-y1),i); v1.push_back(para); } vector<int> gdzie(n); sort(v1.begin(), v1.end()); for(int i=0; i<n; i++){ gdzie[i]=v1[i].second; } int ds=pow(2,(int)log2(n-1)+1); vector<int> drzewo(2*ds); for(int i=0; i<n; i++){ drzewo[ds+i]=v1[i].first.second; } for(int i=n; i<ds; i++){ drzewo[ds+i]=0; } for(int i=ds-1; i>0; i--){ drzewo[i]=max(drzewo[2*i], drzewo[2*i+1]); } vector<pair<pair<int,int>, int> > v2; for(int i=0; i<n; i++){ cin>>x1>>y1>>x2>>y2; para=make_pair(make_pair(x1,y2-y1),i); v2.push_back(para); } sort(v2.begin(), v2.end()); bool spr=1; int start, start2, maxh; for(int i=0; i<n; i++){ start=ds+gdzie[v2[i].second]-1; start2=ds; if(gdzie[v2[i].second]!=0){ maxh=drzewo[start]; while(start!=start2){ start2/=2; start/=2; if(start%2==1) { maxh=max(maxh, drzewo[start*2]); } } if(maxh+v2[i].first.first>h) { spr=0; break; } } start=ds+gdzie[v2[i].second]; drzewo[start]=0; while(start!=1){ start/=2; drzewo[start]=max(drzewo[start*2], drzewo[start*2+1]); } } if(spr) cout<<"TAK"<<endl; else cout<<"NIE"<<endl; } } |
polski