結果

問題 No.875 Range Mindex Query
ユーザー hoktohokto
提出日時 2020-02-13 17:48:44
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,991 ms / 2,000 ms
コード長 1,786 bytes
コンパイル時間 47 ms
コンパイル使用メモリ 7,808 KB
実行使用メモリ 37,504 KB
最終ジャッジ日時 2024-04-15 23:16:00
合計ジャッジ時間 15,286 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
12,288 KB
testcase_01 AC 103 ms
12,672 KB
testcase_02 AC 101 ms
12,544 KB
testcase_03 AC 88 ms
12,160 KB
testcase_04 AC 93 ms
12,416 KB
testcase_05 AC 92 ms
12,160 KB
testcase_06 AC 93 ms
12,416 KB
testcase_07 AC 94 ms
12,288 KB
testcase_08 AC 94 ms
12,288 KB
testcase_09 AC 93 ms
12,288 KB
testcase_10 AC 96 ms
12,544 KB
testcase_11 AC 1,668 ms
37,504 KB
testcase_12 AC 1,282 ms
24,448 KB
testcase_13 AC 1,286 ms
32,640 KB
testcase_14 AC 1,276 ms
36,736 KB
testcase_15 AC 1,626 ms
32,896 KB
testcase_16 AC 1,875 ms
32,640 KB
testcase_17 AC 1,991 ms
32,640 KB
testcase_18 AC 1,930 ms
32,768 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end


def min(val1,val2)
  return val1[0]>val2[0] ? val2 : val1
end
class ST
  attr_accessor:node,:n
  def initialize(n)
    @n=1
    @n*=2 while @n<n
    n=@n
    @node=array(2,2*@n-1,10**5+1)
  end

  def update(i,x)
    @node[i+@n-1][1]=i
    i=@n+i-1
    @node[i][0]=x
    while i>0
      i=(i-1)/2
      @node[i]=min(@node[i*2+1],@node[i*2+2])
    end
  end

  def find(s,t,i,l,r)
    return [10**5+1,10**5+1] if(r<=s or t<=l)
    return @node[i] if (s<=l and r<=t)
    mid=(l+r)/2
    leaf_l=find(s,t,i*2+1,l,mid)
    leaf_r=find(s,t,i*2+2,mid,r)
    return min(leaf_l,leaf_r)
  end
  def swap(l,r)
    val=@node[l+@n-1][0]
    @node[r+@n-1][0]
    update(l,@node[r+@n-1][0])
    update(r,val)
  end
end
n,q=get_i
a=get_i
st=ST.new(n)
_n=1
_n*=2 while _n<n
a.each_with_index do|num,i|
  st.update(i,num)
end

q.times do|i|
  c,l,r=get_i
  if c==1
    st.swap(l-1,r-1) 
  else
    puts st.find(l-1,r,0,0,_n)[1]+1
  end
end
0