結果

問題 No.1110 好きな歌
ユーザー tonyu0
提出日時 2020-07-10 22:09:32
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 64 ms / 5,000 ms
コード長 903 bytes
コンパイル時間 12,960 ms
コンパイル使用メモリ 385,208 KB
実行使用メモリ 6,888 KB
最終ジャッジ日時 2024-10-11 09:25:24
合計ジャッジ時間 17,036 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
use std::io::*;

fn lower_bound<T: PartialOrd>(x: T, a: &Vec<T>) -> usize {
    let mut l: usize = 0;
    let mut r: usize = a.len();
    while r != l {
        let mid = (l + r) >> 1;
        if a[mid] < x {
            l = mid + 1;
        } else {
            r = mid;
        }
    }
    l
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let d: i32 = itr.next().unwrap().parse().unwrap();
    let mut a: Vec<i32> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let b = a.clone();
    a.sort();
    let mut out = Vec::new();
    // a_i - a_j >= d
    for i in 0..n {
        writeln!(out, "{}", lower_bound(b[i] - d + 1, &a)).ok();
    }
    stdout().write_all(&out).unwrap();
}
0