Monotonous queue! = Priority queue. Sorry, I watched the half-day priority queue with the help of computing director. I had a hard time reading the question, and finally asked my brother. Given a m, and then a sequence, find the maximum number of consecutive M numbers in the given sequence. The final output of these maximum values is actually a very bare monotonous queue. Then start searching information about monotonous queue on the Internet, from here http://www.felix021.com/blog/read.php? 1965 learned. In fact, it is to maintain the monotonicity of the queue, regardless of whether it is monotonic increasing or monotonic decreasing. The Header element is always the minimum value (or maximum value) of the Most column ).
# Include <iostream>
# Include <cstdio>
# Include <cstring>
Using namespace STD;
Const int n= 25005;
Struct node {
Int I;
Int num;
} Q [N];
Int ans [N];
Int main (){
// Freopen ("data. In", "r", stdin );
Int M, T, K;
Int F, R;
Scanf ("% d", & M );
Scanf ("% d", & T );
F = r = k = 0;
While (T! =-1 ){
If (F <R & Q [f]. I <= k-m) f ++; // Delete the old Element
While (F <R & Q [r-1]. Num <= T) r --; // delete an element smaller than T
Q [R]. I = K; Q [R]. num = T; r ++; // incoming queue
Ans [k] = Q [f]. Num; k ++;
Scanf ("% d", & T );
}
For (t = m-1; t <K; t ++)
Printf ("% d \ n", ANS [T]);
Return 0;
}
PS: I started to reduce the memory size and crash twice. I personally feel that I can use the scrolling array optimization, but I didn't write it...