Please sign in first.
Submission #28465041
Source Code Expand
class BIT
def initialize n
@z = n+1
@a = Hash.new 0
end
def [] i
i += 1
s = 0
while 0<i
s += @a[i]
i &= i-1
end
return s
end
def index s
i,t,b = 0,0,1<<(@z-1).bit_length
t += @a[i|=b] if i|b<@z && t+@a[i|b]<s while 0 < b>>=1
return i if s<=self[i]
end
def add i,d
i += 1
while i<@z
@a[i] += d
i += i&-i
end
end
end
N,Q = gets.split.map(&:to_i)
S = gets.split
X,T = $<.map(&:split).transpose
J2T = (S|T).sort
T2J = J2T.each_with_index.to_h
J2I = J2T.map{ BIT.new N }
SJ = BIT.new J2T.size
S.each_with_index{|s,i|
SJ.add T2J[s],1
J2I[T2J[s]].add i,1
}
Q.times{|q|
x,t = X[q].to_i,T[q]
j1 = T2J[t]
j0 = SJ.index x # x<=SJ[j0]
i = J2I[j0].index x-(0<j0 ? SJ[j0-1] : 0)
# warn "#{J2T[j0]} の #{x}-#{0<j0 ? SJ[j0-1] : 0}=#{x-(0<j0 ? SJ[j0-1] : 0)} 番目の人 i=#{i} -> #{t}"
SJ.add j0,-1
SJ.add j1,1
J2I[j0].add i,-1
J2I[j1].add i,1
}
A = [nil]*N
J2T.each_with_index{|t,j|
n,is,i = 0,J2I[j]
A[i] = t while i = is.index(n += 1)
}
puts A
Submission Info
| Submission Time | |
|---|---|
| Task | M - Deadnames |
| User | ds14050 |
| Language | Ruby (2.7.1) |
| Score | 6 |
| Code Size | 1054 Byte |
| Status | AC |
| Exec Time | 2778 ms |
| Memory | 198528 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 6 / 6 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, example0.txt, example1.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 2175 ms | 131916 KiB |
| 001.txt | AC | 758 ms | 44556 KiB |
| 002.txt | AC | 845 ms | 77956 KiB |
| 003.txt | AC | 58 ms | 13968 KiB |
| 004.txt | AC | 2214 ms | 131920 KiB |
| 005.txt | AC | 2137 ms | 131680 KiB |
| 006.txt | AC | 2164 ms | 132044 KiB |
| 007.txt | AC | 2183 ms | 131948 KiB |
| 008.txt | AC | 756 ms | 57776 KiB |
| 009.txt | AC | 749 ms | 68724 KiB |
| 010.txt | AC | 2778 ms | 198528 KiB |
| 011.txt | AC | 896 ms | 63004 KiB |
| 012.txt | AC | 1841 ms | 108188 KiB |
| 013.txt | AC | 1923 ms | 118308 KiB |
| 014.txt | AC | 1668 ms | 99708 KiB |
| 015.txt | AC | 1886 ms | 109392 KiB |
| 016.txt | AC | 1947 ms | 115560 KiB |
| 017.txt | AC | 2074 ms | 126460 KiB |
| 018.txt | AC | 1900 ms | 105544 KiB |
| 019.txt | AC | 1924 ms | 116432 KiB |
| 020.txt | AC | 1456 ms | 70752 KiB |
| 021.txt | AC | 1457 ms | 71256 KiB |
| 022.txt | AC | 1429 ms | 70844 KiB |
| 023.txt | AC | 1440 ms | 69888 KiB |
| 024.txt | AC | 1545 ms | 70348 KiB |
| 025.txt | AC | 984 ms | 45568 KiB |
| 026.txt | AC | 961 ms | 45624 KiB |
| 027.txt | AC | 972 ms | 45736 KiB |
| 028.txt | AC | 949 ms | 45428 KiB |
| 029.txt | AC | 954 ms | 45872 KiB |
| 030.txt | AC | 972 ms | 46020 KiB |
| 031.txt | AC | 957 ms | 45964 KiB |
| 032.txt | AC | 962 ms | 45964 KiB |
| example0.txt | AC | 57 ms | 13952 KiB |
| example1.txt | AC | 55 ms | 14036 KiB |