Summer Training Mania Brush Series--foj 1894 volunteer selection (monotone queue)

Source: Internet
Author: User

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)

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.