// 提出時に定数倍高速化,assertはオフ #ifndef DEBUG #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #ifndef NDEBUG #define NDEBUG #endif #endif #include using namespace std; using ll = long long; #define all(x) (x).begin(), (x).end() template using vec = vector; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N, K; cin >> N >> K; vecA(N); for(int &a : A) cin >> a; stack cur; vec front, back; for(int i = 0; i < N; i++){ if(cur.empty()){ cur.push(i); continue; } if(cur.top() < i){ while(!cur.empty()){ front.push_back(cur.top()); cur.pop(); } } else if(cur.top() < i){ while(!cur.empty()){ back.push_back(cur.top()); cur.pop(); } } cur.push(i); } reverse(all(back)); for(int &x : front) cout << x << " "; for(int &x : back) cout << x << " "; cout << "\n"; }