結果
問題 |
No.2210 equence Squence Seuence
|
ユーザー |
|
提出日時 | 2023-02-11 20:44:34 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 36 ms / 2,000 ms |
コード長 | 1,392 bytes |
コンパイル時間 | 8,903 ms |
コンパイル使用メモリ | 264,972 KB |
最終ジャッジ日時 | 2025-02-10 14:33:55 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
// 提出時に定数倍高速化,assertはオフ #ifndef DEBUG #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #ifndef NDEBUG #define NDEBUG #endif #endif #include <bits/stdc++.h> using namespace std; using ll = long long; #define all(x) (x).begin(), (x).end() template <class T> using vec = vector<T>; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N, K; cin >> N >> K; vec<int>A(N); for(int &a : A) cin >> a; stack<int> cur; vec<int> ans(N, -1); int frontIndex = 0, backIndex = N - 1; for(int i = 0; i < N; i++){ if(cur.empty()){ cur.push(i); continue; } if(A[cur.top()] > A[i]){ while(!cur.empty()){ ans[frontIndex++] = cur.top(); cur.pop(); } } else if(A[cur.top()] < A[i]){ while(!cur.empty()){ ans[backIndex--] = cur.top(); cur.pop(); } } cur.push(i); } while(!cur.empty()){ ans[frontIndex++] = cur.top(); cur.pop(); } /* for(int i = 0; i < N; i++){ cout << ans[i] << "\n"; } //*/ //* int ansIndex = ans[K - 1]; for(int i = 0; i < N; i++){ if(i != ansIndex) cout << A[i] << " "; } cout << "\n"; //*/ }