// clang-format off #include <bits/stdc++.h> using namespace std; #define ALL(x) (x).begin(), (x).end() template<class C> void mini(C &a5, C b5) { a5 = min(a5, b5); } template<class C> void maxi(C &a5, C b5) { a5 = max(a5, b5); } #ifdef LOCAL const bool debug = true; #else const bool debug = false; #define cerr if (true) {} else cout #endif // clang-format on #define int long long #define double long double const int INF = 1e18; const int mod = 1e9 + 7; const int nax = 1e6 + 1000; int arr_[2][nax]; int idx_[2][nax]; int pre_min[nax]; int suf_max[nax]; multiset<int> s_[2]; set<int> solve2(int begin, int end, int* arr, int* idx) { pre_min[begin - 1] = INF; suf_max[end] = -INF; for (int i = begin; i < end; i++) { pre_min[i] = min(arr[i], pre_min[i-1]); } for (int i = end - 1; i >= begin; i--) { suf_max[i] = max(arr[i], suf_max[i+1]); } for (int i = begin; i+1 < end; i++) { if (pre_min[i] >= suf_max[i+1]) { return {idx[i]}; } } return {}; } set<int> solve3(int begin, int end, int* arr, int* idx, multiset<int> &s) { auto it = s.begin(); int smallest = *it; ++it; int second_smallest = *it; if (arr[begin] != smallest || arr[begin] == second_smallest) { for (int i = end - 1; i >= begin; i--) { if (arr[i] == smallest) { return {idx[i], idx[i]-1}; } } } return {}; } set<int> solve4(int begin, int end, int* arr) { for (int i = begin; i+1 < end; i++) { if (arr[i] >= arr[i+1]) { return {i-1,i,i+1}; } } return {}; } void output_result(set<int> &&s, int k, int n) { k--; if (s.empty()) { return; } s.erase(0); s.erase(n); if ((int)s.size() > k) { cout << "NIE\n"; exit(0); } int i = 1; while ((int)s.size() < k) { s.insert(i); i++; } cout << "TAK\n"; for (int j : s) { cout << j << " "; } cout << "\n"; if ((int)s.size() != k) { exit(1); } exit(0); } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { int a; cin >> a; arr_[0][i] = a; arr_[1][n-i+1] = -a; idx_[0][i] = i; idx_[1][n-i+1] = i; s_[0].insert(a); s_[1].insert(-a); } output_result(solve2(1, n+1, arr_[0], idx_[0]), k, n); for (int i = 0; i < 2; i++) { output_result(solve3(1, n+1, arr_[i], idx_[i], s_[i]), k, n); } output_result(solve4(1, n+1, arr_[0]), k, n); cout << "NIE\n"; return 0; }/* 6 3 3 5 4 8 3 7 * TAK 3 5 */
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 131 132 133 134 135 136 137 138 139 140 141 | // clang-format off #include <bits/stdc++.h> using namespace std; #define ALL(x) (x).begin(), (x).end() template<class C> void mini(C &a5, C b5) { a5 = min(a5, b5); } template<class C> void maxi(C &a5, C b5) { a5 = max(a5, b5); } #ifdef LOCAL const bool debug = true; #else const bool debug = false; #define cerr if (true) {} else cout #endif // clang-format on #define int long long #define double long double const int INF = 1e18; const int mod = 1e9 + 7; const int nax = 1e6 + 1000; int arr_[2][nax]; int idx_[2][nax]; int pre_min[nax]; int suf_max[nax]; multiset<int> s_[2]; set<int> solve2(int begin, int end, int* arr, int* idx) { pre_min[begin - 1] = INF; suf_max[end] = -INF; for (int i = begin; i < end; i++) { pre_min[i] = min(arr[i], pre_min[i-1]); } for (int i = end - 1; i >= begin; i--) { suf_max[i] = max(arr[i], suf_max[i+1]); } for (int i = begin; i+1 < end; i++) { if (pre_min[i] >= suf_max[i+1]) { return {idx[i]}; } } return {}; } set<int> solve3(int begin, int end, int* arr, int* idx, multiset<int> &s) { auto it = s.begin(); int smallest = *it; ++it; int second_smallest = *it; if (arr[begin] != smallest || arr[begin] == second_smallest) { for (int i = end - 1; i >= begin; i--) { if (arr[i] == smallest) { return {idx[i], idx[i]-1}; } } } return {}; } set<int> solve4(int begin, int end, int* arr) { for (int i = begin; i+1 < end; i++) { if (arr[i] >= arr[i+1]) { return {i-1,i,i+1}; } } return {}; } void output_result(set<int> &&s, int k, int n) { k--; if (s.empty()) { return; } s.erase(0); s.erase(n); if ((int)s.size() > k) { cout << "NIE\n"; exit(0); } int i = 1; while ((int)s.size() < k) { s.insert(i); i++; } cout << "TAK\n"; for (int j : s) { cout << j << " "; } cout << "\n"; if ((int)s.size() != k) { exit(1); } exit(0); } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { int a; cin >> a; arr_[0][i] = a; arr_[1][n-i+1] = -a; idx_[0][i] = i; idx_[1][n-i+1] = i; s_[0].insert(a); s_[1].insert(-a); } output_result(solve2(1, n+1, arr_[0], idx_[0]), k, n); for (int i = 0; i < 2; i++) { output_result(solve3(1, n+1, arr_[i], idx_[i], s_[i]), k, n); } output_result(solve4(1, n+1, arr_[0]), k, n); cout << "NIE\n"; return 0; }/* 6 3 3 5 4 8 3 7 * TAK 3 5 */ |