結果

問題 No.905 Sorted?
ユーザー akakimidoriakakimidori
提出日時 2019-10-11 21:28:52
言語 Rust
(1.77.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,034 bytes
コンパイル時間 1,270 ms
コンパイル使用メモリ 148,608 KB
実行使用メモリ 8,020 KB
最終ジャッジ日時 2023-08-16 17:08:56
合計ジャッジ時間 3,047 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 18 ms
5,176 KB
testcase_09 AC 10 ms
4,380 KB
testcase_10 AC 19 ms
7,928 KB
testcase_11 AC 16 ms
5,584 KB
testcase_12 AC 18 ms
5,516 KB
testcase_13 AC 24 ms
8,020 KB
testcase_14 AC 24 ms
7,964 KB
testcase_15 AC 19 ms
5,896 KB
testcase_16 AC 19 ms
5,988 KB
testcase_17 AC 18 ms
5,888 KB
testcase_18 AC 15 ms
5,968 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 0 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let a: Vec<i64> = (0..n).map(|_| it.next().unwrap().parse().unwrap()).collect();
    let mut b = vec![0; n];
    let mut c = vec![0; n];
    for i in 1..n {
        if a[i - 1] < a[i] {
            b[i - 1] = 1;
        }
        if a[i - 1] > a[i] {
            c[i - 1] = 1;
        }
    }
    for i in (1..n).rev() {
        b[i - 1] += b[i];
        c[i - 1] += c[i];
    }
    let q: usize = it.next().unwrap().parse().unwrap();
    let mut ans = String::new();
    for _ in 0..q {
        let l: usize = it.next().unwrap().parse().unwrap();
        let r: usize = it.next().unwrap().parse().unwrap();
        let x = if c[l] - c[r] > 0 {0} else {1};
        let y = if b[l] - b[r] > 0 {0} else {1};
        ans.push_str(&format!("{} {}\n", x, y));
    }
    print!("{}", ans);
}

fn main() {
    run();
}
0