結果
問題 | No.610 区間賞(Section Award) |
ユーザー |
![]() |
提出日時 | 2023-06-09 01:39:31 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 521 ms / 2,000 ms |
コード長 | 814 bytes |
コンパイル時間 | 229 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 36,608 KB |
最終ジャッジ日時 | 2024-12-31 09:15:28 |
合計ジャッジ時間 | 15,073 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
コンパイルメッセージ
Syntax OK
ソースコード
class BinaryIndexTreedef initialize(size, init: 0)@values = Array.new(size, init)@size = sizeend# @param idx [Integer]# @param x [Numeric]def add(idx, x)raise 'Out of range reference' if @size <= idxidx += 1while idx <= @size@values[idx - 1] += xidx += idx & -idxendenddef sum(l, r)_sum(r) - _sum(l)endprivatedef _sum(idx)res = 0while idx > 0res += @values[idx - 1]idx -= idx & -idxendresendendN = gets.to_iA = gets.split.map(&:to_i)B = gets.split.map(&:to_i)rank = Hash.newA.each.with_index(1) do |a, i|rank[a] = iendbit = BinaryIndexTree.new(N + 1)ans = []B.each do |b|br = rank[b]if bit.sum(br, N + 1) == 0ans << bendbit.add(br, 1)endputs ans.sort