🏡 index : github.com/captn3m0/codechef.git

---
{"category_name":"easy","problem_code":"TICKETQU","problem_name":"Cinema Ticketing Queue","problemComponents":{"constraints":"- $1 \\leq T \\leq 10^4$\n- $1 \\leq N \\leq 10^5$\n- $1 \\leq A_i \\leq N$\n- The sum of $N$ over all test cases does not exceed $5 \\cdot 10^5$.\n","constraintsState":true,"subtasks":"- 30 points : $1 \\leq R \\leq 10000$\n- 70 points : $1 \\leq R \\leq 10^9$\n","subtasksState":false,"inputFormat":"- The first line of input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line of each testcase line contains $N$ space-separated integers $A_1, A_2, \\dots , A_N$.\n\n","inputFormatState":true,"outputFormat":"For each test case, print a single line containing $N$ space-separated integers, where the $i^{th}$ integer denotes the seat number finally occupied by the Person $i$.\n","outputFormatState":true,"sampleTestCases":{"0":{"id":1,"input":"4\n5\n1 2 3 2 4\n4\n4 1 3 2\n3\n1 1 1\n5\n2 5 1 5 2","output":"1 2 3 5 4\n4 1 3 2\n1 2 3\n2 5 1 6 3 \n","explanation":"**Test case $1$**: \n- First, the first, second, third, and fifth person get the seats numbered $1$, $2$, $3$, and $4$ respectively because when they come to the front of the queue the corresponding seats are empty. The fourth person does not get the seat numbered $2$, because when he comes to the front of the queue, the seat is already occupied by the second person. Hence he goes to the rear of the queue and the number on the ticket of the fourth person is incremented by one and becomes $3$.\n- The fourth person does not get the seat numbered $3$ because it is already occupied by the third person. Hence the number on the ticket of the fourth person is incremented by one and becomes $4$.\n- Again, the fourth person does not get the seat numbered $4$ because it is occupied by the fifth person. Hence the number on the ticket of the fourth person is incremented by one and becomes $5$.\n- Finally the fourth person gets the seat numbered $5$.\n\n\n**Test case $3$**: \n- The first person gets the seat numbered $1$. The second and third people do not get the seat numbered $1$ because when they come to the front of the queue, the seat is already occupied by the first person. Hence the number on the tickets of both is incremented by one and becomes $2$.\n\n- Then, the second person gets the seat numbered $2$. The third person does not get the seat numbered $2$ because when he comes to the front of the queue, it is already occupied by the second person. Hence the number on the ticket of the third person is increased to $3$.\n\n- Finally, the third person gets the seat numbered $3$.\n","isDeleted":false}}},"video_editorial_url":"https://youtu.be/MuS9fCn2xeM","languages_supported":{"0":"CPP14","1":"C","2":"JAVA","3":"PYTH 3.6","4":"CPP17","5":"PYTH","6":"PYP3","7":"CS2","8":"ADA","9":"PYPY","10":"TEXT","11":"PAS fpc","12":"NODEJS","13":"RUBY","14":"PHP","15":"GO","16":"HASK","17":"TCL","18":"PERL","19":"SCALA","20":"LUA","21":"kotlin","22":"BASH","23":"JS","24":"LISP sbcl","25":"rust","26":"PAS gpc","27":"BF","28":"CLOJ","29":"R","30":"D","31":"CAML","32":"FORT","33":"ASM","34":"swift","35":"FS","36":"WSPC","37":"LISP clisp","38":"SQL","39":"SCM guile","40":"PERL6","41":"ERL","42":"CLPS","43":"ICK","44":"NICE","45":"PRLG","46":"ICON","47":"COB","48":"SCM chicken","49":"PIKE","50":"SCM qobi","51":"ST","52":"SQLQ","53":"NEM"},"max_timelimit":1,"source_sizelimit":50000,"problem_author":"soumyadeep_21","problem_tester":"","date_added":"27-07-2021","tags":{"0":"binary","1":"queue","2":"soumyadeep_21","3":"start8"},"problem_difficulty_level":"Unavailable","best_tag":"Binary Search","editorial_url":"https://discuss.codechef.com/problems/TICKETQU","time":{"view_start_date":1629124200,"submit_start_date":1629124200,"visible_start_date":1629124200,"end_date":1735669800},"is_direct_submittable":false,"problemDiscussURL":"https://discuss.codechef.com/search?q=TICKETQU","is_proctored":false,"visitedContests":{},"layout":"problem"}
---
### Read problem statements in [Russian](https://www.codechef.com/download/translated/START8/russian/TICKETQU.pdf), [Mandarin Chinese](https://www.codechef.com/download/translated/START8/mandarin/TICKETQU.pdf), [Bengali](https://www.codechef.com/download/translated/START8/bengali/TICKETQU.pdf), and [Vietnamese](https://www.codechef.com/download/translated/START8/vietnamese/TICKETQU.pdf) as well.

There are $N$ people, numbered from $1$ to $N$. They go to a cinema hall. Each of them buys a ticket, which has a number written on it. The number on the ticket of the $i^{th}$ person is $A_i$. 

There are infinite seats in the cinema hall. The seats are numbered sequentially starting from $1$. All the $N$ people stand in a queue to get their respective seats. Person $1$ stands at the front of the queue, Person $2$ stands in the second position of the queue, so on up to Person $N$ who stands at the rear of the queue. They were given seats in this manner:


Let the number on the ticket of the person currently standing in front of the queue be $X$. If the $X^{th}$ seat is empty, the person gets out of the queue and takes the $X^{th}$ seat. Otherwise the person goes to the rear of the queue, and the number on his ticket is incremented by one - that is, it becomes $X+1$.

Print the seat number occupied by each of the $N$ people.

<aside style='background: #f8f8f8;padding: 10px 15px;'><div>All submissions for this problem are available.</div></aside>