小渣青999 @ 2020-08-26 09:04:19
#include<iostream>
#include<queue>
#include<cstdio>
using namespace std;
struct node
{
int wei,val;
bool operator < (const node &a) const
{
return val<a.val;//大顶堆
}
};
struct node1
{
int wei,val;
bool operator <(const node1 &a) const
{
return val>a.val;
}
};
priority_queue<node> q;
priority_queue<node1>q1;
int a[1000010];
int read()
{
int x=0,f=1;
char c;
c=getchar();
while(c>'9'||c<'0')
{
if(c=='-') f=-1;
c=getchar();
}
while(c<='9'&&c>='0')
{
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
int main()
{
int n=read(),m=read();
//printf("n:%d m:%d\n",n,m);
// scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) a[i]=read();
//scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
{
q1.push((node1){i,a[i]});
// printf("i:%d a:%d\n",i,a[i]);
if(i>=m)
{
while(q1.top().wei<=i-m) q1.pop();
printf("%d ",q1.top().val);
}
}
printf("\n");
for(int i=1;i<=n;i++)
{
q.push((node){i,a[i]});
if(i>=m)
{
while(q.top().wei<=i-m) q.pop();
printf("%d ",q.top().val);
}
}
return 0;
}
by 明依 @ 2020-08-26 09:21:34
emm为什么要用优先队列啊
不应该用普通队列吗
by Krystallos @ 2020-08-26 09:29:37
优先队列切单调队列的题,讲究