#include<cstdio> #include<algorithm> #include<vector> #include<tuple> #define MAXD 50005 using namespace std; class CounterTree{ private: int *T, n; int FRAME; public: CounterTree(int n); ~CounterTree(); void set(int k, int v); void add(int k, int v); void inc(int k); void dec(int k); int query(int k); int query(int k0, int k1); int less_than(int k); int greater_than(int k); void clear(); void erase(int k); }; CounterTree::CounterTree(int _n):n(_n){ this->FRAME = 1; while(this->FRAME < n) this->FRAME<<=1; this->T = new int[2*this->FRAME]; for(int i = 0; i < 2*this->FRAME; i++) this->T[i] = 0; } CounterTree::~CounterTree(){ delete[] this->T; } void CounterTree::add(int k, int v){ if(k<0 || k>=this->n)return; k += this->FRAME; while(k>0){ this->T[k] += v; k/=2; } } void CounterTree::set(int k, int v){ this->add(k, v-this->query(k)); } void CounterTree::inc(int k){ this->add(k, 1); } void CounterTree::dec(int k){ this->add(k, -1); } int CounterTree::less_than(int k){ if(k<0)return 0; if(k>=this->n)return this->T[1]; k += this->FRAME; int res = 0; while(k > 0){ if(2*(k/2)+1 == k) res+=this->T[k-1]; k/=2; } return res; } int CounterTree::greater_than(int k){ if(k>=this->n)return 0; if(k<0)return this->T[1]; k += this->FRAME; int res = 0; while(k > 0){ if(2*(k/2) == k) res += this->T[k+1]; k/=2; } return res; } int CounterTree::query(int k){ return this->T[k+this->FRAME]; } int CounterTree::query(int k0, int k1){ return this->less_than(k1+1)-this->less_than(k0); } void CounterTree::clear(){ for(int i=0;i<2*this->FRAME;i++) this->T[i] = 0; } void CounterTree::erase(int k){ this->set(k, 0); } int M[2*MAXD]; int pre[MAXD][2]; int post[MAXD][2]; int n,z,h; int main(){ scanf("%d",&z); while(z--){ vector<tuple<int,int,int> > A, B; vector<pair<int,int> > W; scanf("%d%d",&n,&h); for(int i=0;i<n;i++){ int x1,x2,y1,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); int hh = abs(y1-y2); W.push_back(make_pair(hh, i)); W.push_back(make_pair(h-hh, i+n)); A.push_back(make_tuple(min(x1,x2), min(y1,y2), i)); } for(int i=0;i<n;i++){ int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); B.push_back(make_tuple(min(x1,x2), min(y1,y2), i)); } sort(A.begin(), A.end()); sort(B.begin(), B.end()); sort(W.begin(), W.end()); int next = 0; M[W[0].second] = next; for(int i=1;i<W.size();i++){ if(W[i].first!=W[i-1].first) next++; M[W[i].second] = next; } CounterTree C(next+1); for(int i=0;i<n;i++){ pre[get<2>(A[i])][0] = C.greater_than(M[get<2>(A[i])+n]); C.inc(M[get<2>(A[i])]); }C.clear(); /*for(int i=n-1;i>=0;i--){ pre[get<2>(A[i])][1] = C.greater_than(M[get<2>(A[i])+n]); C.inc(M[get<2>(A[i])]); }C.clear();*/ for(int i=0;i<n;i++){ post[get<2>(B[i])][0] = C.greater_than(M[get<2>(B[i])+n]); C.inc(M[get<2>(B[i])]); }C.clear(); /*for(int i=n-1;i>=0;i--){ post[get<2>(B[i])][1] = C.greater_than(M[get<2>(B[i])+n]); C.inc(M[get<2>(B[i])]); }C.clear();*/ bool ok = true; for(int i=0;i<n;i++) if(post[i][0] != pre[i][0]){ ok = false; break; } printf("%s\n",ok?"TAK":"NIE"); } 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | #include<cstdio> #include<algorithm> #include<vector> #include<tuple> #define MAXD 50005 using namespace std; class CounterTree{ private: int *T, n; int FRAME; public: CounterTree(int n); ~CounterTree(); void set(int k, int v); void add(int k, int v); void inc(int k); void dec(int k); int query(int k); int query(int k0, int k1); int less_than(int k); int greater_than(int k); void clear(); void erase(int k); }; CounterTree::CounterTree(int _n):n(_n){ this->FRAME = 1; while(this->FRAME < n) this->FRAME<<=1; this->T = new int[2*this->FRAME]; for(int i = 0; i < 2*this->FRAME; i++) this->T[i] = 0; } CounterTree::~CounterTree(){ delete[] this->T; } void CounterTree::add(int k, int v){ if(k<0 || k>=this->n)return; k += this->FRAME; while(k>0){ this->T[k] += v; k/=2; } } void CounterTree::set(int k, int v){ this->add(k, v-this->query(k)); } void CounterTree::inc(int k){ this->add(k, 1); } void CounterTree::dec(int k){ this->add(k, -1); } int CounterTree::less_than(int k){ if(k<0)return 0; if(k>=this->n)return this->T[1]; k += this->FRAME; int res = 0; while(k > 0){ if(2*(k/2)+1 == k) res+=this->T[k-1]; k/=2; } return res; } int CounterTree::greater_than(int k){ if(k>=this->n)return 0; if(k<0)return this->T[1]; k += this->FRAME; int res = 0; while(k > 0){ if(2*(k/2) == k) res += this->T[k+1]; k/=2; } return res; } int CounterTree::query(int k){ return this->T[k+this->FRAME]; } int CounterTree::query(int k0, int k1){ return this->less_than(k1+1)-this->less_than(k0); } void CounterTree::clear(){ for(int i=0;i<2*this->FRAME;i++) this->T[i] = 0; } void CounterTree::erase(int k){ this->set(k, 0); } int M[2*MAXD]; int pre[MAXD][2]; int post[MAXD][2]; int n,z,h; int main(){ scanf("%d",&z); while(z--){ vector<tuple<int,int,int> > A, B; vector<pair<int,int> > W; scanf("%d%d",&n,&h); for(int i=0;i<n;i++){ int x1,x2,y1,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); int hh = abs(y1-y2); W.push_back(make_pair(hh, i)); W.push_back(make_pair(h-hh, i+n)); A.push_back(make_tuple(min(x1,x2), min(y1,y2), i)); } for(int i=0;i<n;i++){ int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); B.push_back(make_tuple(min(x1,x2), min(y1,y2), i)); } sort(A.begin(), A.end()); sort(B.begin(), B.end()); sort(W.begin(), W.end()); int next = 0; M[W[0].second] = next; for(int i=1;i<W.size();i++){ if(W[i].first!=W[i-1].first) next++; M[W[i].second] = next; } CounterTree C(next+1); for(int i=0;i<n;i++){ pre[get<2>(A[i])][0] = C.greater_than(M[get<2>(A[i])+n]); C.inc(M[get<2>(A[i])]); }C.clear(); /*for(int i=n-1;i>=0;i--){ pre[get<2>(A[i])][1] = C.greater_than(M[get<2>(A[i])+n]); C.inc(M[get<2>(A[i])]); }C.clear();*/ for(int i=0;i<n;i++){ post[get<2>(B[i])][0] = C.greater_than(M[get<2>(B[i])+n]); C.inc(M[get<2>(B[i])]); }C.clear(); /*for(int i=n-1;i>=0;i--){ post[get<2>(B[i])][1] = C.greater_than(M[get<2>(B[i])+n]); C.inc(M[get<2>(B[i])]); }C.clear();*/ bool ok = true; for(int i=0;i<n;i++) if(post[i][0] != pre[i][0]){ ok = false; break; } printf("%s\n",ok?"TAK":"NIE"); } return 0; } |