This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
MIS = lambda: map(int,input().split())
def compress(L):
L = list(L)
d = {}
for i, x in enumerate(sorted(L)): d[x] = i
return list(map(d.__getitem__, L))
class Fenwick:
def __init__(_, size): _.arr = [0]*size
def add(_, i, val):
while i < len(_.arr): _.arr[i] += val; i |= i+1
def getsum(_, i):
res = 0
while i >= 0: res+= _.arr[i]; i = (i&(i+1))-1
return res
def intersum(_, i, j): return _.getsum(j) - _.getsum(i-1)
n, k = MIS()
orig = list(MIS())
L = compress(orig)
F = Fenwick(n)
pos = []
for i, x in enumerate(L):
pos.append(i - min(k, F.intersum(x+1, n-1)))
F.add(x, 1)
# TODO optimize...
L = []
for i in range(n): L.insert(pos[i], orig[i])
print(*L)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |