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
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include<list>
using namespace std;
#define fio cin.tie(0);ios_base::sync_with_stdio(0);
int series[500005];
bool ans[500005];
int main()
{
    fio;
    int n,k;
    cin>>n>>k;
    int ile_ans=1;
    ans[n]=1;
    for(int i=1;i<=n;i++)
    {
        cin>>series[i];
    }
    if(k==2)
    {
        /*pair<int,int> min={2000000000,-1};
        for(int i=1;i<=n;i++){if(series[i]<=min.first){min.first=series[i];min.second=i;}}
        //min lewo >= max prawo
        int minl=2000000000;
        for(int i=1;i<min.second;i++)
        {
            if(series[i]<minl){minl=series[i];}
        }
        int maxp=-1;
        for(int i=min.second;i<=n;i++)
        {
            if(series[i]>maxp){maxp=series[i];}
        }
        if(minl>=maxp)
        {
            cout<<"TAK\n";//<<min.second-1;
        }
        else{cout<<"NIE\n";return 0;}*/
        int minlew=series[1];
    list<pair<int,int>> maxpra;
    //wypelniamy maxpra dla calego ciagu
    maxpra.push_back({series[1],1});
    for(int i=2;i<=n;i++)
    {
        while(!maxpra.empty()&&series[i]>maxpra.back().first)
        {
            maxpra.pop_back();
        }
        maxpra.push_back({series[i],i});
    }
    if(maxpra.front().second==1){maxpra.pop_front();}
    if(minlew>=maxpra.front().first){cout<<"TAK\n1";return 0;}
    for(int i=2;i<n;i++)
    {
        if(series[i]<minlew){minlew=series[i];}
        if(maxpra.front().second==i){maxpra.pop_front();}
        if(minlew>=maxpra.front().first){cout<<"TAK\n"<<i;;return 0;}
    }

    cout<<"NIE\n";
    }



    else if(k==3)
    {
///przegladamy ciag trzymajac min dla 1->i-1  i max dla i+1->n  jeżeli minl>=series[i] lub maxp<=series[i]
    int minlew=series[1];
    list<pair<int,int>> maxpra;
    //wypelniamy maxpra dla calego ciagu
    maxpra.push_back({series[1],1});
    for(int i=2;i<=n;i++)
    {
        while(!maxpra.empty()&&series[i]>maxpra.back().first)
        {
            maxpra.pop_back();
        }
        maxpra.push_back({series[i],i});
    }
    /////////
    if(maxpra.front().first<=series[1]){cout<<"TAK\n1 2";return 0;}
    else{
        if(maxpra.front().second==1){maxpra.pop_front();}
    for(int i=2;i<n;i++)
    {
        if(series[i-1]<minlew){minlew=series[i-1];}
        if(maxpra.front().second==i){maxpra.pop_front();}
        if(minlew>=series[i]){cout<<"TAK\n"<<i-1<<" "<<i;return 0;}
        if(maxpra.front().first<=series[i]){cout<<"TAK\n"<<i-1<<" "<<i;return 0;}
    }
    }
        cout<<"NIE\n";
    }


    else
    {
        if(series[1]>=series[2])
        {
            ans[1]=1;ans[2]=1;
            ile_ans+=2;
        }
        else{
        for(int i=2;i<n;i++)
        {
            if(series[i]>=series[i+1])
            {
                ans[i-1]=1;ans[i]=1;ans[i+1]=1;
                ile_ans+=3;
            }
        } 
        }
        if(ile_ans==1){cout<<"NIE\n";}
        else{cout<<"TAK\n";
        for(int i=1;ile_ans<n;i++)
        {
            if(ans[i]==0){ile_ans++;ans[i]=1;}
        }
        for(int i=1;i<n;i++)
        {
            if(ans[i]==1){cout<<i<<" ";}
        }
        }

    }

    return 0;
}