Bus Seating

시간 제한3초메모리 제한2048 MB

요약
승객이 탈 때마다 (C에서 행 거리를 뺀 값)을 그 행의 기존 승객 수만큼 절반으로 나눈 값이 최대인 행을 고르고, 동점이면 번호가 작은 행을 택한다. 모든 승객의 좌석 행을 출력한다.
난이도

어려움10점 중 8점

유형
세그먼트 트리, 이분 탐색, 그리디, 구현
정답자
아직 제출이 없습니다

문제

A bus has nn rows numbered 11 through nn with kk seats in each row, and there will be mm people entering the bus. Each person has a favorite row, and they will derive utility CC from being able to sit in that row. People prefer to sit closer to their favorite row, so if a person's favorite row is r_xr\_x, and they sit in row r_yr\_y, then that person will normally derive utility C−∣r_x−r_y∣C - |r\_x - r\_y| for sitting in it.

However, people are also introverts. For each person already sitting in a given row, the utility the person would derive gets halved. Formally, if pp people are already sitting in row r_yr\_y and the person's favorite row is r_xr\_x, then the person would derive C−∣r_x−r_y∣2p\dfrac{C - |r\_x - r\_y|}{2^p} utility for sitting in row r_yr\_y. Each seat can accommodate exactly one person, so if all kk seats in a row are occupied, then the person cannot sit in that row.

Can you determine where everyone will sit, if every person is trying to maximize their personal utility at the time they decide where to sit? If the row that maximizes the personal utility is not uniquely determined, the person will pick, among all such rows, the row with the smallest number. People do not change rows after sitting down.

입력

The first line of input contains four integers n,k,mn, k, m, and CC (1≤n,k,m≤2⋅1051\le n,k,m\le 2\cdot 10^5, n≤C≤109n\le C\le 10^9, and m≤n⋅km\le n\cdot k) --- the number of rows in the bus, the number of seats in each row, the number of people entering the bus, and each person's utility of sitting in their favorite row, respectively.

The next line contains mm integers a_1,a_2,…,a_ma\_1,a\_2,\ldots,a\_m (1≤a_i≤n1\le a\_i\le n) --- a_ia\_i is person ii's favorite row. People sit down in the order specified in the input.

출력

Output one line containing mm integers b_1,b_2,…,b_mb\_1,b\_2,\ldots,b\_m (1≤b_i≤n1\le b\_i\le n) --- b_ib\_i being the row in which person ii will sit.

힌트

In the first sample, here is what the utilities look like for every person:

  1. The utilities for a person with preference 33 are \[(4−2),(4−1),(4−0)]=\[2,3,4]\[(4-2), (4-1), (4-0)] = \[2, 3, 4] so they choose row 33.
  2. The utilities for a person with preference 22 now are \[(4−1),(4−0),(4−1)/2]=\[3,4,1.5]\[(4-1), (4-0), (4-1)/2] = \[3, 4, 1.5] so they choose row 22.
  3. The utilities for a person with preference 33 now are \[(4−2),(4−1)/2,(4−0)/2]=\[2,1.5,2]\[(4-2), (4-1)/2, (4-0)/2] = \[2, 1.5, 2] so they choose row 11.
  4. The utilities for a person with preference 22 now are \[(4−1)/2,(4−0)/2,(4−1)/2]=\[1.5,2,1.5]\[(4-1)/2, (4-0)/2, (4-1)/2] = \[1.5, 2, 1.5] so they choose row 22.
  5. The utilities for a person with preference 22 now are \[(4−1)/2,(4−0)/4,(4−1)/2]=\[1.5,1,1.5]\[(4-1)/2, (4-0)/4, (4-1)/2] = \[1.5, 1, 1.5] so they choose row 11.
  6. The utilities for a person with preference 11 now are \[(4−0)/4,(4−1)/4,(4−2)/2]=\[1,0.75,1]\[(4-0)/4, (4-1)/4, (4-2)/2] = \[1, 0.75, 1]. Since row 11 is full, they choose row 33.

예제2

  1. 예제 1

    입력
    3 2 6 4
    3 2 3 2 2 1
    
    예상 출력
    3 2 1 2 1 3
    
  2. 예제 2

    입력
    2 5 8 1000000000
    2 2 2 2 2 2 2 2
    
    예상 출력
    2 1 2 1 2 1 2 1