标签:pac dig 队列 for getch clu head c++ log
#include <bits/stdc++.h> using namespace std; void qin(int &aaa){ char c=getchar(); int ans=0,flag=1; while(!isdigit(c)){ if(c==‘-‘)flag=-flag;c=getchar(); } while(isdigit(c))ans=ans*10+c-‘0‘,c=getchar(); aaa=ans*flag; } void qout(int aaa,char c){ char s[11]={c}; int n=0,flag=1; if(aaa<0){ flag=0; aaa=-aaa; } while(aaa>0){ s[++n]=aaa%10+‘0‘; aaa/=10; } if(!flag)putchar(‘-‘); for(int i=n;~i;--i)putchar(s[i]); } int q[1000005],a[1000005],head=1,tail=1; int main(){ int n,m; qin(n);qin(m); for(int i=1;i<=n;++i) qin(a[i]); for(int i=1;i<=n;++i)q[i]=2147483647; for(int i=1;i<=m;++i){ while(head<=tail&&a[i]<q[tail])tail--; q[++tail]=a[i]; } qout(q[head],‘ ‘); for(int i=m+1;i<=n;++i){ if(a[i-m]==q[head])head++; while(head<=tail&&a[i]<q[tail])tail--; q[++tail]=a[i]; qout(q[head],‘ ‘); } return 0; }
标签:pac dig 队列 for getch clu head c++ log
原文地址:http://www.cnblogs.com/HC-LittleJian/p/7501622.html