codeToEnd @ 2022-09-02 14:55:23
using namespace std;
const int N = 1000001;
int deq[N];
int a[N];
int tail=-1,head=-1;
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
while(deq[head]>=a[i]&&head!=tail) head--;
deq[++head] = a[i];
if(i>m&&deq[tail+1]==a[i-m]) tail++;
if (i>=m) printf("%d ",deq[tail+1]);
}
head =0,tail=0;
printf("\n");
for(int i=1;i<=n;i++){
while(deq[head]<=a[i]&&head!=tail) head--;
deq[++head] = a[i];
if(i>m&&deq[tail+1]==a[i-m]) tail++;
if (i>=m) printf("%d ",deq[tail+1]);
}
}
可以ac,但是数据
8 3
1 3 -1 -3 -3 -3 -3 -3
明显输出错误