//Andrzej Jabłoński #include "bits/stdc++.h" #define forx(i,b,e) for(std::common_type<decltype(b, e)>::type i = (b), ie = (e); i < ie; i++) #define pow2(x) (1ll<<(x)) #define all(x) begin(x), end(x) #define until(x) while(!(x)) #define len(x) (int)size(x) using namespace std; using llong = long long; template<class T> void __echo(const T& x, string sep) { cerr << x << sep; } void __echo(const string& x, string sep) { cerr << "\"" << x << "\"" << sep; } void __echo(const char& x, string sep = ", ") { cerr << "\'" << x << "\'" << sep; } template<class T> void __echo(const vector<T>& x, string sep) { cerr << "{"; for (size_t i = 0; i < x.size(); i++) __echo(x[i], i + 1 == x.size() ? "" : ", "); cerr << "}" << sep; } template<class T1, class T2> void __echo(const pair<T1, T2>& x, string sep = ", ") { cerr << "("; __echo(x.first, ", "); __echo(x.second, ""); cerr << ")" << sep; } void __echo(istringstream& stream) { cerr << "\n"; } template<size_t> struct Int {}; template<class Tuple, size_t Pos> void print_tuple(const Tuple& x, Int<Pos>) { __echo(get<tuple_size<Tuple>::value - Pos>(x), ", "); print_tuple(x, Int<Pos - 1>()); } template<class Tuple> void print_tuple(const Tuple& x, Int<1>) { cerr << get<tuple_size<Tuple>::value - 1>(x); } template<class... Args> void print_tuple(const tuple<Args...>& x) { print_tuple(x, Int<sizeof... (Args)>()); } template<class... Args> void __echo(const tuple<Args...>& x, string sep) { cerr << "("; print_tuple(x); cerr << ")" << sep; } template<class T> bool _char_const(const T& x) { return false; } bool _char_const(const char* x) { cerr << x; return true; } template<class T> bool isCharConst(const T& x) { return false; } bool isCharConst(const char* x) { return true; } string trim(string x) { return string(begin(x) + x.find_first_not_of(' '), begin(x) + x.find_last_not_of(' ') + 1); } template<class T, class... Args> void __echo(istringstream& stream, const T& x, Args... args) { static int cnt[200] = { 0 };//no bo po co to tworzyc od nowa? string name; do { string s; getline(stream, s, ','); for (auto c : s) cnt[(int)c]++; name += s + ','; } while (not(cnt['('] == cnt[')'] && cnt['['] == cnt[']'] && cnt['{'] == cnt['}'] && cnt['\"'] % 2 == 0 && cnt['\''] % 2 == 0)); name.pop_back();//usuwamy ',' if (!_char_const(x)) { cerr << trim(name) << " = "; __echo(x, "; "); } __echo(stream, args...); } #define echo(...) if(DBG) {istringstream str(#__VA_ARGS__); __echo(str, __VA_ARGS__); } ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// #define TESTSETS 0 #define DBG 0 constexpr int mod = int(1000'000'000 + 7); void solve() { int n, k; cin >> n >> k; vector<int> a(n); for (auto& ai : a) cin >> ai; if (k == 2) { vector<int> min_pref(n); vector<int> max_suff(n); min_pref[0] = a[0]; max_suff[n - 1] = a[n - 1]; forx(i, 1, n) min_pref[i] = min(min_pref[i - 1], a[i]); for (int i = n - 2; i >= 0; i--) max_suff[i] = max(max_suff[i + 1], a[i]); forx(v, 0, n - 1) if (min_pref[v] >= max_suff[v + 1]) return void(cout << "TAK\n" << v + 1 << "\n"); return void(cout << "NIE\n"); } else if (k == 3) { int mnp = 0; forx(i, 1, n) if (a[i] <= a[mnp]) mnp = i; int mxp = n - 1; for (int i = n - 2; i >= 0; i--) if (a[i] >= a[mxp]) mxp = i; if (mnp == 0 && mxp == n - 1) return void(cout << "NIE\n"); cout << "TAK\n"; if (mnp > 0) { if (mnp < n - 1) { return void(cout << mnp << " " << mnp + 1 << "\n"); } else { return void(cout << n - 2 << " " << n - 1 << "\n"); } } else { if (mxp > 0) { return void(cout << mxp << " " << mxp + 1 << "\n"); } else { return void(cout << 1 << " " << 2 << "\n"); } } } else { forx(v, 0, n - 1) { if (a[v] >= a[v + 1]) { cout << "TAK\n"; if (v == 0) { cout << "1 2 3 "; k -= 4; for (int p = 4; k; p++, k--) cout << p << " "; } else if (v + 1 == n - 1) { k -= 4; for (int p = 1; k && p < n - 3; p++, k--) cout << p << " "; cout << n - 3 << " " << n - 2 << " " << n - 1 << " "; } else { k -= 4; for (int p = 1; k && p < v; p++, k--) cout << p << " "; cout << v << " " << v + 1 << " " << v + 2 << " "; for (int p = v+3; k; p++, k--) cout << p << " "; } return void(cout << "\n"); } } return void(cout << "NIE\n"); } } int main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; if (TESTSETS) cin >> t; while (t--) solve(); }
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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | //Andrzej Jabłoński #include "bits/stdc++.h" #define forx(i,b,e) for(std::common_type<decltype(b, e)>::type i = (b), ie = (e); i < ie; i++) #define pow2(x) (1ll<<(x)) #define all(x) begin(x), end(x) #define until(x) while(!(x)) #define len(x) (int)size(x) using namespace std; using llong = long long; template<class T> void __echo(const T& x, string sep) { cerr << x << sep; } void __echo(const string& x, string sep) { cerr << "\"" << x << "\"" << sep; } void __echo(const char& x, string sep = ", ") { cerr << "\'" << x << "\'" << sep; } template<class T> void __echo(const vector<T>& x, string sep) { cerr << "{"; for (size_t i = 0; i < x.size(); i++) __echo(x[i], i + 1 == x.size() ? "" : ", "); cerr << "}" << sep; } template<class T1, class T2> void __echo(const pair<T1, T2>& x, string sep = ", ") { cerr << "("; __echo(x.first, ", "); __echo(x.second, ""); cerr << ")" << sep; } void __echo(istringstream& stream) { cerr << "\n"; } template<size_t> struct Int {}; template<class Tuple, size_t Pos> void print_tuple(const Tuple& x, Int<Pos>) { __echo(get<tuple_size<Tuple>::value - Pos>(x), ", "); print_tuple(x, Int<Pos - 1>()); } template<class Tuple> void print_tuple(const Tuple& x, Int<1>) { cerr << get<tuple_size<Tuple>::value - 1>(x); } template<class... Args> void print_tuple(const tuple<Args...>& x) { print_tuple(x, Int<sizeof... (Args)>()); } template<class... Args> void __echo(const tuple<Args...>& x, string sep) { cerr << "("; print_tuple(x); cerr << ")" << sep; } template<class T> bool _char_const(const T& x) { return false; } bool _char_const(const char* x) { cerr << x; return true; } template<class T> bool isCharConst(const T& x) { return false; } bool isCharConst(const char* x) { return true; } string trim(string x) { return string(begin(x) + x.find_first_not_of(' '), begin(x) + x.find_last_not_of(' ') + 1); } template<class T, class... Args> void __echo(istringstream& stream, const T& x, Args... args) { static int cnt[200] = { 0 };//no bo po co to tworzyc od nowa? string name; do { string s; getline(stream, s, ','); for (auto c : s) cnt[(int)c]++; name += s + ','; } while (not(cnt['('] == cnt[')'] && cnt['['] == cnt[']'] && cnt['{'] == cnt['}'] && cnt['\"'] % 2 == 0 && cnt['\''] % 2 == 0)); name.pop_back();//usuwamy ',' if (!_char_const(x)) { cerr << trim(name) << " = "; __echo(x, "; "); } __echo(stream, args...); } #define echo(...) if(DBG) {istringstream str(#__VA_ARGS__); __echo(str, __VA_ARGS__); } ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// #define TESTSETS 0 #define DBG 0 constexpr int mod = int(1000'000'000 + 7); void solve() { int n, k; cin >> n >> k; vector<int> a(n); for (auto& ai : a) cin >> ai; if (k == 2) { vector<int> min_pref(n); vector<int> max_suff(n); min_pref[0] = a[0]; max_suff[n - 1] = a[n - 1]; forx(i, 1, n) min_pref[i] = min(min_pref[i - 1], a[i]); for (int i = n - 2; i >= 0; i--) max_suff[i] = max(max_suff[i + 1], a[i]); forx(v, 0, n - 1) if (min_pref[v] >= max_suff[v + 1]) return void(cout << "TAK\n" << v + 1 << "\n"); return void(cout << "NIE\n"); } else if (k == 3) { int mnp = 0; forx(i, 1, n) if (a[i] <= a[mnp]) mnp = i; int mxp = n - 1; for (int i = n - 2; i >= 0; i--) if (a[i] >= a[mxp]) mxp = i; if (mnp == 0 && mxp == n - 1) return void(cout << "NIE\n"); cout << "TAK\n"; if (mnp > 0) { if (mnp < n - 1) { return void(cout << mnp << " " << mnp + 1 << "\n"); } else { return void(cout << n - 2 << " " << n - 1 << "\n"); } } else { if (mxp > 0) { return void(cout << mxp << " " << mxp + 1 << "\n"); } else { return void(cout << 1 << " " << 2 << "\n"); } } } else { forx(v, 0, n - 1) { if (a[v] >= a[v + 1]) { cout << "TAK\n"; if (v == 0) { cout << "1 2 3 "; k -= 4; for (int p = 4; k; p++, k--) cout << p << " "; } else if (v + 1 == n - 1) { k -= 4; for (int p = 1; k && p < n - 3; p++, k--) cout << p << " "; cout << n - 3 << " " << n - 2 << " " << n - 1 << " "; } else { k -= 4; for (int p = 1; k && p < v; p++, k--) cout << p << " "; cout << v << " " << v + 1 << " " << v + 2 << " "; for (int p = v+3; k; p++, k--) cout << p << " "; } return void(cout << "\n"); } } return void(cout << "NIE\n"); } } int main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; if (TESTSETS) cin >> t; while (t--) solve(); } |