結果

問題 No.2961 Shiny Monster Master
ユーザー naut3naut3
提出日時 2024-11-17 07:56:31
言語 Rust
(1.77.0 + proconio)
結果
WA  
実行時間 -
コード長 3,524 bytes
コンパイル時間 14,823 ms
コンパイル使用メモリ 385,232 KB
実行使用メモリ 11,224 KB
最終ジャッジ日時 2024-11-17 07:56:52
合計ジャッジ時間 19,179 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,820 KB
testcase_03 AC 1 ms
6,816 KB
testcase_04 AC 1 ms
6,820 KB
testcase_05 AC 8 ms
6,816 KB
testcase_06 AC 5 ms
8,700 KB
testcase_07 AC 8 ms
7,532 KB
testcase_08 AC 10 ms
10,100 KB
testcase_09 AC 3 ms
6,820 KB
testcase_10 AC 11 ms
9,932 KB
testcase_11 AC 8 ms
8,668 KB
testcase_12 AC 7 ms
9,292 KB
testcase_13 AC 1 ms
6,820 KB
testcase_14 AC 10 ms
10,024 KB
testcase_15 AC 9 ms
6,820 KB
testcase_16 AC 5 ms
7,744 KB
testcase_17 AC 8 ms
6,816 KB
testcase_18 AC 10 ms
7,256 KB
testcase_19 AC 11 ms
7,040 KB
testcase_20 AC 10 ms
9,812 KB
testcase_21 AC 12 ms
9,304 KB
testcase_22 AC 4 ms
6,816 KB
testcase_23 AC 9 ms
6,816 KB
testcase_24 AC 4 ms
6,816 KB
testcase_25 AC 9 ms
8,968 KB
testcase_26 AC 11 ms
8,488 KB
testcase_27 AC 7 ms
6,820 KB
testcase_28 AC 7 ms
7,464 KB
testcase_29 AC 4 ms
6,820 KB
testcase_30 AC 11 ms
10,768 KB
testcase_31 AC 8 ms
8,300 KB
testcase_32 AC 9 ms
8,472 KB
testcase_33 AC 12 ms
9,492 KB
testcase_34 AC 7 ms
8,084 KB
testcase_35 AC 11 ms
9,588 KB
testcase_36 AC 5 ms
7,812 KB
testcase_37 AC 11 ms
6,820 KB
testcase_38 AC 6 ms
6,860 KB
testcase_39 AC 8 ms
9,140 KB
testcase_40 AC 7 ms
6,816 KB
testcase_41 AC 3 ms
6,816 KB
testcase_42 AC 10 ms
8,116 KB
testcase_43 AC 4 ms
6,820 KB
testcase_44 AC 11 ms
7,640 KB
testcase_45 AC 1 ms
6,820 KB
testcase_46 AC 5 ms
6,816 KB
testcase_47 AC 9 ms
10,240 KB
testcase_48 AC 4 ms
9,112 KB
testcase_49 AC 4 ms
6,820 KB
testcase_50 AC 10 ms
9,236 KB
testcase_51 AC 7 ms
6,820 KB
testcase_52 AC 7 ms
6,816 KB
testcase_53 AC 6 ms
6,820 KB
testcase_54 AC 3 ms
6,816 KB
testcase_55 AC 9 ms
10,048 KB
testcase_56 AC 10 ms
7,132 KB
testcase_57 AC 7 ms
6,816 KB
testcase_58 AC 6 ms
7,064 KB
testcase_59 AC 10 ms
8,100 KB
testcase_60 AC 8 ms
6,816 KB
testcase_61 AC 6 ms
6,816 KB
testcase_62 AC 13 ms
10,792 KB
testcase_63 AC 9 ms
10,340 KB
testcase_64 AC 6 ms
6,820 KB
testcase_65 AC 10 ms
8,340 KB
testcase_66 AC 1 ms
6,816 KB
testcase_67 WA -
testcase_68 WA -
testcase_69 AC 1 ms
6,820 KB
testcase_70 WA -
testcase_71 AC 1 ms
6,816 KB
testcase_72 AC 1 ms
6,816 KB
testcase_73 WA -
testcase_74 AC 13 ms
11,220 KB
testcase_75 AC 14 ms
11,224 KB
testcase_76 AC 13 ms
11,216 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) + if qr > 0 { bit.sum(0..=qr) } else { 0 };

        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