Submission #28790707
Source Code Expand
class BIT
def initialize n
@a = [0]*(n+1)
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,z = 0,0,1<<(@a.size-1).bit_length,@a.size
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
z = @a.size
while i<z
@a[i] += d
i += i&-i
end
end
end
L,Q = gets.split.map(&:to_i)
Qry = $<.map{|ln| ln.split.map(&:to_i) }
X = 0,*Qry.map(&:last).uniq.sort,L
I = X.each_with_index.to_h
W = BIT.new I.size+1
W.add I[L],I[L]
Qry.each{|c,x|
i = I[x]
if c<2
w = W[i]
j = W.index w+1
d = i-w
W.add j,-d
W.add i,d
else
w = W[i]
i = W.index w
j = W.index w+1
puts X[j]-X[i]
end
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Cutting Woods |
| User | ds14050 |
| Language | Ruby (2.7.1) |
| Score | 400 |
| Code Size | 773 Byte |
| Status | AC |
| Exec Time | 1218 ms |
| Memory | 42600 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_max_random_00.txt, 01_max_random_01.txt, 01_max_random_02.txt, 01_max_random_03.txt, 01_max_random_04.txt, 02_all_1_00.txt, 03_all_2_00.txt, 04_hack_00.txt, 04_hack_01.txt, 04_hack_02.txt, 04_hack_03.txt, 04_hack_04.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 58 ms | 14076 KiB |
| 00_sample_01.txt | AC | 54 ms | 14184 KiB |
| 00_sample_02.txt | AC | 59 ms | 14188 KiB |
| 01_max_random_00.txt | AC | 1184 ms | 41992 KiB |
| 01_max_random_01.txt | AC | 1218 ms | 40592 KiB |
| 01_max_random_02.txt | AC | 1175 ms | 40520 KiB |
| 01_max_random_03.txt | AC | 1160 ms | 40448 KiB |
| 01_max_random_04.txt | AC | 1174 ms | 40844 KiB |
| 02_all_1_00.txt | AC | 1058 ms | 40604 KiB |
| 03_all_2_00.txt | AC | 1120 ms | 40612 KiB |
| 04_hack_00.txt | AC | 858 ms | 40728 KiB |
| 04_hack_01.txt | AC | 984 ms | 40664 KiB |
| 04_hack_02.txt | AC | 1136 ms | 42020 KiB |
| 04_hack_03.txt | AC | 1109 ms | 42600 KiB |
| 04_hack_04.txt | AC | 1132 ms | 42056 KiB |