結果

問題 No.2961 Shiny Monster Master
ユーザー naut3naut3
提出日時 2024-11-17 07:57:21
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 14 ms / 1,777 ms
コード長 3,499 bytes
コンパイル時間 13,671 ms
コンパイル使用メモリ 377,748 KB
実行使用メモリ 11,224 KB
最終ジャッジ日時 2024-11-17 07:57:41
合計ジャッジ時間 16,425 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 1 ms
5,248 KB
testcase_04 AC 1 ms
5,248 KB
testcase_05 AC 7 ms
6,528 KB
testcase_06 AC 6 ms
8,700 KB
testcase_07 AC 8 ms
7,552 KB
testcase_08 AC 10 ms
10,112 KB
testcase_09 AC 3 ms
5,248 KB
testcase_10 AC 13 ms
9,984 KB
testcase_11 AC 8 ms
8,668 KB
testcase_12 AC 7 ms
9,252 KB
testcase_13 AC 1 ms
5,248 KB
testcase_14 AC 10 ms
9,856 KB
testcase_15 AC 9 ms
6,528 KB
testcase_16 AC 6 ms
7,664 KB
testcase_17 AC 8 ms
5,248 KB
testcase_18 AC 9 ms
7,168 KB
testcase_19 AC 10 ms
6,912 KB
testcase_20 AC 9 ms
9,728 KB
testcase_21 AC 9 ms
9,472 KB
testcase_22 AC 3 ms
5,248 KB
testcase_23 AC 8 ms
5,248 KB
testcase_24 AC 4 ms
5,248 KB
testcase_25 AC 9 ms
8,960 KB
testcase_26 AC 9 ms
8,636 KB
testcase_27 AC 7 ms
6,016 KB
testcase_28 AC 6 ms
7,340 KB
testcase_29 AC 5 ms
5,888 KB
testcase_30 AC 10 ms
10,752 KB
testcase_31 AC 9 ms
8,064 KB
testcase_32 AC 8 ms
8,320 KB
testcase_33 AC 10 ms
9,492 KB
testcase_34 AC 6 ms
8,192 KB
testcase_35 AC 11 ms
9,464 KB
testcase_36 AC 4 ms
7,840 KB
testcase_37 AC 10 ms
6,528 KB
testcase_38 AC 4 ms
7,040 KB
testcase_39 AC 7 ms
9,216 KB
testcase_40 AC 6 ms
6,528 KB
testcase_41 AC 4 ms
5,248 KB
testcase_42 AC 8 ms
7,996 KB
testcase_43 AC 3 ms
5,248 KB
testcase_44 AC 11 ms
7,532 KB
testcase_45 AC 1 ms
5,248 KB
testcase_46 AC 5 ms
5,248 KB
testcase_47 AC 8 ms
10,496 KB
testcase_48 AC 5 ms
9,216 KB
testcase_49 AC 5 ms
5,504 KB
testcase_50 AC 10 ms
9,216 KB
testcase_51 AC 6 ms
5,248 KB
testcase_52 AC 6 ms
6,400 KB
testcase_53 AC 4 ms
6,820 KB
testcase_54 AC 3 ms
5,248 KB
testcase_55 AC 9 ms
9,984 KB
testcase_56 AC 10 ms
7,128 KB
testcase_57 AC 7 ms
6,016 KB
testcase_58 AC 6 ms
6,824 KB
testcase_59 AC 9 ms
8,192 KB
testcase_60 AC 7 ms
5,248 KB
testcase_61 AC 6 ms
5,888 KB
testcase_62 AC 13 ms
10,752 KB
testcase_63 AC 9 ms
10,232 KB
testcase_64 AC 6 ms
5,248 KB
testcase_65 AC 10 ms
8,192 KB
testcase_66 AC 1 ms
5,248 KB
testcase_67 AC 1 ms
5,248 KB
testcase_68 AC 1 ms
5,248 KB
testcase_69 AC 2 ms
5,248 KB
testcase_70 AC 1 ms
5,248 KB
testcase_71 AC 1 ms
5,248 KB
testcase_72 AC 1 ms
5,248 KB
testcase_73 AC 1 ms
5,248 KB
testcase_74 AC 13 ms
11,112 KB
testcase_75 AC 14 ms
11,224 KB
testcase_76 AC 13 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case, unused_must_use, unused_imports)]
use std::io::{self, prelude::*};

