#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = b; i >= a; i--) #define cat(x) cout << #x << ": " << x << endl using namespace std; using ll = long long; const int N = 500500; int n, k, a[N], mn[N], mx[N]; void answer(vector<int> v) { assert(1 <= v.size() && v.size() < k); for (int i = 0; i + 1 < int(v.size()); i++) { assert(v[i] + 1 == v[i + 1]); } if (v[0] == 0) { v.erase(v.begin()); } if (v.back() == n) { v.pop_back(); } int L = v[0]; int R = v.back(); rep(i, 1, L - 1) { if (v.size() < k - 1) { v.push_back(i); } } rep(i, R + 1, n - 1) { if (v.size() < k - 1) { v.push_back(i); } } sort(v.begin(), v.end()); assert(v.size() == k - 1); cout << "TAK\n"; for (auto x : v) { cout << x << " "; } cout << "\n"; v.insert(v.begin(), 0); v.insert(v.end(), n); int h = 0; rep(i, 1, k) { assert(v[i - 1] < v[i]); int now = INT_MAX; rep(j, v[i - 1] + 1, v[i]) { if (a[j] > h) { now = min(now, a[j]); } } if (now == INT_MAX) { exit(0); } h = now; } assert(0); } void nope() { cout << "NIE\n"; exit(0); } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> k; rep(i, 1, n) cin >> a[i]; bool inc = true; rep(i, 2, n) inc &= a[i - 1] < a[i]; if (inc) { nope(); } if (k >= 4) { rep(i, 2, n) { if (a[i - 1] >= a[i]) { answer({i - 2, i - 1, i}); } } assert(0); } mn[0] = 1e9; rep(i, 1, n) mn[i] = min(mn[i - 1], a[i]); mx[n + 1] = 1; per(i, 1, n) mx[i] = max(mx[i + 1], a[i]); if (k == 3) { rep(i, 2, n) { if (a[i] == mn[n]) { answer({i - 1, i}); } } rep(i, 1, n - 1) { if (a[i] == mx[1]) { answer({i - 1, i}); } } nope(); } assert(k == 2); rep(i, 1, n - 1) { if (mn[i] >= mx[i + 1]) { answer({i}); } } nope(); 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 | #include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = b; i >= a; i--) #define cat(x) cout << #x << ": " << x << endl using namespace std; using ll = long long; const int N = 500500; int n, k, a[N], mn[N], mx[N]; void answer(vector<int> v) { assert(1 <= v.size() && v.size() < k); for (int i = 0; i + 1 < int(v.size()); i++) { assert(v[i] + 1 == v[i + 1]); } if (v[0] == 0) { v.erase(v.begin()); } if (v.back() == n) { v.pop_back(); } int L = v[0]; int R = v.back(); rep(i, 1, L - 1) { if (v.size() < k - 1) { v.push_back(i); } } rep(i, R + 1, n - 1) { if (v.size() < k - 1) { v.push_back(i); } } sort(v.begin(), v.end()); assert(v.size() == k - 1); cout << "TAK\n"; for (auto x : v) { cout << x << " "; } cout << "\n"; v.insert(v.begin(), 0); v.insert(v.end(), n); int h = 0; rep(i, 1, k) { assert(v[i - 1] < v[i]); int now = INT_MAX; rep(j, v[i - 1] + 1, v[i]) { if (a[j] > h) { now = min(now, a[j]); } } if (now == INT_MAX) { exit(0); } h = now; } assert(0); } void nope() { cout << "NIE\n"; exit(0); } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> k; rep(i, 1, n) cin >> a[i]; bool inc = true; rep(i, 2, n) inc &= a[i - 1] < a[i]; if (inc) { nope(); } if (k >= 4) { rep(i, 2, n) { if (a[i - 1] >= a[i]) { answer({i - 2, i - 1, i}); } } assert(0); } mn[0] = 1e9; rep(i, 1, n) mn[i] = min(mn[i - 1], a[i]); mx[n + 1] = 1; per(i, 1, n) mx[i] = max(mx[i + 1], a[i]); if (k == 3) { rep(i, 2, n) { if (a[i] == mn[n]) { answer({i - 1, i}); } } rep(i, 1, n - 1) { if (a[i] == mx[1]) { answer({i - 1, i}); } } nope(); } assert(k == 2); rep(i, 1, n - 1) { if (mn[i] >= mx[i + 1]) { answer({i}); } } nope(); return 0; } |