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
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
int main()
{
 ios_base::sync_with_stdio(0);
int t, n, wmin, wmax, hmin, hmax;
int w1[100000], w2[100000], h1[100000], h2[100000];
cin>>t;
for(int k=0; k<t; k++){
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>w1[i]>>w2[i]>>h1[i]>>h2[i];
        }

        wmin=w1[0];
        wmax=w2[0];
        hmin=h1[0];
        hmax=0;
    for(int i=1; i<n; i++){
        if(h2[i]>h2[hmax]) hmax=i;
        else if(h2[i]==h2[hmax]){
            if(h1[i]<h1[hmax]) hmax=i;
            else if(h1[i]==h1[hmax]){
                if(w2[i]>w2[hmax])hmax=i;
                else if(w2[i]==w2[hmax])
                    if(w1[i]<w1[hmax])hmax=i;
                }
            }

        if(w1[i]<wmin) wmin=w1[i];
        if(w2[i]>wmax) wmax=w2[i];
        if(h1[i]<hmin) hmin=h1[i];
        }
    if(w1[hmax]==wmin && w2[hmax]==wmax && h1[hmax]==hmin) cout<<"TAK"<<endl;
    else cout<<"NIE"<<endl;

    }
    return 0;
}