// #pragma GCC optimize("O3") // #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define ordered_set \ // tree<PII, null_type, less<PII>, rb_tree_tag, \ // tree_order_statistics_node_update> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef pair<ld, ld> PLD; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<PII> VII; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<VII> VVII; typedef vector<PLL> VLL; typedef vector<VLL> VVLL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<bool> VB; typedef vector<VB> VVB; typedef vector<string> VS; template <class T, class G> ostream &operator<<(ostream &os, const pair<T, G> ¶) { os << para.first << " " << para.second; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (const T &el : vec) os << el << " "; return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &vec) { for (const T &el : vec) os << el << " "; return os; } #define REP(i, j) for (int i = 0; i < (j); i++) #define REP1(i, j) for (int i = 1; i < (j); i++) #define FOREACH(el, n) for (auto &el : n) #define pb push_back #define pf push_front #define st first #define nd second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define get_unique(x) x.erase(unique(all(x)), x.end()); #define sp ' ' #define ent '\n' // template <class T> void print_case(int i, T &x) { // cout << "Case #" << i << ": " << x << ent; // } // void prep() {} void TEST(int testcase_i) { int n, k; cin >> n >> k; VI v(n); REP(i, n) cin >> v[i]; if (k >= 4) { set<int> ans; for (int i = 1; i < n; ++i) { if (v[i - 1] >= v[i]) { if (i == 1) { ans.insert(1); ans.insert(2); ans.insert(3); break; } else if (i == n - 1) { ans.insert(i - 2); ans.insert(i - 1); ans.insert(i); break; } else { ans.insert(i - 1); ans.insert(i); ans.insert(i + 1); break; } } } if (ans.size() == 3) { for (int j = 1; j < n and ans.size() < k - 1; ++j) { ans.insert(j); } cout << "TAK" << ent; for (int el : ans) cout << el << sp; return; } } else if (k == 2) { VI pref_min(n + 5), suf_max(n + 5); pref_min[0] = v[0]; for (int i = 1; i < n; ++i) { pref_min[i] = min(pref_min[i - 1], v[i]); } suf_max[n - 1] = v[n - 1]; for (int i = n - 2; i >= 0; --i) { suf_max[i] = max(suf_max[i + 1], v[i]); } REP(i, n - 1) { if (pref_min[i] >= suf_max[i + 1]) { cout << "TAK" << ent; cout << i + 1 << ent; return; } } } else if (k == 3) { int mini = *min_element(all(v)); int maxi = *max_element(all(v)); int last_mini = 0; REP(i, n) { if (v[i] == mini) last_mini = i; } int first_maxi = n - 1; REP(i, n) { if (v[i] == maxi) { first_maxi = i; break; } } if (last_mini == n - 1) { cout << "TAK" << ent; cout << n - 2 << sp << n - 1 << ent; return; } if (last_mini != 0) { cout << "TAK" << ent; cout << last_mini << sp << last_mini + 1 << ent; return; } if (first_maxi == 0) { cout << "TAK" << ent; cout << 1 << sp << 2 << ent; return; } if (first_maxi != n - 1) { cout << "TAK" << ent; cout << first_maxi << sp << first_maxi + 1 << ent; return; } } else { assert(false); } cout << "NIE" << ent; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // cout << setprecision(16) << fixed; // srand(time(NULL)); // freopen("sorting.in", "r", stdin); // freopen("sorting.out", "w", stdout); // prep(); int t = 1; // cin >> t; REP(i, t) { TEST(i); } return 0; }
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 | // #pragma GCC optimize("O3") // #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define ordered_set \ // tree<PII, null_type, less<PII>, rb_tree_tag, \ // tree_order_statistics_node_update> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef pair<ld, ld> PLD; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<PII> VII; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<VII> VVII; typedef vector<PLL> VLL; typedef vector<VLL> VVLL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<bool> VB; typedef vector<VB> VVB; typedef vector<string> VS; template <class T, class G> ostream &operator<<(ostream &os, const pair<T, G> ¶) { os << para.first << " " << para.second; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (const T &el : vec) os << el << " "; return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &vec) { for (const T &el : vec) os << el << " "; return os; } #define REP(i, j) for (int i = 0; i < (j); i++) #define REP1(i, j) for (int i = 1; i < (j); i++) #define FOREACH(el, n) for (auto &el : n) #define pb push_back #define pf push_front #define st first #define nd second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define get_unique(x) x.erase(unique(all(x)), x.end()); #define sp ' ' #define ent '\n' // template <class T> void print_case(int i, T &x) { // cout << "Case #" << i << ": " << x << ent; // } // void prep() {} void TEST(int testcase_i) { int n, k; cin >> n >> k; VI v(n); REP(i, n) cin >> v[i]; if (k >= 4) { set<int> ans; for (int i = 1; i < n; ++i) { if (v[i - 1] >= v[i]) { if (i == 1) { ans.insert(1); ans.insert(2); ans.insert(3); break; } else if (i == n - 1) { ans.insert(i - 2); ans.insert(i - 1); ans.insert(i); break; } else { ans.insert(i - 1); ans.insert(i); ans.insert(i + 1); break; } } } if (ans.size() == 3) { for (int j = 1; j < n and ans.size() < k - 1; ++j) { ans.insert(j); } cout << "TAK" << ent; for (int el : ans) cout << el << sp; return; } } else if (k == 2) { VI pref_min(n + 5), suf_max(n + 5); pref_min[0] = v[0]; for (int i = 1; i < n; ++i) { pref_min[i] = min(pref_min[i - 1], v[i]); } suf_max[n - 1] = v[n - 1]; for (int i = n - 2; i >= 0; --i) { suf_max[i] = max(suf_max[i + 1], v[i]); } REP(i, n - 1) { if (pref_min[i] >= suf_max[i + 1]) { cout << "TAK" << ent; cout << i + 1 << ent; return; } } } else if (k == 3) { int mini = *min_element(all(v)); int maxi = *max_element(all(v)); int last_mini = 0; REP(i, n) { if (v[i] == mini) last_mini = i; } int first_maxi = n - 1; REP(i, n) { if (v[i] == maxi) { first_maxi = i; break; } } if (last_mini == n - 1) { cout << "TAK" << ent; cout << n - 2 << sp << n - 1 << ent; return; } if (last_mini != 0) { cout << "TAK" << ent; cout << last_mini << sp << last_mini + 1 << ent; return; } if (first_maxi == 0) { cout << "TAK" << ent; cout << 1 << sp << 2 << ent; return; } if (first_maxi != n - 1) { cout << "TAK" << ent; cout << first_maxi << sp << first_maxi + 1 << ent; return; } } else { assert(false); } cout << "NIE" << ent; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // cout << setprecision(16) << fixed; // srand(time(NULL)); // freopen("sorting.in", "r", stdin); // freopen("sorting.out", "w", stdout); // prep(); int t = 1; // cin >> t; REP(i, t) { TEST(i); } return 0; } |