結果

問題 No.905 Sorted?
ユーザー simansiman
提出日時 2021-12-09 04:47:56
言語 Ruby
(3.3.0)
結果
AC  
実行時間 405 ms / 2,000 ms
コード長 487 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 11,524 KB
実行使用メモリ 30,500 KB
最終ジャッジ日時 2023-09-23 15:49:35
合計ジャッジ時間 8,591 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
15,324 KB
testcase_01 AC 76 ms
15,068 KB
testcase_02 AC 70 ms
15,032 KB
testcase_03 AC 70 ms
15,164 KB
testcase_04 AC 70 ms
15,316 KB
testcase_05 AC 74 ms
15,376 KB
testcase_06 AC 75 ms
15,148 KB
testcase_07 AC 82 ms
15,688 KB
testcase_08 AC 351 ms
23,200 KB
testcase_09 AC 244 ms
22,264 KB
testcase_10 AC 336 ms
23,984 KB
testcase_11 AC 342 ms
21,472 KB
testcase_12 AC 381 ms
21,540 KB
testcase_13 AC 388 ms
30,444 KB
testcase_14 AC 384 ms
30,500 KB
testcase_15 AC 405 ms
29,464 KB
testcase_16 AC 399 ms
29,760 KB
testcase_17 AC 393 ms
29,740 KB
testcase_18 AC 329 ms
29,744 KB
testcase_19 AC 73 ms
15,276 KB
testcase_20 AC 75 ms
15,132 KB
testcase_21 AC 72 ms
15,168 KB
testcase_22 AC 72 ms
15,080 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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