洛谷P1440 求m区间内的最小值
1 #include<iostream> 2 #include<cstdio> 3 #include<deque> 4 using namespace std; 5 struct data{ int ID,val; data(int ID=0,int val=0):ID(ID),val(val){} }; 6 deque<data> minn; 7 int n,k; 8 inline void read(int &tmp) 9 { 10 int x=1;char c=getchar(); 11 for(tmp=0;!isdigit(c);c=getchar()) if(c=='-') x=-1; 12 for(;isdigit(c);tmp=tmp*10+c-48,c=getchar()); 13 tmp*=x; 14 } 15 int main() 16 { 17 read(n),read(k); 18 for(int i=1,tmp;i<=n;i++) 19 { 20 read(tmp); 21 while(!minn.empty()&&minn.front().ID<i-k) minn.pop_front(); 22 while(!minn.empty()&&tmp<minn.back().val) minn.pop_back(); 23 if(i==1) printf("%d\n",0); 24 else printf("%d\n",minn.front().val); 25 minn.push_back(data(i,tmp)); 26 } 27 return 0; 28 }