单调队列
题目 代码如下: # include <iostream> using namespace std ; const int N = 1000010 ; int a [ N ] , q [ N ] ; int main ( ) { int hh = 0 , tt = - 1 ; int n , k ; cin >> n >> k ; for ( int i = 0 ; i < n ; i ++ ) cin >> a [ i ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( hh <= tt && i - k + 1 > q [ hh ] ) hh ++ ; //判断队首是否已退队 while ( hh <= tt && a [ i ] <= a [ q [ tt ] ] ) tt -- ; q [ ++ tt ] = i ; if ( i >= k - 1 ) cout << a [ q [ hh ] ] << ' ' ; } puts ( "" ) ; //输出换行 hh = 0 , tt = - 1 ; //别忘了重新声明hh和tt for ( int i = 0 ; i < n ; i ++ ) { if ( hh <= tt && i - k + 1 > q [ hh ] ) hh ++ ; while ( hh <= tt && a [