imnotcfz @ 2024-08-25 13:04:16
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
int n, k;
int a[1000005];
struct elem {
int x, i;
};
deque<elem> q;
int main() {
cin >> n >> k;
for (int i = 1 ; i <= n ; i++) cin >> a[i];
// min
for (int i = 1 ; i <= n ; i++) {
while (!q.empty() && a[i] <= q.back().x) q.pop_back();
q.push_back({a[i], i});
while (i - k >= q.front().i) q.pop_front();
if (i >= k) cout << q.front().x << ' ';
}
cout << endl;
// max
for (int i = 1 ; i <= n ; i++) {
while (!q.empty() && a[i] >= q.back().x) q.pop_back();
q.push_back({a[i], i});
while (i - k >= q.front().i) q.pop_front();
if (i >= k) cout << q.front().x << ' ';
}
q.clear();
return 0;
}
Subtask0最后一个点WA了
by 水星湖 @ 2024-08-25 13:17:26
@imnotcfz 不是哥们,你clear不应该写中间吗
by I_Love_DS @ 2024-08-25 13:50:50
楼上说的对,但是这为什么只会wa一个点啊
by imnotcfz @ 2024-08-25 15:40:31
@水星湖 写代码的时候不小心给移过去了,然后 AC 了...
by imnotcfz @ 2024-08-25 15:40:55
@imnotcfz 改完 AC 了