結果

問題 No.510 二次漸化式
ユーザー letrangerjpletrangerjp
提出日時 2017-04-28 23:56:28
言語 Ruby
(3.2.2)
結果
TLE  
実行時間 -
コード長 491 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 11,320 KB
実行使用メモリ 22,516 KB
最終ジャッジ日時 2023-10-11 19:53:29
合計ジャッジ時間 5,523 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
19,480 KB
testcase_01 AC 81 ms
15,016 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
Q = gets.to_i
Query = Q.times.map{
  q,*args = gets.split
  [q.intern] + args.map(&:to_i)
}

$x = Hash.new(0)
$y = Hash.new(0)
$a = {}
$b = {}

def a(i)
  return 1 if i == 0
  $a[i] ||= $x[i-1] * b(i-1)**2 + a(i-1)
end

def b(i)
  return 1 if i == 0
  $b[i] ||= $y[i-1] * b(i-1) + 1
end

Query.each{|q, *args|
  case q
  when :a
    puts a(args[0]) % (10**9+7)
  when :x
    $x[args[0]] = args[1]
    $a.clear
  when :y
    $y[args[0]] = args[1]
    $a.clear; $b.clear
  end
}
0