結果

問題 No.2462 七人カノン
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2023-09-09 17:32:59
言語 Rust
(1.77.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 3,043 bytes
コンパイル時間 1,546 ms
コンパイル使用メモリ 156,608 KB
実行使用メモリ 22,300 KB
最終ジャッジ日時 2023-09-09 17:33:08
合計ジャッジ時間 9,022 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 54 ms
19,096 KB
testcase_14 AC 57 ms
18,972 KB
testcase_15 AC 58 ms
17,992 KB
testcase_16 AC 62 ms
22,100 KB
testcase_17 AC 61 ms
20,536 KB
testcase_18 AC 14 ms
8,696 KB
testcase_19 AC 15 ms
8,612 KB
testcase_20 AC 64 ms
20,396 KB
testcase_21 AC 64 ms
20,404 KB
testcase_22 AC 64 ms
22,300 KB
testcase_23 AC 65 ms
20,408 KB
testcase_24 AC 43 ms
13,924 KB
testcase_25 AC 66 ms
20,536 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `i`
  --> Main.rs:21:11
   |
21 |     for &(i, s, t) in queries.iter() { imos[s] += 1; imos[t] -= 1; }
   |           ^ help: if this is intentional, prefix it with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

fn main() {
    let mut sc = Scanner::new();
    let t = 1;
    for _ in 0..t { solve(&mut sc); }
}

fn solve(sc:&mut Scanner) {
    let n = sc.usize();
    let q = sc.usize();
    let mut queries = Vec::with_capacity(q);

    for _ in 0..q {
        let i = sc.usize1();
        let s = sc.usize();
        let t = sc.usize();
        queries.push((i, s, t));
    }

    let mut imos = vec![0; 100_002];
    for &(i, s, t) in queries.iter() { imos[s] += 1; imos[t] -= 1; }
    for i in 0..100_001 { imos[i+1] += imos[i]; }


    let mut csum = vec![0.0; 100_003];
    for i in 0..100_001 {
        csum[i+1] = csum[i] + if imos[i] > 0 { 1. / imos[i] as f64 } else { 0. }
    }
    
    let mut ans = vec![0.0; n];
    for (i, s, t) in queries { ans[i] += csum[t] - csum[s]; }

    println!("{}", ans.iter().map(|a| a.to_string()).collect::<Vec<String>>().join("\n"));
}


struct Scanner { s : std::collections::VecDeque<String> } #[allow(unused)] impl Scanner { fn new() -> Self { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); Self { s : s.split_whitespace().map(|s| s.to_string()).collect() } } fn reload(&mut self) -> () { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); self.s = s.split_whitespace().map(|s| s.to_string()).collect(); } fn usize(&mut self) -> usize { self.input() } fn usize1(&mut self) -> usize { self.input::<usize>() - 1 } fn isize(&mut self) -> isize { self.input() } fn i32(&mut self) -> i32 { self.input() } fn i64(&mut self) -> i64 { self.input() } fn i128(&mut self) -> i128 { self.input() } fn u8(&mut self) -> u8 { self.input() } fn u32(&mut self) -> u32 { self.input() } fn u64(&mut self) -> u64 { self.input() } fn u128(&mut self) -> u128 { self.input() } fn edge(&mut self) -> (usize, usize) { (self.usize1(), self.usize1()) } fn edges(&mut self, m : usize) -> Vec<(usize, usize)> { let mut e = Vec::with_capacity(m); for _ in 0..m { e.push(self.edge()); } e } fn wedge<T:std::str::FromStr>(&mut self) -> (usize, usize, T) { (self.usize1(), self.usize1(), self.input()) } fn wedges<T:std::str::FromStr>(&mut self, m : usize) -> Vec<(usize, usize, T)> { let mut e = Vec::with_capacity(m); for _ in 0..m { e.push(self.wedge()); } e } fn input<T>(&mut self) -> T where T: std::str::FromStr { if self.s.is_empty() { self.reload(); } if let Some(head) = self.s.pop_front() { head.parse::<T>().ok().unwrap() } else { panic!() } } fn tuple<T, U>(&mut self) -> (T, U) where T: std::str::FromStr, U: std::str::FromStr { (self.input(), self.input()) } fn vec<T>(&mut self, n: usize) -> Vec<T> where T: std::str::FromStr { if self.s.is_empty() { self.reload(); } self.s.drain(..n).map(|s| s.parse::<T>().ok().unwrap() ).collect::<Vec<T>>() } fn nvec<T>(&mut self) -> Vec<T> where T: std::str::FromStr { let n : usize = self.input(); self.vec(n) } fn chars(&mut self) -> Vec<char> { let s : String = self.input(); s.chars().collect() } fn bytes(&mut self) -> Vec<u8> { let s : String = self.input(); s.bytes().collect() } }
0