4415: [Shoi2013] Licensing time limit:10 Sec Memory limit:256 MB
submit:173 solved:124
[Submit] [Status] [Discuss] 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
The most natural idea: run two points in a tree-like array.
K is the meaning of the current n number of the answer is the largest. O (nlogn^2) Fans of water over
(Of course, you can change to a line tree, so do not two points, which side of the match to go O (nlogn))
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstdlib>5#include <algorithm>6#include <vector>7#include <cstring>8 #defineYyj (s) freopen (S ".", "R", stdin), Freopen (S ". Out", "w", stdout);9 #defineLLG Long LongTen #defineMAXN 700010 One Llg I,J,K,X,N,M,T,Y,L,R,C[MAXN]; A using namespacestd; -Llg lowbit (Llg x) {returnx&-x;} - voidAdd (Llg X,llg val) { while(x<=y) {c[x]+=val; x+=lowbit (x);}} theLLG sum (Llg x) {LLG ans=0; while(x>0{ans+=c[x]; x-=lowbit (x);}returnans;} - intMain () - { -Yyj"a"); +cin>>n; y=N; - for(i=1; i<=n;i++) Add (i,1); +k=1; A while(n--) at { -scanf"%lld",&m); -k= (k+m-1)% (n+1)+1; -L=1; R=y; - while(l!=R) - { inLlg mid= (l+r)/2; -LLG w=sum (mid); to if(w>=k) R=mid;ElseL=mid+1; + } -printf"%lld\n", L); theAdd (l,-1); * //k++; $ }Panax Notoginseng return 0; -}
Who's next to the bottom?
Bzoj 4415: [Shoi2013] Licensing