// region standard #pragma GCC optimize "-O3" #include <bits/stdc++.h> using namespace std; #pragma GCC diagnostic ignored "-Wunused-macros" namespace std { // type_traits logical operations mock for C++11 #if __cplusplus < 201700L template <bool B> using bool_constant = integral_constant<bool, B>; template<typename...> struct conjunction : true_type { }; template<typename B1> struct conjunction<B1> : B1 { }; template<typename B1, typename... Bn> struct conjunction<B1, Bn...> : conditional<bool(B1::value), conjunction<Bn...>, B1>::type { }; template<class...> struct disjunction : false_type { }; template<class B1> struct disjunction<B1> : B1 { }; template<class B1, class... Bn> struct disjunction<B1, Bn...> : conditional<bool(B1::value), B1, disjunction<Bn...>>::type { }; template<typename B> struct negation : bool_constant<!bool(B::value)> { }; #endif } #define guard(x) if (!(x)) #define _CAT(A, B) A ## B #define CAT(A, B) _CAT(A, B) #define _CAT3(A, B, C) A ## B ## C #define CAT3(A, B, C) _CAT3(A, B, C) #define _STR(...) #__VA_ARGS__ #define STR(...) _STR(__VA_ARGS__) #define _FIRST(F, ...) F #define FIRST(...) _FIRST(__VA_ARGS__, ) #define SKIP1(F, ...) __VA_ARGS__ #define SKIP2(F, ...) SKIP1(__VA_ARGS__, ) #define SKIP3(F, ...) SKIP2(__VA_ARGS__, ) #define SKIP4(F, ...) SKIP3(__VA_ARGS__, ) #define SKIP5(F, ...) SKIP4(__VA_ARGS__, ) #define SKIP6(F, ...) SKIP5(__VA_ARGS__, ) #define SKIP7(F, ...) SKIP6(__VA_ARGS__, ) #define SKIP8(F, ...) SKIP7(__VA_ARGS__, ) #define SKIP9(F, ...) SKIP8(__VA_ARGS__, ) #define SKIP10(F, ...) SKIP9(__VA_ARGS__, ) #define SKIP11(F, ...) SKIP10(__VA_ARGS__, ) #define SKIP12(F, ...) SKIP11(__VA_ARGS__, ) #define SKIP(N, ...) CAT(SKIP, N)(__VA_ARGS__, ) #define COUNT(...) FIRST(SKIP12(__VA_ARGS__, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)) #ifdef DEBUG #define MAGIC do { std::clog << boolalpha; } while(0) #define PRINT(msg) do { std::clog << "DBG:" << __LINE__ << "> " << msg << std::endl; } while(0) #else #define MAGIC do { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } while(0) #define PRINT(msg) do { } while(0) #define clog DONT_USE_CLOG!!!!!!! #define cerr DONT_USE_CERR!!!!!!! #define endl DONT_USE_ENDL!!!!!!! #endif #define _DBG1(x, ...) STR(x) << ": " << (x) #define _DBG2(x, ...) STR(x) << ": " << (x) << " \t" << _DBG1(__VA_ARGS__) #define _DBG3(x, ...) STR(x) << ": " << (x) << " \t" << _DBG2(__VA_ARGS__) #define _DBG4(x, ...) STR(x) << ": " << (x) << " \t" << _DBG3(__VA_ARGS__) #define _DBG5(x, ...) STR(x) << ": " << (x) << " \t" << _DBG4(__VA_ARGS__) #define _DBG6(x, ...) STR(x) << ": " << (x) << " \t" << _DBG5(__VA_ARGS__) #define _DBG7(x, ...) STR(x) << ": " << (x) << " \t" << _DBG6(__VA_ARGS__) #define _DBG8(x, ...) STR(x) << ": " << (x) << " \t" << _DBG7(__VA_ARGS__) #define _DBG9(x, ...) STR(x) << ": " << (x) << " \t" << _DBG8(__VA_ARGS__) #define _DBG10(x, ...) STR(x) << ": " << (x) << " \t" << _DBG9(__VA_ARGS__) #define _DBG11(x, ...) STR(x) << ": " << (x) << " \t" << _DBG10(__VA_ARGS__) #define _DBG12(x, ...) STR(x) << ": " << (x) << " \t" << _DBG11(__VA_ARGS__) #define _DBG(...) CAT(_DBG, COUNT(__VA_ARGS__))(__VA_ARGS__, ) #define DBG(...) PRINT(_DBG(__VA_ARGS__)) #define PDBG(msg, ...) PRINT(msg << _DBG(__VA_ARGS__)) #define ST first #define ND second #define EM emplace #define EB emplace_back #define IN insert #define PB push_back #define vec vector #define umap unordered_map #define nil nullptr using ll = long long; using ull = unsigned long long; using ld = long double; using str = string; using PI = pair<int, int>; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<ll>; template <typename T, unsigned long N> char(&dim_helper(T(&)[N]))[N]; #define ASZ(x) ((ll)(sizeof(dim_helper((x))))) #define SZ(x) ((ll)((x).size())) #define ALL(x) std::begin((x)), std::end((x)) #define PAL(p) (p).ST, (p).ND #define FI(e, v) for (auto const & e : (v)) #define _FS(i, s, n, r, type) for (type i = s; r ? i > n : i < n; i += 1 - 2*r) #define FS(i, s, n) _FS(i, (s), (n), ((s) > (n)), remove_cv<__typeof((n))>::type) #define FR(i, n) FS(i, 0, (n)) #define _RS(i, s, n, r, type) for (type i = s; r ? i >= n : i <= n; i += 1 - 2*r) #define RS(i, s, n) _RS(i, (s), (n), ((s) > (n)), remove_cv<__typeof((n))>::type) #define RR(i, n) RS(i, 1, (n)) template <typename T> inline T safemod(T x, T m) { return (x % m + m) % m; } template <typename T> inline T mini(T & a, T const & b) { return a = min(a, b); } template <typename T> inline T maxi(T & a, T const & b) { return a = max(a, b); } template <typename T> inline T fpow(T a, ull b, T M) { T r(1); while (b > 0) { if (b & 1) { r *= a; r %= M; } a *= a; a %= M; b >>= 1; } return r; } // ostream out ostream template <typename Iter> void ooo(Iter first, Iter last, char const * delim, ostream & os) { while (first != last) { os << *(first++) << delim; } } // ostream out template <typename Iter> inline void oo(Iter first, Iter last, char const * delim) { ooo(first, last, delim, cout); } // container ostream out template <typename C> inline void coo(C V, char const * delim) { ooo(ALL(V), delim, cout); } // infix out ostream template <typename Iter> void ioo(Iter first, Iter last, char const * delim, ostream & os) { goto delim_jmp; while (first != last) { os << delim; delim_jmp: os << *(first++); } } // infix out template <typename Iter> inline void io(Iter first, Iter last, char const * delim) { ioo(first, last, delim, cout); } // container infix out template <typename C> inline void cio(C V, char const * delim) { ioo(ALL(V), delim, cout); } #ifdef DEBUG template<typename T, typename S> ostream & operator << (ostream & os, pair<T, S> const & p) { return os << "(" << p.ST << ", " << p.ND << ")"; } template<typename... Args> ostream & operator << (ostream & os, multimap<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}"; } template<typename... Args> ostream & operator << (ostream & os, map<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}"; } template<typename... Args> ostream & operator << (ostream & os, multiset<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}"; } template<typename... Args> ostream & operator << (ostream & os, set<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}"; } template<typename... Args> ostream & operator << (ostream & os, vector<Args...> const & V) { os << "["; ioo(ALL(V), ", ", os); return os << "]"; } template<typename... Args> ostream & operator << (ostream & os, valarray<Args...> const & VA) { os << "["; ioo(ALL(VA), ", ", os); return os << "]"; } #endif // istream in istream template <typename Iter> void iii(Iter to, ll n, istream & is) { while(n--) { is >> *(to++); } } // istream in template <typename Iter> void ii(Iter to, ll const & n) { iii(to, n, cin); } // container istream in template <typename C> void cii(C & V, ll const & n) { iii(V.begin(), n, cin); } // container istream in template <typename C> C cii(ll const & n) { C V(n); iii(V.begin(), n, cin); return V; } template<typename WEIGHT, typename NODE = int> struct _Node { NODE v; _Node() : _Node(0) { } _Node(NODE const _v) : v(_v) { } operator NODE () const { return v; } WEIGHT w() const; WEIGHT w(NODE u) const; WEIGHT w(_Node u) const { return w(u.v); } _Node & operator [] (NODE u) const; _Node & operator [] (_Node u) const { return operator [] (u.v); } friend istream & operator >> (istream & is, _Node & self) { return is >> self.v; } friend ostream & operator << (ostream & os, _Node const & self) { return os << self.v; } }; // endregion struct Algo { struct Baj { ll l; ll a; ll b; friend istream & operator >> (istream & is, Baj & self) { ll a, b, c; is >> a >> b >> c; self = {a, b, c}; return is; } }; int N; vec<Baj> BAJ; void main() { cin >> N; BAJ = cii<decltype(BAJ)>(N); ll mxA = accumulate(ALL(BAJ), LLONG_MIN, [](ll m, const auto & t) { return max(m, t.a); }); ll mxB = accumulate(ALL(BAJ), LLONG_MIN, [](ll m, const auto & t) { return max(m, t.b); }); ll miA = accumulate(ALL(BAJ), LLONG_MAX, [](ll m, const auto & t) { return min(m, t.a); }); ll miB = accumulate(ALL(BAJ), LLONG_MAX, [](ll m, const auto & t) { return min(m, t.b); }); ll accA = accumulate(ALL(BAJ), 0LL, [](ll acc, const auto & t) { return acc + t.l * t.a; }); ll accB = accumulate(ALL(BAJ), 0LL, [](ll acc, const auto & t) { return acc + t.l * t.b; }); guard (miA <= miB && mxB <= mxA && accA == accB) { cout << "NIE\n"; return; } cout << "TAK\n"; } }; int main() { MAGIC; int T; cin >> T; while (T--) { Algo().main(); } }
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 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | // region standard #pragma GCC optimize "-O3" #include <bits/stdc++.h> using namespace std; #pragma GCC diagnostic ignored "-Wunused-macros" namespace std { // type_traits logical operations mock for C++11 #if __cplusplus < 201700L template <bool B> using bool_constant = integral_constant<bool, B>; template<typename...> struct conjunction : true_type { }; template<typename B1> struct conjunction<B1> : B1 { }; template<typename B1, typename... Bn> struct conjunction<B1, Bn...> : conditional<bool(B1::value), conjunction<Bn...>, B1>::type { }; template<class...> struct disjunction : false_type { }; template<class B1> struct disjunction<B1> : B1 { }; template<class B1, class... Bn> struct disjunction<B1, Bn...> : conditional<bool(B1::value), B1, disjunction<Bn...>>::type { }; template<typename B> struct negation : bool_constant<!bool(B::value)> { }; #endif } #define guard(x) if (!(x)) #define _CAT(A, B) A ## B #define CAT(A, B) _CAT(A, B) #define _CAT3(A, B, C) A ## B ## C #define CAT3(A, B, C) _CAT3(A, B, C) #define _STR(...) #__VA_ARGS__ #define STR(...) _STR(__VA_ARGS__) #define _FIRST(F, ...) F #define FIRST(...) _FIRST(__VA_ARGS__, ) #define SKIP1(F, ...) __VA_ARGS__ #define SKIP2(F, ...) SKIP1(__VA_ARGS__, ) #define SKIP3(F, ...) SKIP2(__VA_ARGS__, ) #define SKIP4(F, ...) SKIP3(__VA_ARGS__, ) #define SKIP5(F, ...) SKIP4(__VA_ARGS__, ) #define SKIP6(F, ...) SKIP5(__VA_ARGS__, ) #define SKIP7(F, ...) SKIP6(__VA_ARGS__, ) #define SKIP8(F, ...) SKIP7(__VA_ARGS__, ) #define SKIP9(F, ...) SKIP8(__VA_ARGS__, ) #define SKIP10(F, ...) SKIP9(__VA_ARGS__, ) #define SKIP11(F, ...) SKIP10(__VA_ARGS__, ) #define SKIP12(F, ...) SKIP11(__VA_ARGS__, ) #define SKIP(N, ...) CAT(SKIP, N)(__VA_ARGS__, ) #define COUNT(...) FIRST(SKIP12(__VA_ARGS__, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)) #ifdef DEBUG #define MAGIC do { std::clog << boolalpha; } while(0) #define PRINT(msg) do { std::clog << "DBG:" << __LINE__ << "> " << msg << std::endl; } while(0) #else #define MAGIC do { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } while(0) #define PRINT(msg) do { } while(0) #define clog DONT_USE_CLOG!!!!!!! #define cerr DONT_USE_CERR!!!!!!! #define endl DONT_USE_ENDL!!!!!!! #endif #define _DBG1(x, ...) STR(x) << ": " << (x) #define _DBG2(x, ...) STR(x) << ": " << (x) << " \t" << _DBG1(__VA_ARGS__) #define _DBG3(x, ...) STR(x) << ": " << (x) << " \t" << _DBG2(__VA_ARGS__) #define _DBG4(x, ...) STR(x) << ": " << (x) << " \t" << _DBG3(__VA_ARGS__) #define _DBG5(x, ...) STR(x) << ": " << (x) << " \t" << _DBG4(__VA_ARGS__) #define _DBG6(x, ...) STR(x) << ": " << (x) << " \t" << _DBG5(__VA_ARGS__) #define _DBG7(x, ...) STR(x) << ": " << (x) << " \t" << _DBG6(__VA_ARGS__) #define _DBG8(x, ...) STR(x) << ": " << (x) << " \t" << _DBG7(__VA_ARGS__) #define _DBG9(x, ...) STR(x) << ": " << (x) << " \t" << _DBG8(__VA_ARGS__) #define _DBG10(x, ...) STR(x) << ": " << (x) << " \t" << _DBG9(__VA_ARGS__) #define _DBG11(x, ...) STR(x) << ": " << (x) << " \t" << _DBG10(__VA_ARGS__) #define _DBG12(x, ...) STR(x) << ": " << (x) << " \t" << _DBG11(__VA_ARGS__) #define _DBG(...) CAT(_DBG, COUNT(__VA_ARGS__))(__VA_ARGS__, ) #define DBG(...) PRINT(_DBG(__VA_ARGS__)) #define PDBG(msg, ...) PRINT(msg << _DBG(__VA_ARGS__)) #define ST first #define ND second #define EM emplace #define EB emplace_back #define IN insert #define PB push_back #define vec vector #define umap unordered_map #define nil nullptr using ll = long long; using ull = unsigned long long; using ld = long double; using str = string; using PI = pair<int, int>; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<ll>; template <typename T, unsigned long N> char(&dim_helper(T(&)[N]))[N]; #define ASZ(x) ((ll)(sizeof(dim_helper((x))))) #define SZ(x) ((ll)((x).size())) #define ALL(x) std::begin((x)), std::end((x)) #define PAL(p) (p).ST, (p).ND #define FI(e, v) for (auto const & e : (v)) #define _FS(i, s, n, r, type) for (type i = s; r ? i > n : i < n; i += 1 - 2*r) #define FS(i, s, n) _FS(i, (s), (n), ((s) > (n)), remove_cv<__typeof((n))>::type) #define FR(i, n) FS(i, 0, (n)) #define _RS(i, s, n, r, type) for (type i = s; r ? i >= n : i <= n; i += 1 - 2*r) #define RS(i, s, n) _RS(i, (s), (n), ((s) > (n)), remove_cv<__typeof((n))>::type) #define RR(i, n) RS(i, 1, (n)) template <typename T> inline T safemod(T x, T m) { return (x % m + m) % m; } template <typename T> inline T mini(T & a, T const & b) { return a = min(a, b); } template <typename T> inline T maxi(T & a, T const & b) { return a = max(a, b); } template <typename T> inline T fpow(T a, ull b, T M) { T r(1); while (b > 0) { if (b & 1) { r *= a; r %= M; } a *= a; a %= M; b >>= 1; } return r; } // ostream out ostream template <typename Iter> void ooo(Iter first, Iter last, char const * delim, ostream & os) { while (first != last) { os << *(first++) << delim; } } // ostream out template <typename Iter> inline void oo(Iter first, Iter last, char const * delim) { ooo(first, last, delim, cout); } // container ostream out template <typename C> inline void coo(C V, char const * delim) { ooo(ALL(V), delim, cout); } // infix out ostream template <typename Iter> void ioo(Iter first, Iter last, char const * delim, ostream & os) { goto delim_jmp; while (first != last) { os << delim; delim_jmp: os << *(first++); } } // infix out template <typename Iter> inline void io(Iter first, Iter last, char const * delim) { ioo(first, last, delim, cout); } // container infix out template <typename C> inline void cio(C V, char const * delim) { ioo(ALL(V), delim, cout); } #ifdef DEBUG template<typename T, typename S> ostream & operator << (ostream & os, pair<T, S> const & p) { return os << "(" << p.ST << ", " << p.ND << ")"; } template<typename... Args> ostream & operator << (ostream & os, multimap<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}"; } template<typename... Args> ostream & operator << (ostream & os, map<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}"; } template<typename... Args> ostream & operator << (ostream & os, multiset<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}"; } template<typename... Args> ostream & operator << (ostream & os, set<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}"; } template<typename... Args> ostream & operator << (ostream & os, vector<Args...> const & V) { os << "["; ioo(ALL(V), ", ", os); return os << "]"; } template<typename... Args> ostream & operator << (ostream & os, valarray<Args...> const & VA) { os << "["; ioo(ALL(VA), ", ", os); return os << "]"; } #endif // istream in istream template <typename Iter> void iii(Iter to, ll n, istream & is) { while(n--) { is >> *(to++); } } // istream in template <typename Iter> void ii(Iter to, ll const & n) { iii(to, n, cin); } // container istream in template <typename C> void cii(C & V, ll const & n) { iii(V.begin(), n, cin); } // container istream in template <typename C> C cii(ll const & n) { C V(n); iii(V.begin(), n, cin); return V; } template<typename WEIGHT, typename NODE = int> struct _Node { NODE v; _Node() : _Node(0) { } _Node(NODE const _v) : v(_v) { } operator NODE () const { return v; } WEIGHT w() const; WEIGHT w(NODE u) const; WEIGHT w(_Node u) const { return w(u.v); } _Node & operator [] (NODE u) const; _Node & operator [] (_Node u) const { return operator [] (u.v); } friend istream & operator >> (istream & is, _Node & self) { return is >> self.v; } friend ostream & operator << (ostream & os, _Node const & self) { return os << self.v; } }; // endregion struct Algo { struct Baj { ll l; ll a; ll b; friend istream & operator >> (istream & is, Baj & self) { ll a, b, c; is >> a >> b >> c; self = {a, b, c}; return is; } }; int N; vec<Baj> BAJ; void main() { cin >> N; BAJ = cii<decltype(BAJ)>(N); ll mxA = accumulate(ALL(BAJ), LLONG_MIN, [](ll m, const auto & t) { return max(m, t.a); }); ll mxB = accumulate(ALL(BAJ), LLONG_MIN, [](ll m, const auto & t) { return max(m, t.b); }); ll miA = accumulate(ALL(BAJ), LLONG_MAX, [](ll m, const auto & t) { return min(m, t.a); }); ll miB = accumulate(ALL(BAJ), LLONG_MAX, [](ll m, const auto & t) { return min(m, t.b); }); ll accA = accumulate(ALL(BAJ), 0LL, [](ll acc, const auto & t) { return acc + t.l * t.a; }); ll accB = accumulate(ALL(BAJ), 0LL, [](ll acc, const auto & t) { return acc + t.l * t.b; }); guard (miA <= miB && mxB <= mxA && accA == accB) { cout << "NIE\n"; return; } cout << "TAK\n"; } }; int main() { MAGIC; int T; cin >> T; while (T--) { Algo().main(); } } |