//#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-all-loops") //#pragma GCC target("avx,sse2,sse3,ssse3,sse4,lzcnt,popcnt") #include <bits/stdc++.h> #include <fstream> #define ll long long #define point pair<int, int> #define X first #define Y second #define all(x) (x).begin(), (x).end() #define pb push_back #define show(x) cerr << (#x) << " = " << x << '\n' #define print(x) if (1) {cerr << (#x) << " = "; for (auto it : x) \ cerr << it << ' '; cerr << '\n';} #define fast_io ios_base::sync_with_stdio(0), cin.tie(0) using namespace std; const int N = 1000000 + 64; const int INF = 2e9 + 64; const ll MAX = 2e18 + 64; const int MOD = 998244353; int a[N], pmin[N], pmax[N], smin[N], smax[N], col[N], ptr = 2; signed main() { fast_io; int n, k; cin >> n >> k; for (int i = 0; i < n; ++i) cin >> a[i]; pmin[0] = pmax[0] = a[0]; for (int i = 1; i < n; ++i) pmin[i] = min(a[i], pmin[i - 1]), pmax[i] = max(pmax[i - 1], a[i]); smin[n - 1] = smax[n - 1] = a[n - 1]; for (int i = n - 2; i >= 0; --i) smin[i] = min(smin[i + 1], a[i]), smax[i] = max(smax[i + 1], a[i]); if (k == 2) { for (int i = 0; i + 1 < n; ++i) if (pmin[i] >= smax[i + 1]) return cout << "TAK\n" << i + 1 << '\n', 0; return cout << "NIE\n", 0; } if (k == 3) { for (int i = 0; i + 2 < n; ++i) if (pmin[i] >= a[i + 1]) return cout << "TAK\n" << i + 1 << ' ' << i + 2 << '\n', 0; for (int i = 2; i < n; ++i) if (smax[i] <= a[i - 1]) return cout << "TAK\n" << i - 1 << ' ' << i << '\n', 0; return cout << "NIE\n", 0; } for (int i = 0; i + 1 < n; ++i) if (a[i] >= a[i + 1]) { col[i] = 1, col[i + 1] = 2; ptr += (i > 0) + (i + 2 < n); for (int j = 0; j < n && ptr < k; ++j) if (!col[j] && ((j > 0 && col[j - 1] == col[j]) || (j + 1 < n && col[j] == col[j + 1]))) col[j] = ptr++; cout << "TAK\n"; for (int j = 1; j < n; ++j) if (col[j] != col[j - 1]) cout << j << ' '; return 0; } cout << "NIE\n"; }
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 | //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-all-loops") //#pragma GCC target("avx,sse2,sse3,ssse3,sse4,lzcnt,popcnt") #include <bits/stdc++.h> #include <fstream> #define ll long long #define point pair<int, int> #define X first #define Y second #define all(x) (x).begin(), (x).end() #define pb push_back #define show(x) cerr << (#x) << " = " << x << '\n' #define print(x) if (1) {cerr << (#x) << " = "; for (auto it : x) \ cerr << it << ' '; cerr << '\n';} #define fast_io ios_base::sync_with_stdio(0), cin.tie(0) using namespace std; const int N = 1000000 + 64; const int INF = 2e9 + 64; const ll MAX = 2e18 + 64; const int MOD = 998244353; int a[N], pmin[N], pmax[N], smin[N], smax[N], col[N], ptr = 2; signed main() { fast_io; int n, k; cin >> n >> k; for (int i = 0; i < n; ++i) cin >> a[i]; pmin[0] = pmax[0] = a[0]; for (int i = 1; i < n; ++i) pmin[i] = min(a[i], pmin[i - 1]), pmax[i] = max(pmax[i - 1], a[i]); smin[n - 1] = smax[n - 1] = a[n - 1]; for (int i = n - 2; i >= 0; --i) smin[i] = min(smin[i + 1], a[i]), smax[i] = max(smax[i + 1], a[i]); if (k == 2) { for (int i = 0; i + 1 < n; ++i) if (pmin[i] >= smax[i + 1]) return cout << "TAK\n" << i + 1 << '\n', 0; return cout << "NIE\n", 0; } if (k == 3) { for (int i = 0; i + 2 < n; ++i) if (pmin[i] >= a[i + 1]) return cout << "TAK\n" << i + 1 << ' ' << i + 2 << '\n', 0; for (int i = 2; i < n; ++i) if (smax[i] <= a[i - 1]) return cout << "TAK\n" << i - 1 << ' ' << i << '\n', 0; return cout << "NIE\n", 0; } for (int i = 0; i + 1 < n; ++i) if (a[i] >= a[i + 1]) { col[i] = 1, col[i + 1] = 2; ptr += (i > 0) + (i + 2 < n); for (int j = 0; j < n && ptr < k; ++j) if (!col[j] && ((j > 0 && col[j - 1] == col[j]) || (j + 1 < n && col[j] == col[j + 1]))) col[j] = ptr++; cout << "TAK\n"; for (int j = 1; j < n; ++j) if (col[j] != col[j - 1]) cout << j << ' '; return 0; } cout << "NIE\n"; } |