結果

問題 No.875 Range Mindex Query
ユーザー yosuteconyosutecon
提出日時 2020-01-10 13:09:22
言語 Julia
(1.10.2)
結果
WA  
実行時間 -
コード長 939 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 7,200 KB
実行使用メモリ 288,340 KB
最終ジャッジ日時 2024-04-09 14:16:26
合計ジャッジ時間 9,664 ms
ジャッジサーバーID
(参考情報)
judge5 / 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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function refresh(st::Array{Int,1},lt::Array{Int,1},x)
	n = length(st)
	rt = n>>1
	if x<=rt
		st[x<<1] += lt[x]
		st[x<<1+1] += lt[x]
		lt[x] = 0
	end
end

function main()
	n,q = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	k = 0
	while 2^k<n
		k += 1
	end
	rt = 2^k-1
	st = zeros(Int,2^(k+1)-1)
	for i in 1:n
		st[rt+i]=a[i]
	end
	for i in rt:-1:1
		st[i]=min(st[i<<1],st[i<<1+1])
	end
	for iter in 1:q
		f,ll,rr = readline() |> split |> parseMap
		if f==1
			tmp = st[rt+ll]
			st[rt+ll]=st[rt+rr]
			st[rt+rr]=tmp
		else
			rp = Int[]
			m = 10^18
			for i in k:-1:0
				l = (rt+ll)>>i
				r = (rt+rr)>>i
				if r-l>1&&i>0
					if l%2==0
						m=min(m,st[l+1])
					end
					if r%2==1
						m=min(m,st[r-1])
					end
				elseif i==0
					m=min(m,st[l])
					m=min(m,st[r])
				end
			end
			println(m)
		end
	end
end

main()
0