#define pb push_back #define mp make_pair #define fi first #define se second #define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__) #define boost {ios_base::sync_with_stdio(false); cin.tie(); cout.tie();} #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector <int> vi; typedef pair<int,int> PII; typedef pair<ll,ll> PLL; constexpr ll nax = 5e5+6969, INF = 2e9+6969; int n, A[nax], k; int mn[nax], mx[nax], paired[nax]; bool ans[nax]; int flag = -1; void bigK() { puts("TAK"); int cur = 0; for(int i=2;i<=n;i++) { if(A[i-1] >= A[i]) { ans[i] = ans[i-1] = 1; cur = 2; if(i > 2) { ans[i-2] = 1; cur = 3; } break; } } for(int i=1;i<=n;i++) { if(ans[i]) continue; if(cur == k-1) break; ans[i] = 1; cur++; } for(int i=1;i<=n;i++) { if(ans[i]) { printf("%d ", i); } } puts(""); } void kTwo() { for(int i=1;i<n;i++) { if(mn[i] >= mx[i+1]) { puts("TAK"); printf("%d\n", i); return; } } puts("NIE"); } void kThree() { if(flag > -1) { puts("TAK"); printf("%d %d\n", flag - 1, flag); return; } for(int i=1;i<n-1;i++) { if(mn[i] >= paired[i+1]) { puts("TAK"); printf("%d ", i); for(int j=i+1;j<n;j++) { if(paired[i+1] == A[j]) { printf("%d\n", j); break; } } return; } } puts("NIE"); } int main() { scanf("%d%d", &n, &k); for(int i=1;i<=n;i++) { scanf("%d", &A[i]); } bool increasing = true; for(int i=2;i<=n;i++) { if(A[i] <= A[i-1]) { increasing = false; break; } } if(increasing) { puts("NIE"); return 0; } if(k >= 4) { bigK(); return 0; } mn[1] = A[1]; for(int i=2;i<=n;i++) { mn[i] = min(mn[i-1], A[i]); } mx[n] = A[n]; for(int i=n-1;i>=1;i--) { mx[i] = max(mx[i+1], A[i]); } paired[n] = -1; for(int i = n-1;i>=1;i--) { int right = mx[i+1]; paired[i] = paired[i+1]; if(A[i] < right) { paired[i] = max(paired[i], A[i]); } else { if(i > 1) flag = i; } } if(k == 2) { kTwo(); return 0; } if(k == 3) { kThree(); return 0; } 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 | #define pb push_back #define mp make_pair #define fi first #define se second #define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__) #define boost {ios_base::sync_with_stdio(false); cin.tie(); cout.tie();} #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector <int> vi; typedef pair<int,int> PII; typedef pair<ll,ll> PLL; constexpr ll nax = 5e5+6969, INF = 2e9+6969; int n, A[nax], k; int mn[nax], mx[nax], paired[nax]; bool ans[nax]; int flag = -1; void bigK() { puts("TAK"); int cur = 0; for(int i=2;i<=n;i++) { if(A[i-1] >= A[i]) { ans[i] = ans[i-1] = 1; cur = 2; if(i > 2) { ans[i-2] = 1; cur = 3; } break; } } for(int i=1;i<=n;i++) { if(ans[i]) continue; if(cur == k-1) break; ans[i] = 1; cur++; } for(int i=1;i<=n;i++) { if(ans[i]) { printf("%d ", i); } } puts(""); } void kTwo() { for(int i=1;i<n;i++) { if(mn[i] >= mx[i+1]) { puts("TAK"); printf("%d\n", i); return; } } puts("NIE"); } void kThree() { if(flag > -1) { puts("TAK"); printf("%d %d\n", flag - 1, flag); return; } for(int i=1;i<n-1;i++) { if(mn[i] >= paired[i+1]) { puts("TAK"); printf("%d ", i); for(int j=i+1;j<n;j++) { if(paired[i+1] == A[j]) { printf("%d\n", j); break; } } return; } } puts("NIE"); } int main() { scanf("%d%d", &n, &k); for(int i=1;i<=n;i++) { scanf("%d", &A[i]); } bool increasing = true; for(int i=2;i<=n;i++) { if(A[i] <= A[i-1]) { increasing = false; break; } } if(increasing) { puts("NIE"); return 0; } if(k >= 4) { bigK(); return 0; } mn[1] = A[1]; for(int i=2;i<=n;i++) { mn[i] = min(mn[i-1], A[i]); } mx[n] = A[n]; for(int i=n-1;i>=1;i--) { mx[i] = max(mx[i+1], A[i]); } paired[n] = -1; for(int i = n-1;i>=1;i--) { int right = mx[i+1]; paired[i] = paired[i+1]; if(A[i] < right) { paired[i] = max(paired[i], A[i]); } else { if(i > 1) flag = i; } } if(k == 2) { kTwo(); return 0; } if(k == 3) { kThree(); return 0; } return 0; } |