結果

問題 No.1093 区間の和 / Sum of Range
ユーザー yuruhiyayuruhiya
提出日時 2020-06-26 13:12:09
言語 Crystal
(1.10.0)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 23,173 ms
コンパイル使用メモリ 256,672 KB
実行使用メモリ 11,956 KB
最終ジャッジ日時 2023-09-13 10:53:32
合計ジャッジ時間 25,521 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 79 ms
7,476 KB
testcase_02 AC 39 ms
5,148 KB
testcase_03 AC 24 ms
10,420 KB
testcase_04 AC 18 ms
10,176 KB
testcase_05 AC 118 ms
7,244 KB
testcase_06 AC 26 ms
6,480 KB
testcase_07 AC 65 ms
7,268 KB
testcase_08 AC 54 ms
10,404 KB
testcase_09 AC 103 ms
6,088 KB
testcase_10 AC 60 ms
10,280 KB
testcase_11 AC 107 ms
7,560 KB
testcase_12 AC 66 ms
10,256 KB
testcase_13 AC 3 ms
4,612 KB
testcase_14 AC 117 ms
6,468 KB
testcase_15 AC 30 ms
7,252 KB
testcase_16 AC 137 ms
8,400 KB
testcase_17 AC 111 ms
6,004 KB
testcase_18 AC 76 ms
6,540 KB
testcase_19 AC 9 ms
5,408 KB
testcase_20 AC 63 ms
5,800 KB
testcase_21 AC 136 ms
6,408 KB
testcase_22 AC 131 ms
10,488 KB
testcase_23 AC 96 ms
5,972 KB
testcase_24 AC 26 ms
9,996 KB
testcase_25 AC 113 ms
7,656 KB
testcase_26 AC 93 ms
10,300 KB
testcase_27 AC 133 ms
6,544 KB
testcase_28 AC 87 ms
10,340 KB
testcase_29 AC 168 ms
11,956 KB
testcase_30 AC 23 ms
5,956 KB
testcase_31 AC 30 ms
6,400 KB
testcase_32 AC 47 ms
7,500 KB
testcase_33 AC 139 ms
10,376 KB
testcase_34 AC 11 ms
4,992 KB
testcase_35 AC 154 ms
5,152 KB
testcase_36 AC 121 ms
10,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
0