Bzoj 1012 [JSOI2008] Maximum number MaxNumber

Source: Internet
Author: User

Title: https://www.lydsy.com/JudgeOnline/problem.php?id=1012

Monotonous stack water problem. You can use Lower_bound.

But input do not char ch; Cin>>ch. Will tle. Why )

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intn=2e5+5;intN,m,mod,stack[n],a[n],top,lst;intMain () {scanf ("%d%d",&m,&MoD); Charch[5];intx;  while(m--) {scanf ("%s%d",ch,&x); if(ch[0]=='A') {(x+=LST)%=mod;a[++n]=x;  while(Top&&x>=a[stack[top]]) top--; stack[++top]=N; }        if(ch[0]=='Q')        {            intK=lower_bound (stack+1, stack+top+1, n-x+1)-Stack; LST=A[stack[k]]; printf ("%d\n", LST); }    }    return 0;}
Lower_bound
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;Const intn=2e5+5;intN,m,mod,stack[n],ps[n],top,lst;intMain () {scanf ("%d%d",&m,&MoD); Charch[5];intx;  while(m--) {scanf ("%s%d",ch,&x); if(ch[0]=='A') {(x+=LST)%=MoD;  while(Top&&x>=stack[top]) top--; stack[++top]=x;ps[top]=++N; }        if(ch[0]=='Q')        {            intL=1, r=top;  while(l<=r) {intMid= (l+r) >>1); if(ps[mid]>n-x) lst=mid,r=mid-1; ElseL=mid+1; } LST=Stack[lst]; printf ("%d\n", LST); }    }    return 0;}

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.