Bzoj 1012 [JSOI2008] Maximum number MaxNumber

Source: Internet
Author: User

How to do all can be a question. You can use a line segment tree. You can use the balance tree. Anyway, there's a lot of ways

Personal comparison of the magnetic monotone queue + binary search for the wording, constant small code less easy to understand.

The specific idea is to maintain a monotonous non-rising monotone queue, and then query in this monotone queue of two points to find just fine ~

//This problem can be regarded as a magic of the monotonous queue .//of course, there are many ways to use line tree, balance tree, tree array, etc., where the monotone queue is the most ingenious and simplest//Why is it possible to use a monotone queue for this problem? //(that is, the sequence stored in the queue must be the subscript monotone and the value is monotonous)//If each node has no subscript advantage (team early) and no numerical advantage (bigger), then obviously it can't be an answer.//and then how to query it? //obviously, using sequential lookups must be timed out.//Notice that the subscript is monotonous and satisfies the condition that you can use the two-point answer. We can use the two-point answer to find the location of the query.//(the element with the lowest subscript on the leftmost subscript of the >= query that satisfies the node)#include<deque>#include<cstdio>using namespacestd;structnode{Node (Constsize_t &a =0,Const int&b =0): Number (a), Value (b) {} size_t number; intValue;}; unsignedintM;intd;size_t Len;deque<node>S;intT;intSearch (Constsize_t &Left ) {size_t L (0), R (S.size ()), Mid;  while(L <r) {Mid= L + ((r-l) >>1); if(S[mid]. Number >=Left ) R=mid; ElseL= Mid +1; }        returnS[l]. Value;}intMain () {Charop[Ten]; intInput; scanf ("%u%d", &m, &D);  while(m--) {scanf ("%s%d", OP, &Input); if(*op = ='A') {Input+=T; Input%=D;  while(S.empty () = =false&& S.back (). Value <Input)            S.pop_back (); S.push_back (Node (++Len, Input)); }        Elseprintf ("%d\n", T = (S.empty ()?0: Search (Len-input +1))); }        return 0;}
Bzoj 1012

Bzoj 1012 [JSOI2008] Maximum number maxnumber

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.