結果

問題 No.905 Sorted?
ユーザー akakimidori
提出日時 2019-10-11 21:28:52
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,034 bytes
コンパイル時間 11,724 ms
コンパイル使用メモリ 384,808 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-25 06:44:22
合計ジャッジ時間 13,669 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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