P1198 [JSOI2008] Maximum number

Source: Internet
Author: User

Title Description

Now you are asked to maintain a sequence that requires the following two actions:

1, query operation.

Grammar:Q L

Function: Query the maximum number of L in the number of the end of the current sequence and output the value of this number.

Limit: lL does not exceed the length of the current series. (L > 0)(l>0)

2, insert operation.

Grammar:A n

Function: WillNN Plust t , where  t t   is the answer to the most recent query operation ( t=0 t =0 ), and the resulting result to a fixed constant  d d  modulo, inserting the resulting answer into the end of the sequence.

Limit: nN is an integer (possibly negative) and within a long range.

Note: The initial sequence is empty and does not have a number.

Input/output format

Input format:

The first row of two integers,MM andDD, whereMM indicates the number of operations(M \le 200,000)(M≤200,000) ,d d  to meet   (0<d<2,000,000,000) (0<d<2,0 00,00 0,000

The next m-m line, one string per line, describes a specific operation. The syntax is as described above.

Output format:

For each query operation, you should output the results sequentially, with each result in one row.

Input and Output sample input sample #: Copy
5 100A 96Q 1 a 97Q 1Q 2
Output Example # #: Replication
969396
Description

[JSOI2008]

The data has been strengthened

Single-point modification + interval query

#include <bits/stdc++.h>#defineLL Long Long#defineN 800005using namespacestd;structnode{intL,r,w;} Tr[n];intn,d,t,l;voidBuildintKintLintR) {TR[K].L=l;tr[k].r=R; if(L==R)return; intMid= (L+R)/2; Build (k*2, l,mid); Build (k*2+1, mid+1, R);}voidChangeintKintPintX) {    if(TR[K].L==TR[K].R) {tr[k].w=p;return;} if(x<= (TR[K].L+TR[K].R)/2) Change (k*2, p,x); ElseChange (k*2+1, p,x); TR[K].W=max (tr[k*2].w,tr[k*2+1].W); }voidAskintKintLintR) {    intLl=tr[k].l,rr=tr[k].r,mid= (LL+RR)/2; if(ll>=l&&rr<=R) {T=Max (tr[k].w,t); return; }if(L<=mid) Ask (k*2, L,r); if(R>mid) Ask (k*2+1, l,r);}intMain () {scanf ("%d%d",&n,&d); Build (1,1, N);  for(intX,i=1; i<=n;i++){        CharP;cin>>p>>x; if(p=='A') Change (1, (x+t)%d,++L); Else{T=-101010; Ask (1, l-x+1, L); printf ("%d\n", T); }    }return 0;}

P1198 [JSOI2008] Maximum number

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.