結果
問題 | No.1000 Point Add and Array Add |
ユーザー | siman |
提出日時 | 2020-02-28 22:16:06 |
言語 | Ruby (3.2.2) |
結果 |
AC
|
実行時間 | 1,224 ms / 2,000 ms |
コード長 | 991 bytes |
コンパイル時間 | 391 ms |
コンパイル使用メモリ | 11,472 KB |
実行使用メモリ | 38,964 KB |
最終ジャッジ日時 | 2023-08-03 20:40:51 |
合計ジャッジ時間 | 11,623 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 82 ms
15,068 KB |
testcase_01 | AC | 79 ms
15,328 KB |
testcase_02 | AC | 79 ms
15,100 KB |
testcase_03 | AC | 79 ms
15,208 KB |
testcase_04 | AC | 79 ms
15,116 KB |
testcase_05 | AC | 80 ms
15,188 KB |
testcase_06 | AC | 81 ms
15,096 KB |
testcase_07 | AC | 79 ms
15,248 KB |
testcase_08 | AC | 79 ms
15,280 KB |
testcase_09 | AC | 79 ms
15,184 KB |
testcase_10 | AC | 81 ms
14,988 KB |
testcase_11 | AC | 81 ms
14,984 KB |
testcase_12 | AC | 88 ms
15,168 KB |
testcase_13 | AC | 87 ms
15,216 KB |
testcase_14 | AC | 93 ms
15,332 KB |
testcase_15 | AC | 88 ms
15,428 KB |
testcase_16 | AC | 813 ms
36,996 KB |
testcase_17 | AC | 771 ms
28,120 KB |
testcase_18 | AC | 1,171 ms
38,896 KB |
testcase_19 | AC | 1,175 ms
38,704 KB |
testcase_20 | AC | 702 ms
36,488 KB |
testcase_21 | AC | 1,016 ms
38,964 KB |
testcase_22 | AC | 1,224 ms
38,700 KB |
testcase_23 | AC | 1,045 ms
38,964 KB |
コンパイルメッセージ
Syntax OK
ソースコード
class BinaryIndexTree attr_reader :bit, :size def initialize(size, init: 0) @bit = Array.new(size + 1, init) @size = size end def sum(i) s = 0 while i > 0 s += bit[i] i -= i & -i end s end def add(i, x) while i <= size bit[i] += x i += i & -i end end end N, Q = gets.split.map(&:to_i) A = gets.split.map(&:to_i) B = Array.new(N + 1, 0) C = Array.new(N + 2, 0) bit = BinaryIndexTree.new(N + 2) Q.times do c, x, y = gets.chomp.split x = x.to_i y = y.to_i if c == 'A' cnt = bit.sum(x) # p [x, cnt] if cnt > 0 # p 'middle update' B[x] += cnt * A[x - 1] # p B bit.add(x, -cnt) bit.add(x + 1, cnt) C[x] -= cnt C[x + 1] += cnt end A[x - 1] += y else bit.add(x, 1) bit.add(y + 1, -1) C[x] += 1 C[y + 1] -= 1 end # p [:C, C] end c = 0 1.upto(N) do |i| c += C[i] B[i] += A[i - 1] * c end # p A puts B[1..-1].join(' ')