Topic Connection:
http://acm.fzu.edu.cn/problem.php?pid=1894
Problem Solving Ideas:
Because the team and the queue are satisfied with the nature of queues, priority monotone queue priority has to enter the queue order and character, in a period of time if the occurrence of X[i] is the largest, then [0,i-1] The number in the interval is not recorded, So in the monotonous queue can be in descending order of character values, the output of the time to determine whether the current element has been out of the team.
1#include <cstdio>2#include <cstring>3 using namespacestd;4 Const intMAXN =1000005;5 6 structnode7 {8 intindex, Val;9 }Q[MAXN];Ten One intMain () A { - intT; - Charstr[Ten]; thescanf ("%d", &t); - while(T--) - { - inthead, last, num, cur, x; +scanf ("%s", &str); -Head = last = x =0; +Cur =-1; A while(SCANF ("%s", str), strcmp (str,"END")) at { - if(str[0] =='C') - { -scanf ("%s%d", str, &num); - //the current position is not at the top of the team and the incoming element priority is higher than the current element - while(Head<=cur && q[cur].val<num) inCur--; -Q[++cur].index = x + +; toQ[cur].val =num; + } - Else if(str[0] =='Q') the{//team first element has been out of the team, the past excellent elements * while(Head<=cur && q[head].index<Last ) $Head + +;Panax Notoginseng if(Head >cur) -printf ("-1\n"); the Else +printf ("%d\n", q[head].val); A } the Else +Last + +;//number of out-of-team elements - } $ } $ return 0; -}
Summer Training Mania Brush Series--foj 1894 volunteer selection (monotone queue)