結果

問題 No.905 Sorted?
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2019-12-06 18:23:32
言語 Ruby
(3.3.0)
結果
AC  
実行時間 454 ms / 2,000 ms
コード長 465 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 11,312 KB
実行使用メモリ 30,044 KB
最終ジャッジ日時 2023-08-25 01:22:24
合計ジャッジ時間 7,888 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,084 KB
testcase_01 AC 82 ms
15,248 KB
testcase_02 AC 78 ms
15,056 KB
testcase_03 AC 83 ms
15,352 KB
testcase_04 AC 82 ms
15,340 KB
testcase_05 AC 88 ms
15,488 KB
testcase_06 AC 82 ms
15,312 KB
testcase_07 AC 93 ms
15,584 KB
testcase_08 AC 360 ms
24,260 KB
testcase_09 AC 266 ms
20,384 KB
testcase_10 AC 397 ms
23,660 KB
testcase_11 AC 368 ms
22,596 KB
testcase_12 AC 413 ms
24,600 KB
testcase_13 AC 454 ms
30,004 KB
testcase_14 AC 446 ms
30,044 KB
testcase_15 AC 446 ms
25,700 KB
testcase_16 AC 396 ms
25,688 KB
testcase_17 AC 454 ms
25,704 KB
testcase_18 AC 372 ms
25,760 KB
testcase_19 AC 78 ms
15,204 KB
testcase_20 AC 79 ms
15,296 KB
testcase_21 AC 79 ms
15,156 KB
testcase_22 AC 78 ms
15,040 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

INC = Array.new(N, &:itself)
DEC = Array.new(N, &:itself)

N.times.inject(-1) do |r,l|
  INC[l] = ( l <= r ? r : (l ... N).find{|r_| (r_ + 1 >= N || A[r_ + 1] < A[r_]) } )
end
N.times.inject(-1) do |r,l|
  DEC[l] = ( l <= r ? r : (l ... N).find{|r_| (r_ + 1 >= N || A[r_ + 1] > A[r_]) } )
end

Q = gets.to_i
ANS = Q.times.map do
  l,r = gets.split.map(&:to_i)
  "#{r <= INC[l] ? 1 : 0} #{r <= DEC[l] ? 1 : 0}"
end
puts ANS
0