提出 #29722776


ソースコード 拡げる

Q = gets.to_i
 
class LazySortArray < Array
  def initialize *args
    @lazy = []
    super
  end

  def lazy_push x
    @lazy.push(x)
  end

  def lazy_sort
    xsize = self.size ** 0.5
    if @lazy.size == 0
      return
    elsif @lazy.size < xsize
      @lazy.each do |x|
        i = self.bsearch_index{|a| a >= x}
        if i
          max = i
          self.insert(i, x)
        else
          self.push(x)
        end
      end
    else
      self.push(*@lazy)
      self.sort!
    end
    @lazy = []
  end
end
 
list = LazySortArray.new
 
Q.times do
  q, x, k = gets.split.map(&:to_i)
  if q == 1
    list.lazy_push(x)
  elsif q == 2
    list.lazy_sort
    i = list.bsearch_index{|a| a > x }
    i ||= list.size
    i -= k
    if i >= 0
      puts list[i]
    else
      puts -1
    end
  elsif q == 3
    list.lazy_sort
    i = list.bsearch_index{|a| a >= x }
    i ||= list.size
    i += k - 1
    if list[i]
      puts list[i]
    else
      puts -1
    end
  else
    raise
  end
end

提出情報

提出日時
問題 D - Sequence Query
ユーザ nog
言語 Ruby (2.7.1)
得点 400
コード長 996 Byte
結果 AC
実行時間 1157 ms
メモリ 21044 KiB

コンパイルエラー

./Main.rb:21: warning: assigned but unused variable - max
./Main.rb:49: warning: ambiguous first argument; put parentheses or a space even after `-' operator
./Main.rb:59: warning: ambiguous first argument; put parentheses or a space even after `-' operator

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 1
AC × 29
セット名 テストケース
Sample example0.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, add000.txt, add001.txt, add002.txt, add003.txt, add004.txt, add005.txt, example0.txt
ケース名 結果 実行時間 メモリ
000.txt AC 604 ms 15744 KiB
001.txt AC 607 ms 15380 KiB
002.txt AC 608 ms 15536 KiB
003.txt AC 608 ms 15400 KiB
004.txt AC 607 ms 15496 KiB
005.txt AC 719 ms 15224 KiB
006.txt AC 723 ms 15424 KiB
007.txt AC 725 ms 15520 KiB
008.txt AC 608 ms 15364 KiB
009.txt AC 605 ms 15508 KiB
010.txt AC 607 ms 15636 KiB
011.txt AC 616 ms 15320 KiB
012.txt AC 610 ms 15404 KiB
013.txt AC 604 ms 15412 KiB
014.txt AC 345 ms 14200 KiB
015.txt AC 376 ms 14572 KiB
016.txt AC 384 ms 14616 KiB
017.txt AC 223 ms 17824 KiB
018.txt AC 239 ms 21044 KiB
019.txt AC 256 ms 19284 KiB
020.txt AC 304 ms 15636 KiB
021.txt AC 304 ms 15692 KiB
add000.txt AC 1154 ms 20864 KiB
add001.txt AC 1155 ms 20876 KiB
add002.txt AC 1157 ms 20864 KiB
add003.txt AC 1148 ms 20724 KiB
add004.txt AC 1155 ms 20576 KiB
add005.txt AC 1151 ms 20476 KiB
example0.txt AC 54 ms 14496 KiB