Submission #27334595
Source Code Expand
class BIT
def initialize n, h=nil
@n = n
@h = h||Hash.new(0)
end
def clone
return BIT.new @n,@h.dup
end
def size
return @h.size
end
def [] i
i += 1
s = 0
while 0<i
s += @h[i]
i &= i-1
end
return s
end
def add i,d
i += 1
while i<@n
@h[i] += d
i += i&-i
end
return d
end
end
N,Q = gets.split.map(&:to_i)
Y = Hash.new{|h,k|h[k]=[]}
N.times{
x,y,d,c = gets.split.map(&:to_i)
d += 1
Y[y ]<<[x, c]<<[x+d,-c]
Y[y+d]<<[x,-c]<<[x+d, c]
}
Q.times{|q|
# A,B のどっちが X 座標でどっちが Y 座標か。サンプルから読み解くのはあまりに面倒。
a,b = gets.split.map(&:to_i)
Y[b]<<[a,q,q]
}
A = [nil]*Q
B = BIT.new 10**9*2+2
Y.keys.sort.each{|y|
Y[y].each{|x,c,q|
x += 10**9
if q
A[q] = B[x]
else
B.add x,c
end
}
}
puts A
Submission Info
| Submission Time | |
|---|---|
| Task | N - Building Construction |
| User | ds14050 |
| Language | Ruby (2.7.1) |
| Score | 6 |
| Code Size | 872 Byte |
| Status | AC |
| Exec Time | 1105 ms |
| Memory | 96608 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 6 / 6 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | s1.txt, s2.txt, s3.txt |
| All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, s1.txt, s2.txt, s3.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | AC | 111 ms | 21396 KiB |
| 02.txt | AC | 86 ms | 16724 KiB |
| 03.txt | AC | 77 ms | 16020 KiB |
| 04.txt | AC | 86 ms | 17976 KiB |
| 05.txt | AC | 100 ms | 18380 KiB |
| 06.txt | AC | 108 ms | 21384 KiB |
| 07.txt | AC | 73 ms | 16024 KiB |
| 08.txt | AC | 85 ms | 16660 KiB |
| 09.txt | AC | 90 ms | 17984 KiB |
| 10.txt | AC | 121 ms | 21988 KiB |
| 11.txt | AC | 1092 ms | 96608 KiB |
| 12.txt | AC | 1105 ms | 96132 KiB |
| 13.txt | AC | 1096 ms | 93592 KiB |
| 14.txt | AC | 1064 ms | 93740 KiB |
| 15.txt | AC | 1007 ms | 94148 KiB |
| 16.txt | AC | 988 ms | 93804 KiB |
| 17.txt | AC | 1030 ms | 96428 KiB |
| 18.txt | AC | 984 ms | 94024 KiB |
| s1.txt | AC | 56 ms | 14300 KiB |
| s2.txt | AC | 55 ms | 14148 KiB |
| s3.txt | AC | 58 ms | 14116 KiB |