// start reading at line 233 #include <algorithm> #include <iostream> #include <iomanip> #include <sstream> #include <utility> #include <numeric> #include <bitset> #include <queue> #include <stack> #include <list> #include <map> #include <set> #include <cassert> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath> #include <ctime> #define VAR(v, n) typeof(n) v = (n) #define ALL(c) (c).begin(), (c).end() #define REP(i, n) for (int i = 0, $##i = (n); i < $##i; ++i) #define FOR(i, b, e) for (int i = (b), $##i = (e); i <= $##i; ++i) #define FORD(i, b, e) for (int i = (b), $##i = (e); i >= $##i; --i) #define ever ( ; ; ) #define skip continue #define LOOP_BODY(it, cont, begin, type) \ for (common::IteratorWrapper<typeof((cont).begin())> $##it(cont, type); \ $##it.ok(); $##it.adv()) #define isBegin(it) $##it.first #define LOOP(it, cont, begin, type) \ LOOP_BODY(it, cont, begin, type)\ for (VAR(&it, *$##it.curr); $##it.go; $##it.go = 0) #define LOOP_KV(key, val, cont, begin, type) \ LOOP_BODY(key, cont, begin, type) \ for (VAR(&key, $##key.curr->first); $##key.go; )\ for (VAR(&val, $##key.curr->second); $##key.go; $##key.go = 0) #define EACH(it, cont) LOOP(it, cont, begin, 0) #define REACH(it, cont) LOOP(it, cont, rbegin, 0u) #define EACH_KV(key, val, cont) LOOP_KV(key, val, cont, begin, 0) #define REACH_KV(key, val, cont) LOOP_KV(key, val, cont, rbegin, 0u) template <typename T> struct delete_const { }; template <typename T> struct delete_const<const T> { typedef T type; }; #define FORPQ(x, Q) \ for (delete_const<typeof((Q).top())>::type x; \ !(Q).empty() && (x = (Q).top(), (Q).pop(), true); ) namespace common { template<class Iterator> struct IteratorWrapper { Iterator curr, end; bool go, first; template<class Container> IteratorWrapper(Container &cont, int /* normal */) : curr(cont.begin()), end(cont.end()), go(0), first(1) { } template<class Container> IteratorWrapper(Container &cont, unsigned /* reversed */) : curr(cont.rbegin()), end(cont.rend()), go(0), first(1) { } bool ok() { return (go = !go) && curr != end; } void adv() { ++curr; first = false; } }; struct GetSizeHelper { int s; operator int () const { return s; } template<class T> GetSizeHelper(const T &t) : s((int) t.size()) {} }; } #define SIZE (common::GetSizeHelper) namespace koo { template<class T> int unique(T &t, bool sorted = false) { if (!sorted) { sort(ALL(t)); } t.resize(unique(ALL(t)) - t.begin()); return SIZE t; } template <class T, class U> bool remin(T &a, const U &b) { return b < a ? a = b, true : false; } template <class T, class U> bool remax(T &a, const U &b) { return b > a ? a = b, true : false; } } #define dump fancy_dumper::DumpFirst<&std::cerr>(), #define say fancy_dumper::DumpFirst<&std::cout>(), #define $dump fancy_dumper::Dumper<&std::cerr> #define $say fancy_dumper::Dumper<&std::cout> #ifndef $ #define $(x) #x, fancy_dumper::ToggleSeparator(), (x),\ fancy_dumper::ToggleSeparator() #endif namespace fancy_dumper { using std::ostream; struct ToggleSeparator { }; template<ostream *Out> struct DumpFirst { }; template<ostream *Out> struct Dumper { static void *&last() { static void *p; return p; } static const char *&separator() { static const char *s = " "; return s; } static const char *&separatorNewLine() { static const char *s = "\n"; return s; } static const char *&unseparator() { static const char *s = "="; return s; } Dumper() { last() = this; } ~Dumper() { if (this == last()) { *Out << separatorNewLine(); } } Dumper operator, (ToggleSeparator) { std::swap(separator(), unseparator()); return Dumper(); } }; template<ostream *Out, class T> Dumper<Out> operator,(Dumper<Out>, const T &e) { *Out << Dumper<Out>::separator() << e; return Dumper<Out>(); } template<ostream *Out, class T> Dumper<Out> operator, (DumpFirst<Out>, const T &e) { *Out << e; return Dumper<Out>(); } } namespace koo { using namespace std; template<class T> T fromString(const string &s) { T t; istringstream(s) >> t; return t; } template<class T> string toString(const T &t) { ostringstream oss; oss << t; return oss.str(); } template<class T, class Y> ostream &operator<< (ostream &o, const pair<T, Y> &p) { return o << p.first << ' ' << p.second; } template<class T> ostream &operator<< (ostream &o, const vector<T> &v) { EACH (e, v) { if (!isBegin(e)) { o << ' '; } o << e; } return o; } template<class T> ostream &operator,(ostream &o, const T &t) { return o << t; } template<class T> istream &operator,(istream &i, T &t) { return i >> t; } } using namespace std; using namespace rel_ops; using namespace koo; const int inf = 1000000001; typedef long long ll; typedef unsigned long long ull; // end of default code void read_and_find_characteristic(int n, int w, vector<int> &out) { vector<pair<int,pair<int,int>>> v(n + 1); REP (i, n) { int x, y, y2; cin, x, y, x, y2; y = abs(y - y2); v[i] = make_pair(x, make_pair(y, i)); } v[n] = make_pair(inf, make_pair(inf, inf)); sort(ALL(v)); priority_queue<pair<int,int>> q; FOR (i, 0, n) { if (v[i].second.first * 2 > w) { while (!q.empty()) { const int y = q.top().first; if (y + v[i].second.first > w) { out[q.top().second] = v[i].second.second; q.pop(); } else { break; } } } q.push(v[i].second); } assert(SIZE q == 1); } bool test() { int n, w; cin, n, w; vector<int> v1(n), v2(n); read_and_find_characteristic(n, w, v1); read_and_find_characteristic(n, w, v2); return v1 == v2; } int main() { ios::sync_with_stdio(0); int tests; cin, tests; FOR (tt, 1, tests) { say test() ? "TAK" : "NIE"; } }
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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | // start reading at line 233 #include <algorithm> #include <iostream> #include <iomanip> #include <sstream> #include <utility> #include <numeric> #include <bitset> #include <queue> #include <stack> #include <list> #include <map> #include <set> #include <cassert> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath> #include <ctime> #define VAR(v, n) typeof(n) v = (n) #define ALL(c) (c).begin(), (c).end() #define REP(i, n) for (int i = 0, $##i = (n); i < $##i; ++i) #define FOR(i, b, e) for (int i = (b), $##i = (e); i <= $##i; ++i) #define FORD(i, b, e) for (int i = (b), $##i = (e); i >= $##i; --i) #define ever ( ; ; ) #define skip continue #define LOOP_BODY(it, cont, begin, type) \ for (common::IteratorWrapper<typeof((cont).begin())> $##it(cont, type); \ $##it.ok(); $##it.adv()) #define isBegin(it) $##it.first #define LOOP(it, cont, begin, type) \ LOOP_BODY(it, cont, begin, type)\ for (VAR(&it, *$##it.curr); $##it.go; $##it.go = 0) #define LOOP_KV(key, val, cont, begin, type) \ LOOP_BODY(key, cont, begin, type) \ for (VAR(&key, $##key.curr->first); $##key.go; )\ for (VAR(&val, $##key.curr->second); $##key.go; $##key.go = 0) #define EACH(it, cont) LOOP(it, cont, begin, 0) #define REACH(it, cont) LOOP(it, cont, rbegin, 0u) #define EACH_KV(key, val, cont) LOOP_KV(key, val, cont, begin, 0) #define REACH_KV(key, val, cont) LOOP_KV(key, val, cont, rbegin, 0u) template <typename T> struct delete_const { }; template <typename T> struct delete_const<const T> { typedef T type; }; #define FORPQ(x, Q) \ for (delete_const<typeof((Q).top())>::type x; \ !(Q).empty() && (x = (Q).top(), (Q).pop(), true); ) namespace common { template<class Iterator> struct IteratorWrapper { Iterator curr, end; bool go, first; template<class Container> IteratorWrapper(Container &cont, int /* normal */) : curr(cont.begin()), end(cont.end()), go(0), first(1) { } template<class Container> IteratorWrapper(Container &cont, unsigned /* reversed */) : curr(cont.rbegin()), end(cont.rend()), go(0), first(1) { } bool ok() { return (go = !go) && curr != end; } void adv() { ++curr; first = false; } }; struct GetSizeHelper { int s; operator int () const { return s; } template<class T> GetSizeHelper(const T &t) : s((int) t.size()) {} }; } #define SIZE (common::GetSizeHelper) namespace koo { template<class T> int unique(T &t, bool sorted = false) { if (!sorted) { sort(ALL(t)); } t.resize(unique(ALL(t)) - t.begin()); return SIZE t; } template <class T, class U> bool remin(T &a, const U &b) { return b < a ? a = b, true : false; } template <class T, class U> bool remax(T &a, const U &b) { return b > a ? a = b, true : false; } } #define dump fancy_dumper::DumpFirst<&std::cerr>(), #define say fancy_dumper::DumpFirst<&std::cout>(), #define $dump fancy_dumper::Dumper<&std::cerr> #define $say fancy_dumper::Dumper<&std::cout> #ifndef $ #define $(x) #x, fancy_dumper::ToggleSeparator(), (x),\ fancy_dumper::ToggleSeparator() #endif namespace fancy_dumper { using std::ostream; struct ToggleSeparator { }; template<ostream *Out> struct DumpFirst { }; template<ostream *Out> struct Dumper { static void *&last() { static void *p; return p; } static const char *&separator() { static const char *s = " "; return s; } static const char *&separatorNewLine() { static const char *s = "\n"; return s; } static const char *&unseparator() { static const char *s = "="; return s; } Dumper() { last() = this; } ~Dumper() { if (this == last()) { *Out << separatorNewLine(); } } Dumper operator, (ToggleSeparator) { std::swap(separator(), unseparator()); return Dumper(); } }; template<ostream *Out, class T> Dumper<Out> operator,(Dumper<Out>, const T &e) { *Out << Dumper<Out>::separator() << e; return Dumper<Out>(); } template<ostream *Out, class T> Dumper<Out> operator, (DumpFirst<Out>, const T &e) { *Out << e; return Dumper<Out>(); } } namespace koo { using namespace std; template<class T> T fromString(const string &s) { T t; istringstream(s) >> t; return t; } template<class T> string toString(const T &t) { ostringstream oss; oss << t; return oss.str(); } template<class T, class Y> ostream &operator<< (ostream &o, const pair<T, Y> &p) { return o << p.first << ' ' << p.second; } template<class T> ostream &operator<< (ostream &o, const vector<T> &v) { EACH (e, v) { if (!isBegin(e)) { o << ' '; } o << e; } return o; } template<class T> ostream &operator,(ostream &o, const T &t) { return o << t; } template<class T> istream &operator,(istream &i, T &t) { return i >> t; } } using namespace std; using namespace rel_ops; using namespace koo; const int inf = 1000000001; typedef long long ll; typedef unsigned long long ull; // end of default code void read_and_find_characteristic(int n, int w, vector<int> &out) { vector<pair<int,pair<int,int>>> v(n + 1); REP (i, n) { int x, y, y2; cin, x, y, x, y2; y = abs(y - y2); v[i] = make_pair(x, make_pair(y, i)); } v[n] = make_pair(inf, make_pair(inf, inf)); sort(ALL(v)); priority_queue<pair<int,int>> q; FOR (i, 0, n) { if (v[i].second.first * 2 > w) { while (!q.empty()) { const int y = q.top().first; if (y + v[i].second.first > w) { out[q.top().second] = v[i].second.second; q.pop(); } else { break; } } } q.push(v[i].second); } assert(SIZE q == 1); } bool test() { int n, w; cin, n, w; vector<int> v1(n), v2(n); read_and_find_characteristic(n, w, v1); read_and_find_characteristic(n, w, v2); return v1 == v2; } int main() { ios::sync_with_stdio(0); int tests; cin, tests; FOR (tt, 1, tests) { say test() ? "TAK" : "NIE"; } } |