結果

問題 No.2758 RDQ
ユーザー CoCo_Japan_panCoCo_Japan_pan
提出日時 2024-05-17 22:04:45
言語 Rust
(1.77.0)
結果
AC  
実行時間 316 ms / 2,000 ms
コード長 2,335 bytes
コンパイル時間 11,436 ms
コンパイル使用メモリ 391,700 KB
実行使用メモリ 199,296 KB
最終ジャッジ日時 2024-05-17 23:45:22
合計ジャッジ時間 17,399 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 265 ms
198,528 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 230 ms
198,656 KB
testcase_07 AC 232 ms
198,656 KB
testcase_08 AC 230 ms
198,784 KB
testcase_09 AC 233 ms
198,656 KB
testcase_10 AC 229 ms
198,656 KB
testcase_11 AC 303 ms
199,296 KB
testcase_12 AC 307 ms
199,296 KB
testcase_13 AC 311 ms
199,296 KB
testcase_14 AC 308 ms
199,296 KB
testcase_15 AC 305 ms
199,296 KB
testcase_16 AC 304 ms
199,296 KB
testcase_17 AC 306 ms
199,296 KB
testcase_18 AC 316 ms
199,296 KB
testcase_19 AC 307 ms
199,296 KB
testcase_20 AC 303 ms
199,296 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
use proconio::marker::{Bytes, Chars, Isize1, Usize1};
use proconio::{fastout, input, input_interactive};

const BUCKET_SIZE: usize = 200;

#[fastout]
fn main() {
    input! {
        N: usize,
        Q: usize,
        A: [usize; N],
    }
    let bucket_memo = {
        let mut memo = mat![0; (N + BUCKET_SIZE - 1) / BUCKET_SIZE; 100_001];
        for (i, &a) in A.iter().enumerate() {
            let bucket = i / BUCKET_SIZE;
            for d in 1.. {
                if d * d > a {
                    break;
                }
                if a % d == 0 {
                    memo[bucket][d] += 1;
                    if a / d != d {
                        memo[bucket][a / d] += 1;
                    }
                }
            }
        }
        memo
    };
    for _ in 0..Q {
        input! {
            L: Usize1,
            R: Usize1,
            K: usize,
        }
        let l_bucket = L / BUCKET_SIZE;
        let r_bucket = R / BUCKET_SIZE;
        let memo_ans = (l_bucket + 1..r_bucket).map(|i| bucket_memo[i][K]).sum::<usize>();
        let left_ans = (L..((l_bucket+1)*BUCKET_SIZE).min(R+1)).map(|i| (A[i] % K == 0) as usize).sum::<usize>();
        let right_ans = if l_bucket < r_bucket {
            ((r_bucket*BUCKET_SIZE).max(L)..(R+1)).map(|i| (A[i] % K == 0) as usize).sum::<usize>()
        } else {
            0
        };
        println!("{}", memo_ans + left_ans + right_ans);
    }
}



#[macro_export]
macro_rules! mat {
    ($($e:expr),*) => { vec![$($e),*] };
    ($($e:expr,)*) => { vec![$($e),*] };
    ($e:expr; $d:expr) => { vec![$e; $d] };
    ($e:expr; $d:expr $(; $ds:expr)+) => { vec![mat![$e $(; $ds)*]; $d] };
}

#[macro_export]
macro_rules! chmin {
    ($a:expr, $b:expr) => {
        if $a > $b {
            $a = $b;
            true
        } else {
            false
        }
    };
}

#[macro_export]
macro_rules! chmax {
    ($a:expr, $b:expr) => {
        if $a < $b {
            $a = $b;
            true
        } else {
            false
        }
    };
}

/// https://maguro.dev/debug-macro/
#[macro_export]
macro_rules! debug {
    ($($a:expr),* $(,)*) => {
        #[cfg(debug_assertions)]
        eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
    };
}
0