結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー 小野寺健小野寺健
提出日時 2021-11-05 08:08:18
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 846 bytes
コンパイル時間 121 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 39,040 KB
最終ジャッジ日時 2024-04-23 15:49:17
合計ジャッジ時間 6,214 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:49: warning: assigned but unused variable - res
Syntax OK

ソースコード

diff #

class SegmentTree
	def initialize(arr)
		@h = (arr.length - 1).bit_length
		@n = 2**@h
		@ie = Float::INFINITY
		@tree = Array.new(2*@n, @ie)
		0.upto(arr.length-1) {|i|
			@tree[@n + i] = arr[i]
		}
		(@n-1).downto(1) {|i|
			@tree[i] = [@tree[2 * i], @tree[2 * i + 1]].min
		}
	end
	def set(idx, x)
		idx += @n
		@tree[idx] = x
		while idx > 0 do
			idx >>= 1
			@tree[idx] = [@tree[2 * idx], @tree[2 * idx + 1]].min
		end
	end
	def query(lt, rt)
		lt += @n
		rt += @n
		vl = vr = @ie
		while rt - lt > 0 do
			if lt & 1 != 0 then
				vl = [vl, @tree[lt]].min
				lt += 1
			end
			if rt & 1 != 0 then
				rt -= 1
				vr = [@tree[rt], vr].min
			end
			lt >>= 1
			rt >>= 1
		end
		[vl, vr].min
	end
end

INF = Float::INFINITY

N = gets.to_i
A = gets.split(" ").map{|s| s.to_i}

S = A.map.with_index{|x, i| [x, i]}.sort_by!{|x| x[0]}

res = INF
0