标签:name cstring tar amp clu turn blank mes for
单调队列版子题
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
const int N=1000005;
int n,m,top1,low1,top2,low2;
int ans1[N],ans2[N],q1[N],q2[N],a[N];
int get(){
char z=getchar();
int y=1,l=0;
while(z>‘9‘||z<‘1‘){
if(z==‘-‘){
y=-1;
}
z=getchar();
}
while(z>=‘0‘&&z<=‘9‘){
l=l*10+z-‘0‘;
z=getchar();
}
return l*y;
}
int main(){
n=get();m=get();
for(int i=1;i<=n;i++){
scanf("%d",a+i);
while(top1>=low1&&a[q1[top1]]>=a[i])top1--;
q1[++top1]=i;
while(top2>=low2&&a[q2[top2]]<=a[i])top2--;
q2[++top2]=i;
if(i>=m){
while(q1[low1]<i-m+1)low1++;
while(q2[low2]<i-m+1)low2++;
ans1[i-m+1]=a[q1[low1]];
ans2[i-m+1]=a[q2[low2]];
}
}
for(int i=1;i<=n-m+1;i++){
printf("%d ",ans1[i]);
}
printf("\n");
for(int i=1;i<=n-m+1;i++){
printf("%d ",ans2[i]);
}
return 0;
}
标签:name cstring tar amp clu turn blank mes for
原文地址:https://www.cnblogs.com/ainiyuling/p/11194443.html