#include<bits/stdc++.h> #define FOR(i,a,b) for(int i=a;i<(int)b;++i) #define FORD(i,a,b) for(int i=a;i>=(int)b;--i) #define PB push_back #define EB emplace_back #define FI first #define SE second #define umap unordered_map #define uset unordered_set #define vi vector<int> #define vvi vector<vi> #define vll vector<ll> #define vvll vector<vll> #define vpii vector<pii> #define pii pair<int, int> #define pll pair<ll, ll> #define ALL(X) (X).begin(),(X).end() #ifndef DEBUG #define endl (char)10 #endif using namespace std; using ll = long long; using ld = long double; template <class T> istream& operator>> (istream& is, vector<T>& vec){ FOR(i,0,vec.size()) is >> vec[i]; return is; } template <class T> ostream& operator<< (ostream& os, vector<T>& vec){ for(auto& t : vec) os << t << " "; return os; } template<class T, class U> ostream& operator<< (ostream& os, const pair<T, U>& p){ os << p.FI << " " << p.SE; return os; } template<class T, class U> istream& operator>> (istream& is, pair<T, U>& p){ is >> p.FI >> p.SE; return is; } void validate(vi& ans, vi& V, int k){ assert(ans.size() == k - 1); int prev = -1; int idx = 0; ans.PB(V.size()); for(int x : ans){ int nv = INT_MAX; while(idx < x){ if (V[idx] > prev) nv = min(nv, V[idx]); idx++; } //assert (nv != INT_MAX); prev = nv; } ans.pop_back(); assert(prev == INT_MAX); } void display(bool succ, vi& ans, vi& V, int k){ cout << (succ ? "TAK" : "NIE") << endl; if (succ) for(int x : ans) cout << x << " "; //if (succ) validate(ans, V, k); exit(0); } int main () { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vi V(n); cin >> V; bool ros = true; FOR(i,1,n) if (V[i] <= V[i - 1]) ros = false; vi ans; if (ros) display(false, ans, V, k); if (k == 2){ vi dol(n), gora(n); dol[0] = V[0]; FOR(i,1,n) dol[i] = min(dol[i - 1], V[i]); gora[n - 1] = V[n - 1]; FORD(i,n - 2,0) gora[i] = max(gora[i + 1], V[i]); FOR(i,1,n) { if (dol[i - 1] >= gora[i]){ ans.PB(i); display(true, ans, V, k); } } display(false, ans, V, k); } if (k > 3){ set<int> sol; FOR(i,1,n){ if (V[i] <= V[i - 1]){ if (i > 0) sol.insert(i); sol.insert(i + 1); sol.insert(i + 2); break; } } int it = 1; while(sol.size() + 1 < k){ sol.insert(it); it++; } for(int x : sol) ans.PB(x); display(true, ans, V, k); } int pm = n; FORD(i,n-1,1) if (V[i] <= V[0]) pm = i; if (pm == n - 1){ ans.PB(1); ans.PB(n - 1); display(true, ans, V, k); } else if (pm != n){ ans.PB(pm); ans.PB(pm + 1); display(true, ans, V, k); } int pw = -1; FOR(i,0,n) if (V[i] >= V[n - 1]) pw = i; if (pw == 0){ ans.PB(1); ans.PB(n - 1); display(true, ans, V, k); } else if (pw != -1){ ans.PB(pw); ans.PB(pw + 1); display(true, ans, V, k); } display(false, ans, V, k); }
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 | #include<bits/stdc++.h> #define FOR(i,a,b) for(int i=a;i<(int)b;++i) #define FORD(i,a,b) for(int i=a;i>=(int)b;--i) #define PB push_back #define EB emplace_back #define FI first #define SE second #define umap unordered_map #define uset unordered_set #define vi vector<int> #define vvi vector<vi> #define vll vector<ll> #define vvll vector<vll> #define vpii vector<pii> #define pii pair<int, int> #define pll pair<ll, ll> #define ALL(X) (X).begin(),(X).end() #ifndef DEBUG #define endl (char)10 #endif using namespace std; using ll = long long; using ld = long double; template <class T> istream& operator>> (istream& is, vector<T>& vec){ FOR(i,0,vec.size()) is >> vec[i]; return is; } template <class T> ostream& operator<< (ostream& os, vector<T>& vec){ for(auto& t : vec) os << t << " "; return os; } template<class T, class U> ostream& operator<< (ostream& os, const pair<T, U>& p){ os << p.FI << " " << p.SE; return os; } template<class T, class U> istream& operator>> (istream& is, pair<T, U>& p){ is >> p.FI >> p.SE; return is; } void validate(vi& ans, vi& V, int k){ assert(ans.size() == k - 1); int prev = -1; int idx = 0; ans.PB(V.size()); for(int x : ans){ int nv = INT_MAX; while(idx < x){ if (V[idx] > prev) nv = min(nv, V[idx]); idx++; } //assert (nv != INT_MAX); prev = nv; } ans.pop_back(); assert(prev == INT_MAX); } void display(bool succ, vi& ans, vi& V, int k){ cout << (succ ? "TAK" : "NIE") << endl; if (succ) for(int x : ans) cout << x << " "; //if (succ) validate(ans, V, k); exit(0); } int main () { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vi V(n); cin >> V; bool ros = true; FOR(i,1,n) if (V[i] <= V[i - 1]) ros = false; vi ans; if (ros) display(false, ans, V, k); if (k == 2){ vi dol(n), gora(n); dol[0] = V[0]; FOR(i,1,n) dol[i] = min(dol[i - 1], V[i]); gora[n - 1] = V[n - 1]; FORD(i,n - 2,0) gora[i] = max(gora[i + 1], V[i]); FOR(i,1,n) { if (dol[i - 1] >= gora[i]){ ans.PB(i); display(true, ans, V, k); } } display(false, ans, V, k); } if (k > 3){ set<int> sol; FOR(i,1,n){ if (V[i] <= V[i - 1]){ if (i > 0) sol.insert(i); sol.insert(i + 1); sol.insert(i + 2); break; } } int it = 1; while(sol.size() + 1 < k){ sol.insert(it); it++; } for(int x : sol) ans.PB(x); display(true, ans, V, k); } int pm = n; FORD(i,n-1,1) if (V[i] <= V[0]) pm = i; if (pm == n - 1){ ans.PB(1); ans.PB(n - 1); display(true, ans, V, k); } else if (pm != n){ ans.PB(pm); ans.PB(pm + 1); display(true, ans, V, k); } int pw = -1; FOR(i,0,n) if (V[i] >= V[n - 1]) pw = i; if (pw == 0){ ans.PB(1); ans.PB(n - 1); display(true, ans, V, k); } else if (pw != -1){ ans.PB(pw); ans.PB(pw + 1); display(true, ans, V, k); } display(false, ans, V, k); } |