Ural_1126. Magnetic Storms monotonous queue

Source: Internet
Author: User

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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.