結果

問題 No.1705 Mode of long array
ユーザー 小野寺健小野寺健
提出日時 2021-11-30 12:49:18
言語 Ruby
(3.3.0)
結果
AC  
実行時間 2,018 ms / 3,000 ms
コード長 742 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 11,448 KB
実行使用メモリ 32,684 KB
最終ジャッジ日時 2023-09-16 05:34:12
合計ジャッジ時間 57,072 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,060 KB
testcase_01 AC 86 ms
15,076 KB
testcase_02 AC 85 ms
15,220 KB
testcase_03 AC 99 ms
15,388 KB
testcase_04 AC 98 ms
15,240 KB
testcase_05 AC 101 ms
15,288 KB
testcase_06 AC 131 ms
15,716 KB
testcase_07 AC 142 ms
15,804 KB
testcase_08 AC 132 ms
15,760 KB
testcase_09 AC 129 ms
15,780 KB
testcase_10 AC 127 ms
15,836 KB
testcase_11 AC 136 ms
15,744 KB
testcase_12 AC 134 ms
15,604 KB
testcase_13 AC 1,301 ms
28,208 KB
testcase_14 AC 882 ms
24,272 KB
testcase_15 AC 724 ms
21,432 KB
testcase_16 AC 871 ms
23,820 KB
testcase_17 AC 632 ms
21,032 KB
testcase_18 AC 539 ms
20,932 KB
testcase_19 AC 1,016 ms
24,480 KB
testcase_20 AC 666 ms
22,116 KB
testcase_21 AC 1,054 ms
25,668 KB
testcase_22 AC 1,456 ms
31,908 KB
testcase_23 AC 666 ms
23,504 KB
testcase_24 AC 648 ms
23,592 KB
testcase_25 AC 651 ms
23,636 KB
testcase_26 AC 658 ms
23,576 KB
testcase_27 AC 652 ms
23,668 KB
testcase_28 AC 653 ms
23,576 KB
testcase_29 AC 649 ms
23,588 KB
testcase_30 AC 657 ms
23,472 KB
testcase_31 AC 659 ms
23,580 KB
testcase_32 AC 659 ms
23,700 KB
testcase_33 AC 2,014 ms
32,368 KB
testcase_34 AC 1,972 ms
32,668 KB
testcase_35 AC 1,965 ms
32,672 KB
testcase_36 AC 1,982 ms
32,684 KB
testcase_37 AC 1,977 ms
32,508 KB
testcase_38 AC 2,002 ms
32,448 KB
testcase_39 AC 1,979 ms
32,612 KB
testcase_40 AC 1,982 ms
32,492 KB
testcase_41 AC 2,018 ms
32,480 KB
testcase_42 AC 1,992 ms
32,444 KB
testcase_43 AC 1,172 ms
31,636 KB
testcase_44 AC 1,180 ms
31,600 KB
testcase_45 AC 1,175 ms
31,784 KB
testcase_46 AC 1,177 ms
31,572 KB
testcase_47 AC 1,172 ms
31,532 KB
testcase_48 AC 1,191 ms
31,644 KB
testcase_49 AC 1,803 ms
32,284 KB
testcase_50 AC 1,791 ms
32,524 KB
testcase_51 AC 1,791 ms
32,448 KB
testcase_52 AC 1,796 ms
32,480 KB
testcase_53 AC 1,808 ms
32,372 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class SegmentTree
	def initialize(n)
		@n = 1
		while @n < n do
			@n *= 2
		end
		@dat = Array.new(2*@n-1, Array.new(2, -1))
	end
	def update(k, a)
		i = k
		k += @n - 1
		@dat[k] = [a, i]
		while k > 0 do
			k = (k - 1) / 2
			@dat[k] = [@dat[k * 2 + 1], @dat[k * 2 + 2]].max
		end
	end
	def max
		@dat[0][1] + 1
	end
	def dat(i)
		@dat[i + @n - 1][0]
	end
end

N, M = gets.split(" ").map{|s| s.to_i}
a = gets.split(" ").map{|s| s.to_i}
tree = SegmentTree.new(M)
a.each_with_index {|x, i|
	tree.update(i, x)
}

Q = gets.to_i
q = []
Q.times {
	q << gets.split(" ").map{|s| s.to_i}
}

q.each {|t, x, y|
	if t == 1 then
		tree.update(x-1, tree.dat(x-1) + y)
	elsif t == 2 then
		tree.update(x-1, tree.dat(x-1) - y)
	else
		puts tree.max
	end
}
0