题解
2025-08-05 13:54:56
发布于:上海
1阅读
0回复
0点赞
#include <iostream>
#include <deque>
using namespace std;
typedef long long ll;
const ll N = 1e6 + 5;
int main(){
deque<ll> q;
ll n, k;
ll a[N] = {};
cin >> n >> k;
for(int i=1; i<=n; i++){
cin >> a[i];
}
for(int i=1; i<=n; i++){
while(q.size() && a[q.back()] > a[i]){
q.pop_back();
}
q.push_back(i);
if(q.front() == i - k){
q.pop_front();
}
if(i - k > -1){
cout << a[q.front()] << endl;
}
}
while(q.size()){
q.pop_back();
}
cout << endl;
return 0;
}
这里空空如也
有帮助,赞一个