wuxiyi @ 2022-12-30 12:12:36
#include<iostream>
using namespace std;
struct node{
int pos,b;
};
int n,m;
node tmp;
node a[4000009];
int head=1,tail=0;
int main()
{
//freopen("P1440_2.in","r",stdin);
//freopen("tmp.out","w",stdout);
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
{
printf("%d\n",a[head].b);
scanf("%d",&tmp.b);
tmp.pos=i;
while (head<=tail&&a[tail].b>=tmp.b)
{
tail--;
}
while (a[head].pos<=i-m)
{
head++;
}
tail++;
a[tail].b=tmp.b;
a[tail].pos=tmp.pos;
}
return 0;
}
https://www.luogu.com.cn/record/98258771
TLE*2
RE*1
WA*1
by bamboo12345 @ 2022-12-30 12:17:34
@wuxiyi 第二while,要加个head<=tail
by wuxiyi @ 2022-12-30 12:51:14
AC了,谢谢! https://www.luogu.com.cn/record/98261851