Poj 2823 monotonous queue bare question
The two queues maintain the maximum and minimum respectively.
# Include
# Include
# Include
Using namespace std;
Struct node
{
Int mi, ma;
} Num [2, 1000010];
Int sax [1000010], sin [1000010];
Int ida [1000010], idi [1000010];
Int main ()
{
Int n, m, I, j, k,;
While (~ Scanf ("% d", & n, & k ))
{
Int fax = 0, tax = 0;
Int fin = 0, tin = 0;
Int j = 0;
For (I = 1; I <= n; I ++)
{
Scanf ("% d", & );
While (fax Ida [tax] = I;
While (fin A) tin --;
Sin [++ tin] =;
Idi [tin] = I;
While (fax Fax ++;
While (fin Fin ++;
If (I> = k)
{
Num [++ j]. mi = sin [fin + 1];
Num [j]. ma = sax [fax + 1];
}
}
For (I = 1; I <= j; I ++)
{
If (I! = 1) printf ("");
Printf ("% d", num [I]. mi );
}
Printf ("\ n ");
For (I = 1; I <= j; I ++)
{
If (I! = 1) printf ("");
Printf ("% d", num [I]. ma );
}
Printf ("\ n ");
}
Return 0;
}