結果
問題 | No.1093 区間の和 / Sum of Range |
ユーザー | fukafukatani |
提出日時 | 2020-10-24 20:06:01 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 128 ms / 2,000 ms |
コード長 | 2,239 bytes |
コンパイル時間 | 12,580 ms |
コンパイル使用メモリ | 404,452 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-21 15:32:45 |
合計ジャッジ時間 | 17,123 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 70 ms
6,944 KB |
testcase_02 | AC | 34 ms
6,940 KB |
testcase_03 | AC | 13 ms
6,940 KB |
testcase_04 | AC | 8 ms
6,944 KB |
testcase_05 | AC | 109 ms
6,940 KB |
testcase_06 | AC | 20 ms
6,944 KB |
testcase_07 | AC | 56 ms
6,944 KB |
testcase_08 | AC | 42 ms
6,944 KB |
testcase_09 | AC | 96 ms
6,944 KB |
testcase_10 | AC | 47 ms
6,944 KB |
testcase_11 | AC | 99 ms
6,940 KB |
testcase_12 | AC | 54 ms
6,944 KB |
testcase_13 | AC | 1 ms
6,940 KB |
testcase_14 | AC | 104 ms
6,940 KB |
testcase_15 | AC | 22 ms
6,944 KB |
testcase_16 | AC | 121 ms
6,940 KB |
testcase_17 | AC | 106 ms
6,940 KB |
testcase_18 | AC | 68 ms
6,940 KB |
testcase_19 | AC | 6 ms
6,940 KB |
testcase_20 | AC | 55 ms
6,940 KB |
testcase_21 | AC | 124 ms
6,940 KB |
testcase_22 | AC | 112 ms
6,940 KB |
testcase_23 | AC | 88 ms
6,940 KB |
testcase_24 | AC | 14 ms
6,944 KB |
testcase_25 | AC | 108 ms
6,944 KB |
testcase_26 | AC | 73 ms
6,944 KB |
testcase_27 | AC | 113 ms
6,944 KB |
testcase_28 | AC | 67 ms
6,940 KB |
testcase_29 | AC | 128 ms
6,940 KB |
testcase_30 | AC | 16 ms
6,940 KB |
testcase_31 | AC | 23 ms
6,940 KB |
testcase_32 | AC | 35 ms
6,940 KB |
testcase_33 | AC | 114 ms
6,940 KB |
testcase_34 | AC | 8 ms
6,940 KB |
testcase_35 | AC | 128 ms
6,940 KB |
testcase_36 | AC | 97 ms
6,940 KB |
ソースコード
#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let v = read_vec::<usize>(); let (n, k) = (v[0], v[1]); let a = read_vec::<i64>(); let q = read::<usize>(); let mut x = vec![0; q]; for i in 0..q { x[i] = read::<i64>(); } let mut s = vec![0; n - k + 1]; s[0] = (0..k).map(|x| a[x]).sum::<i64>(); for i in 1..s.len() { s[i] = s[i - 1] + a[i + k - 1] - a[i - 1]; } s.sort(); for num in x { let ans = s.upper_bound(&num); println!("{}", ans); } } fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } pub trait BinarySearch<T> { fn lower_bound(&self, x: &T) -> usize; fn upper_bound(&self, x: &T) -> usize; } impl<T: Ord> BinarySearch<T> for [T] { fn lower_bound(&self, x: &T) -> usize { let mut low = 0; let mut high = self.len(); while low != high { let mid = (low + high) / 2; match self[mid].cmp(x) { Ordering::Less => { low = mid + 1; } Ordering::Equal | Ordering::Greater => { high = mid; } } } low } fn upper_bound(&self, x: &T) -> usize { let mut low = 0; let mut high = self.len(); while low != high { let mid = (low + high) / 2; match self[mid].cmp(x) { Ordering::Less | Ordering::Equal => { low = mid + 1; } Ordering::Greater => { high = mid; } } } low } }