#ifndef LOCAL #pragma GCC optimize("O3") #endif #include <bits/stdc++.h> using namespace std; #define sim template < class c #define ris return * this #define mor > muu & operator << ( #define R22(r) sim > typename \ enable_if<1 r sizeof dud<c>(0), muu&>::type operator<<(c g) { sim > struct rge {c b, e; }; sim > rge<c> range(c h, c n) { return {h, n}; } sim > auto dud(c * r) -> decltype(cerr << *r); sim > char dud(...); struct muu { #ifdef LOCAL stringstream a; ~muu() { cerr << a.str() << endl; } R22(<) a << boolalpha << g; ris; } R22(==) ris << range(begin(g), end(g)); } sim, class b mor pair < b, c > r) { ris << "(" << r.first << ", " << r.second << ")"; } sim mor rge<c> u) { a << "["; for (c i = u.b; i != u.e; ++i) *this << ", " + 2 * (i == u.b) << *i; ris << "]"; } #else sim mor const c&) { ris; } #endif muu & operator()() { ris; } }; #define imie(r...) "[" #r ": " << (r) << "] " #define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ") int MAX = 1000 * 1000 * 1000 + 15; void yes_fill(int k, vector<int> v, vector<int> xs) { int n = v.size(); set<int> existing; for (int x : xs) existing.insert(x); for (int i = 1; i < n && existing.size() < k - 1; i ++) { if (existing.find(i) == existing.end()) existing.insert(i); } vector<int> res; cout << "TAK\n"; for (int x : existing) res.push_back(x); for (int x : res) cout << x << " "; /* assert(res.size() == k - 1); for (int i = 1; i < res.size(); i ++) { assert(res[i-1] < res[i]); } for (int x : res) { assert(x > 0); assert(x < v.size()); } res.push_back(v.size()); int last = 0; int end_of_seq = 0; bool OK = false; for (int x : res) { int MIN = MAX; for (int i = last; i < x; i ++){ if (v[i] > end_of_seq) MIN = min(MIN, v[i]); } if (MIN == MAX) OK = true; end_of_seq = MIN; last = x; } assert(OK); */ } void no(){ cout << "NIE\n"; } pair<vector<int>, vector<int>> min_max(vector<int> v) { vector<int> MIN = v; vector<int> MAX = v; for (int i = 1; i < MIN.size(); i ++) { MIN[i] = min(MIN[i], MIN[i-1]); } for (int i = MAX.size() - 2; i >= 0; i --) { MAX[i] = max(MAX[i], MAX[i+1]); } return make_pair(MIN, MAX); } void solve2(vector<int> v) { auto minmax = min_max(v); auto MIN = minmax.first; auto MAX = minmax.second; for (int i = 0; i < v.size() - 1; i ++) { if (MIN[i] >= MAX[i+1]) { return yes_fill(2, v, {i + 1}); } } return no(); } void solve4(int k, vector<int> v) { for (int i = 1; i < v.size() - 2; i ++) { if (v[i] >= v[i+1]) { return yes_fill(k, v, {i, i+1, i+2}); } } return no(); } void solve3(int k, vector<int> v) { auto minmax = min_max(v); auto MIN = minmax.first; auto MAX = minmax.second; int global_min = MIN.back(); int global_max = MAX[0]; for (int i = 1; i < v.size() - 1; i ++) { if (v[i] == global_min || v[i] == global_max) { return yes_fill(k, v, {i, i+1}); } } if (v[0] == global_max) return yes_fill(k, v, {1}); if (v.back() == global_min) return yes_fill(k, v, {v.size() - 1}); if (k >= 4) return solve4(k, v); return no(); } int main() { ios_base::sync_with_stdio(0); int n, k; vector<int> v; cin >> n >> k; for (int i = 0; i < n; i ++) { int x; cin >> x; v.push_back(x); } if (k == 2) solve2(v); if (k >= 3) solve3(k, v); }
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 | #ifndef LOCAL #pragma GCC optimize("O3") #endif #include <bits/stdc++.h> using namespace std; #define sim template < class c #define ris return * this #define mor > muu & operator << ( #define R22(r) sim > typename \ enable_if<1 r sizeof dud<c>(0), muu&>::type operator<<(c g) { sim > struct rge {c b, e; }; sim > rge<c> range(c h, c n) { return {h, n}; } sim > auto dud(c * r) -> decltype(cerr << *r); sim > char dud(...); struct muu { #ifdef LOCAL stringstream a; ~muu() { cerr << a.str() << endl; } R22(<) a << boolalpha << g; ris; } R22(==) ris << range(begin(g), end(g)); } sim, class b mor pair < b, c > r) { ris << "(" << r.first << ", " << r.second << ")"; } sim mor rge<c> u) { a << "["; for (c i = u.b; i != u.e; ++i) *this << ", " + 2 * (i == u.b) << *i; ris << "]"; } #else sim mor const c&) { ris; } #endif muu & operator()() { ris; } }; #define imie(r...) "[" #r ": " << (r) << "] " #define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ") int MAX = 1000 * 1000 * 1000 + 15; void yes_fill(int k, vector<int> v, vector<int> xs) { int n = v.size(); set<int> existing; for (int x : xs) existing.insert(x); for (int i = 1; i < n && existing.size() < k - 1; i ++) { if (existing.find(i) == existing.end()) existing.insert(i); } vector<int> res; cout << "TAK\n"; for (int x : existing) res.push_back(x); for (int x : res) cout << x << " "; /* assert(res.size() == k - 1); for (int i = 1; i < res.size(); i ++) { assert(res[i-1] < res[i]); } for (int x : res) { assert(x > 0); assert(x < v.size()); } res.push_back(v.size()); int last = 0; int end_of_seq = 0; bool OK = false; for (int x : res) { int MIN = MAX; for (int i = last; i < x; i ++){ if (v[i] > end_of_seq) MIN = min(MIN, v[i]); } if (MIN == MAX) OK = true; end_of_seq = MIN; last = x; } assert(OK); */ } void no(){ cout << "NIE\n"; } pair<vector<int>, vector<int>> min_max(vector<int> v) { vector<int> MIN = v; vector<int> MAX = v; for (int i = 1; i < MIN.size(); i ++) { MIN[i] = min(MIN[i], MIN[i-1]); } for (int i = MAX.size() - 2; i >= 0; i --) { MAX[i] = max(MAX[i], MAX[i+1]); } return make_pair(MIN, MAX); } void solve2(vector<int> v) { auto minmax = min_max(v); auto MIN = minmax.first; auto MAX = minmax.second; for (int i = 0; i < v.size() - 1; i ++) { if (MIN[i] >= MAX[i+1]) { return yes_fill(2, v, {i + 1}); } } return no(); } void solve4(int k, vector<int> v) { for (int i = 1; i < v.size() - 2; i ++) { if (v[i] >= v[i+1]) { return yes_fill(k, v, {i, i+1, i+2}); } } return no(); } void solve3(int k, vector<int> v) { auto minmax = min_max(v); auto MIN = minmax.first; auto MAX = minmax.second; int global_min = MIN.back(); int global_max = MAX[0]; for (int i = 1; i < v.size() - 1; i ++) { if (v[i] == global_min || v[i] == global_max) { return yes_fill(k, v, {i, i+1}); } } if (v[0] == global_max) return yes_fill(k, v, {1}); if (v.back() == global_min) return yes_fill(k, v, {v.size() - 1}); if (k >= 4) return solve4(k, v); return no(); } int main() { ios_base::sync_with_stdio(0); int n, k; vector<int> v; cin >> n >> k; for (int i = 0; i < n; i ++) { int x; cin >> x; v.push_back(x); } if (k == 2) solve2(v); if (k >= 3) solve3(k, v); } |