Zhetengtiao @ 2023-07-20 09:11:28
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int n,k,a,b,num[2000005],ansmin[200005],ansmax[2000005],cnt=1;
deque<int> q1;
deque<int> q2;
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>num[i];
//for(int j=1;j<=21;j++)st[i][j]=1e9;
}
//for(int i=1;i<=k;i++){
// if(num[i]>num[q.front()])q.push_back(i);
// else q.push_front(i);
//}
for(int i=1;i<=n;i++){
int x=num[i];
while(!q1.empty()&&x>=num[q1.back()])q1.pop_back();
while(!q2.empty()&&x<=num[q2.back()])q2.pop_back();
q1.push_back(i);
q2.push_back(i);
while(!q1.empty()&&q1.front()<=i-k)q1.pop_front();
while(!q2.empty()&&q2.front()<=i-k)q2.pop_front();
if(i>=k){
ansmin[cnt]=q2.front();
ansmax[cnt]=q1.front();
cnt++;
}
}
for(int i=1;i<cnt;i++){
cout<<num[ansmin[i]]<<" ";
}
cout<<endl;
for(int i=1;i<cnt;i++){
cout<<num[ansmax[i]]<<" ";
}
return 0;
}
求助大佬
by Zhetengtiao @ 2023-07-20 09:12:14
我去,md崩了 应该不影响阅读
by Zhetengtiao @ 2023-07-31 08:38:29
数组开小了
ansmin[200005]
((