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
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define ii pair<int, int>
#define ll long long


int n, k, aa[500007], lv, maxik, minik;
int d1[1100000];    //drzewo mini
int d2[1100000];    //drzewo maxi
//Autor:    Jakub Wielocha
//          VI LO Radom
int query1(int a, int b, int w, int l, int r)
{
    if(b<l or r<a)
        return (1e9 +7);
    if(a<=l and r<=b)
        return d1[w];

    return min(query1(a, b, 2*w, l, (r+l)/2), query1(a, b, 2*w +1, (r+l)/2 +1, r));
}
int query2(int a, int b, int w, int l, int r)
{
    if(b<l or r<a)
        return 0;
    if(a<=l and r<=b)
        return d2[w];

    return max(query2(a, b, 2*w, l, (r+l)/2), query2(a, b, 2*w +1, (r+l)/2 +1, r));
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    for(int i = 1;i<=n;i++)
        cin>>aa[i];

    lv = 1;
    while(lv<n)
        lv*=2;

    for(int i = 1;i<=n;i++)
        d1[i+lv-1] = d2[i+lv-1] = aa[i];

    for(int i = lv+n;i<=2*lv;i++)
        d1[i] = 1e9 +7;

    for(int i = lv-1;i>0;i--)
        d2[i] = max(d2[2*i], d2[2*i +1]), d1[i] = min(d1[2*i], d1[2*i +1]);

    if(k==2)
    {
        for(int i = 1;i<n;i++)
        {
            minik = query1(1, i, 1, 1, lv);
            maxik = query2(i+1, n, 1, 1, lv);
            if(minik>=maxik)
            {
                cout<<"TAK\n";
                cout<<i;
                return 0;
            }
        }
        cout<<"NIE\n";
    }
    if(k==3)
    {
        for(int i = 1;i<n;i++)
            if(aa[i]==d2[1])
            {
                cout<<"TAK\n";
                if(i!=1)
                    cout<<i-1<<" "<<i;
                else
                    cout<<i<<" "<<i+1;
                return 0;
            }
        for(int i = 2;i<n;i++)
        {
            minik = query1(1, i-1, 1, 1, lv);
            if(minik>=aa[i])
            {
                cout<<"TAK\n";
                cout<<i-1<<" "<<i;
                return 0;
            }
        }

        cout<<"NIE\n";
    }
    if(k>=4)
    {
        for(int i = 1;i<n;i++)
            if(aa[i]>=aa[i+1])
            {
                cout<<"TAK\n";
                set<int> s;
                if(i!=1)
                    s.insert(i-1);
                s.insert(i);
                s.insert(i+1);
                int pom = 1;
                while(s.size()<k-1)
                {
                    s.insert(pom);
                    pom++;
                }
                set<int>::iterator it;
                for(it = s.begin();it!=s.end();it++)
                    cout<<(*it)<<" ";
                return 0;
            }
        cout<<"NIE\n";
    }
    return 0;
}