結果
| 問題 | 
                            No.1093 区間の和 / Sum of Range
                             | 
                    
| ユーザー | 
                             yuruhiya
                         | 
                    
| 提出日時 | 2020-06-26 13:12:09 | 
| 言語 | Crystal  (1.14.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 158 ms / 2,000 ms | 
| コード長 | 950 bytes | 
| コンパイル時間 | 12,010 ms | 
| コンパイル使用メモリ | 297,824 KB | 
| 実行使用メモリ | 13,184 KB | 
| 最終ジャッジ日時 | 2024-06-30 20:22:13 | 
| 合計ジャッジ時間 | 16,366 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 36 | 
ソースコード
class CulSum(T)
  def initialize(a : Array(T))
    @n = a.size
    @s = Array(T).new(@n + 1, 0)
    @n.times do |i|
      @s[i + 1] = @s[i] + a[i]
    end
  end
  def initialize(@n : Int32, &f : Int32 -> T)
    @s = Array(T).new(@n + 1, 0)
    @n.times do |i|
      @s[i + 1] = @s[i] + yield(i)
    end
  end
  def initialize(a, &f)
    @n = a.size
    @s = Array.new(@n + 1, 0)
    @n.times do |i|
      @s[i + 1] = @s[i] + yield(a[i])
    end
  end
  def [](l : Int32, r : Int32)
    l < r ? @s[r] - @s[l] : 0
  end
  def [](i : Int32)
    @s[i]
  end
  def [](r : Range(Int32, Int32))
    @s[r.exclusive? ? r.end : r.end + 1] - @s[r.begin]
  end
  def to_a
    @n.times.to_a.map { |i| self[i..i] }
  end
end
n, k = read_line.split.map &.to_i
a = read_line.split.map &.to_i
cul = CulSum.new(a)
s = (0..n - k).map { |i| cul[i, i + k] }.sort + [10**9 + 7]
read_line.to_i.times do
  x = read_line.to_i
  puts s.bsearch_index { |i| i > x }
end
            
            
            
        
            
yuruhiya