fn main() {
    let (stdin, stdout) = (io::read_to_string(io::stdin()).unwrap(), io::stdout());
    let (mut stdin, mut buffer) = (stdin.split_whitespace(), io::BufWriter::new(stdout.lock()));

    macro_rules! input {
        ($t: tt, $n: expr) => {
            (0..$n).map(|_| input!($t)).collect::<Vec<_>>()
        };
        (Chars) => {
            input!(String).chars().collect::<Vec<_>>()
        };
        (Usize1) => {
            stdin.next().unwrap().parse::<usize>().unwrap() - 1
        };
        ($t: ty) => {
            stdin.next().unwrap().parse::<$t>().unwrap()
        };
    }

    let R = input!(usize);
    let N = input!(usize);
    let A = input!(usize, N);

    let mut bit = binary_indexed_tree::BinaryIndexedTree::new(R);

    for a in A {
        bit.add(a, 1);
    }

    for _ in 0..input!(u32) {
        let l = input!(usize);
        let r = input!(usize);

        let ql = l % R;
        let c1 = N * (l / R) + if ql > 0 { bit.sum(0..ql) } else { 0 };

        let qr = r % R;
        let c2 = N * (r / R) + bit.sum(0..=qr);

        writeln!(buffer, "{}", c2 - c1);
    }
}

#[rustfmt::skip]
pub mod binary_indexed_tree {#[derive(Clone, PartialEq, Eq, Debug)]pub struct BinaryIndexedTree<T> { tree: Vec<T>, pub size: usize,}impl< T: Default + Clone + Copy + PartialOrd + Ord + std::ops::AddAssign + std::ops::Sub<Output = T> + std::ops::Add<Output = T>, > BinaryIndexedTree<T>{ pub fn new(size: usize) -> Self { return Self { tree: vec![T::default(); size + 1], size, }; } pub fn add(&mut self, i: usize, w: T) { assert!(i < self.size); self._add(i + 1, w); } pub fn prefix_sum(&self, i: usize) -> T { assert!(i < self.size, "size = {}, index = {}", self.size, i); self._sum(i + 1) } pub fn sum<R: std::ops::RangeBounds<usize>>(&self, range: R) -> T { let left = match range.start_bound() { std::ops::Bound::Included(&l) => l, std::ops::Bound::Excluded(&l) => l + 1, std::ops::Bound::Unbounded => 0, }; let right = match range.end_bound() { std::ops::Bound::Included(&r) => r, std::ops::Bound::Excluded(&r) => r - 1, std::ops::Bound::Unbounded => self.tree.len() - 2, }; if left == 0 { return self.prefix_sum(right); } else { return self.prefix_sum(right) - self.prefix_sum(left - 1); } } pub fn upper_bound(&self, w: T) -> usize { let mut d = self.tree.len().next_power_of_two() / 2; let mut j = 0; let mut u = T::default(); while d != 0 { if j + d < self.tree.len() { let v = u + self.tree[j + d]; if v <= w { u = v; j += d; } } d /= 2; } j } pub fn from(array: &[T]) -> Self { let mut tree = vec![T::default(); array.len() + 1]; for i in 1..tree.len() { let x = array[i - 1]; tree[i] += x; let j = i + (i & i.wrapping_neg()); if j < tree.len() { let v = tree[i]; tree[j] += v; } } Self { tree, size: array.len(), } } fn _add(&mut self, mut i: usize, w: T) { while i < self.tree.len() { self.tree[i] += w; i += i & i.wrapping_neg(); } } fn _sum(&self, mut i: usize) -> T { let mut ret = T::default(); while i > 0 { ret += self.tree[i]; i -= i & i.wrapping_neg(); } return ret; }}impl< T: Default + Clone + Copy + PartialOrd + Ord + std::ops::AddAssign + std::ops::Sub<Output = T> + std::fmt::Display + std::ops::Add<Output = T>, > std::fmt::Display for BinaryIndexedTree<T>{ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, "{}", (0..self.size) .map(|i| self.sum(i..=i)) .map(|v| v.to_string()) .collect::<Vec<_>>() .join(" ") ) }}}
0