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
#include <cstdio>
#include <vector>
#include <algorithm>
//#include <chrono>

int main()
{
	//std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
	int t;
	scanf("%d", &t);
	while (t--) {
		int n;
		scanf("%d", &n);
		int w1, w2, h1, h2;
		int minw, maxw, minh, maxh;
		int tw1, tw2, th1, th2;
		bool p = true;
		scanf("%d%d%d%d", &minw, &maxw, &minh, &maxh);
		while (--n) {
			scanf("%d%d%d%d", &w1, &w2, &h1, &h2);
			if (p) {
				if (w1 <= minw && maxw <= w2 && h1 <= minh && maxh <= h2) { 
					minw = w1; maxw = w2;
					minh = h1; maxh = h2;
				} else if (((minh <= h1) != (h2 <= maxh)) || ((minw <= w1) != (w2 <= maxw))) {
					tw1 = std::min(minw, w1); tw2 = std::max(maxw, w2);
					th1 = std::min(minh, h1); th2 = std::max(maxh, h2);
					p = false;
				}
			} else {
				if (w1 <= tw1 && tw2 <= w2 && h1 <= th1 && th2 <= h2) {
					minw = w1; maxw = w2;
					minh = h1; maxh = h2;
					p = true;
				} else {
					tw1 = std::min(tw1, w1); tw2 = std::max(tw2, w2);
					th1 = std::min(th1, h1); th2 = std::max(th2, h2);
				}
			}
		}
		printf(p ? "TAK\n" : "NIE\n");
	}
	//printf("\nElapsed: %lf\n", std::chrono::duration_cast<std::chrono::duration<double> >(std::chrono::high_resolution_clock::now() - start).count());
	return 0;
}