zhczcg314 @ 2022-12-11 12:06:49
#include<iostream>
#include<deque>
using namespace std;
deque<int> q;
deque<int> p;
int n,k,nums[100005];
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>nums[i];
}
for(int i=1;i<=n;i++){
while(!q.empty()&&q.front()<=i-k){
q.pop_front();
}
while(!q.empty()&&nums[q.back()]>=nums[i]){
q.pop_back();
}
q.push_back(i);
if(i>=k){
cout<<nums[q.front()]<<" ";
}
}
cout<<endl;
for(int i=1;i<=n;i++){
while(!p.empty()&&p.front()<=i-k){
p.pop_front();
}
while(!p.empty()&&nums[p.back()]<=nums[i]){
p.pop_back();
}
p.push_back(i);
if(i>=k){
cout<<nums[p.front()]<<" ";
}
}
cout<<endl;
return 0;
}
by CiXuKun @ 2022-12-11 12:42:03
显然数组开小了
by F_S_R_M @ 2022-12-22 19:19:24
也许楼主跟我一样的错误,还都是100005 唉,傻了