BZOJ4415: [Shoi2013] Licensing

Source: Internet
Author: User

Description

Suppose at first, the dealer took out a new deck of cards with n different cards, numbered 1 to N in turn. Because it is a new card, the cards are sorted in order, starting from the top of the library, 1, 2,...... Until the n,n plate at the bottom of the library. In order to finish all the cards, the dealer will carry out n licensing operations, in the first time before the licensing, he will continue to carry out R_i pin operation, R_i by the input given. What is the order of the last player to get this deck?

For example, assuming that n = 4, at the beginning, the order of the cards in the library is {1, 2, 3, 4}.

Assuming r1=2, the dealer should be able to pin two cards, placing 1 and 2 into the bottom of the library, and then sending 3 to the player. The Order of cards in the current library is {4, 1, 2}.

Assuming r2=0, the dealer does not need to sell cards, directly to the 4 players, the current card library in the order of Cards {.}.

Assuming r3=3, the dealer then sells 1, 2, 1, and then 2 to the player. At present, only one card is left in the library 1.

Assuming that r4=2, the dealer is repeatedly pin to two times 1, or 1 to the player, this is because 1 is the only card in the library.

Input

Line 1th, an integer n, represents the number of cards. Line 2nd to nth + 1, in line i + 1, with an integer r_i, 0≤r_i<n

Output

Line 1th to nth: line I has only one integer, which indicates the number of the first card that the player received.

Sample Input4
2
0
3
2Sample Output3
4
2
1
HINT

N<=70 million

It would be nice to have two minutes on the line tree.

#include <cstdio>#include<cctype>#include<queue>#include<cmath>#include<cstring>#include<algorithm>#defineRep (i,s,t) for (int i=s;i<=t;i++)#defineDwn (i,s,t) for (int i=s;i>=t;i--)#defineren for (int i=first[x];i;i=next[i])using namespacestd;Const intBuffersize=1<< -;Charbuffer[buffersize],*head,*Tail;inlineCharGetchar () {if(head==tail) {        intL=fread (Buffer,1, Buffersize,stdin); Tail= (Head=buffer) +l; }    return*head++;} InlineintRead () {intx=0, f=1;CharC=GetChar ();  for(;! IsDigit (c); C=getchar ())if(c=='-') f=-1;  for(; IsDigit (c); C=getchar ()) x=x*Ten+c-'0'; returnx*F;}Const intmaxn=700010;intn,m,sumv[maxn*3];voidBuildintOintLintr) {if(l==r) sumv[o]=1; Else {        intMid=l+r>>1,lc=o<<1, rc=lc|1; Build (Lc,l,mid); Build (Rc,mid+1, R); Sumv[o]=sumv[lc]+SUMV[RC]; }}voidUpdateintOintLintRintp) {if(l==r) Sumv[o]--, printf ("%d\n", L); Else {        intMid=l+r>>1,lc=o<<1, rc=lc|1; if(p<=SUMV[LC]) update (LC,L,MID,P); ElseUpdate (rc,mid+1, r,p-SUMV[LC]); Sumv[o]=sumv[lc]+SUMV[RC]; }}intMain () {m=n=read (); Build (1,1, N); intp=0; Rep (I,1, N) {(P+=read ())%=m; Update (1,1, n,p+1); M--; }    return 0;}
View Code

BZOJ4415: [Shoi2013] Licensing

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.