結果

問題 No.905 Sorted?
ユーザー siman
提出日時 2021-12-09 04:47:56
言語 Ruby
(3.4.1)
結果
AC  
実行時間 447 ms / 2,000 ms
コード長 487 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 29,548 KB
最終ジャッジ日時 2024-07-16 15:35:25
合計ジャッジ時間 7,551 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A = gets.split.map(&:to_i)
Q = gets.to_i

counter = Array.new(N) { [0, 0] }

1.upto(N - 1) do |i|
  counter[i][0] = counter[i - 1][0]
  counter[i][1] = counter[i - 1][1]

  if A[i - 1] < A[i]
    counter[i][0] += 1
  elsif A[i - 1] > A[i]
    counter[i][1] += 1
  end
end

Q.times do
  l, r = gets.split.map(&:to_i)
  ans = [0, 0]

  if counter[r][0] == counter[l][0]
    ans[1] = 1
  end

  if counter[r][1] == counter[l][1]
    ans[0] = 1
  end

  puts ans.join(' ')
end
0