单调队列(数组优化?)P1886

class Deque{
public:
int a[maxn];
int pl=1,pr=0;
}Deq;
int a[maxn];
int n,k;
void solve(){
Deq.pl=1;Deq.pr=0;
for(int i=1;i<=n;i++){
while(Deq.pr>=Deq.pl&&a[Deq.a[Deq.pr]]<a[i])Deq.pr--;//弹尾
Deq.a[++Deq.pr]=i;//入尾
if(Deq.a[Deq.pl]+k<=i)Deq.pl++;//弹首
o(a[Deq.a[Deq.pl]]);putchar(' ');
}
putchar('\n');
}
上一篇:随机森林算法入门


下一篇:UVA10529 Dumb Bones