Submission #74118342


Source Code Expand

use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        a: [usize; n],
        q: usize,
        x: [u128; q],
    }

    let mut count = vec![0usize; m + 1];
    for &val in &a {
        count[val] += 1;
    }

    let max_possible_count = n + m + 1;
    let mut by_count: Vec<Vec<usize>> = vec![Vec::new(); max_possible_count];
    for v in 1..=m {
        by_count[count[v]].push(v);
    }

    let mut added: Vec<usize> = Vec::with_capacity(m * 2);
    let mut min_count = 0;
    while min_count < max_possible_count && by_count[min_count].is_empty() {
        min_count += 1;
    }

    loop {
        let mut max_count = min_count;
        for c in (min_count + 1)..max_possible_count {
            if !by_count[c].is_empty() {
                max_count = c;
            }
        }

        if min_count == max_count {
            break;
        }

        let values = std::mem::take(&mut by_count[min_count]);
        if values.is_empty() {
            while min_count < max_possible_count && by_count[min_count].is_empty() {
                min_count += 1;
            }
            if min_count >= max_possible_count {
                break;
            }
            continue;
        }

        for v in values {
            added.push(v);
            count[v] += 1;
            by_count[count[v]].push(v);
        }

        while min_count < max_possible_count && by_count[min_count].is_empty() {
            min_count += 1;
        }
        if min_count >= max_possible_count {
            break;
        }
    }

    let total_added = added.len();

    for &xi in &x {
        if xi <= n as u128 {
            println!("{}", a[(xi - 1) as usize]);
        } else {
            let pos = xi - n as u128;
            if pos <= total_added as u128 {
                println!("{}", added[(pos - 1) as usize]);
            } else {
                let remaining = pos - total_added as u128;
                let val = ((remaining - 1) % m as u128) as usize + 1;
                println!("{}", val);
            }
        }
    }
}

Submission Info

Submission Time
Task E - A += v
User memoka
Language Rust (rustc 1.89.0)
Score 0
Code Size 2158 Byte
Status WA
Exec Time 984 ms
Memory > 1048576 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 475
Status
AC × 2
AC × 7
WA × 17
MLE × 10
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 01_handmade_10.txt, 01_handmade_11.txt, 01_handmade_12.txt, 01_handmade_13.txt, 01_handmade_14.txt, 01_handmade_15.txt, 01_handmade_16.txt, 01_handmade_17.txt, 01_handmade_18.txt, 01_handmade_19.txt, 01_handmade_20.txt, 01_handmade_21.txt, 01_handmade_22.txt, 01_handmade_23.txt, 01_handmade_24.txt, 01_handmade_25.txt, 01_handmade_26.txt, 01_handmade_27.txt, 01_handmade_28.txt, 01_handmade_29.txt, 01_handmade_30.txt, 01_handmade_31.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 0 ms 1828 KiB
00_sample_01.txt AC 0 ms 2132 KiB
01_handmade_00.txt AC 76 ms 5044 KiB
01_handmade_01.txt MLE 984 ms > 1048576 KiB
01_handmade_02.txt WA 106 ms 5040 KiB
01_handmade_03.txt WA 98 ms 38032 KiB
01_handmade_04.txt WA 130 ms 57792 KiB
01_handmade_05.txt WA 131 ms 65164 KiB
01_handmade_06.txt WA 137 ms 73252 KiB
01_handmade_07.txt WA 133 ms 70564 KiB
01_handmade_08.txt WA 143 ms 80196 KiB
01_handmade_09.txt WA 123 ms 63392 KiB
01_handmade_10.txt WA 136 ms 76472 KiB
01_handmade_11.txt WA 98 ms 21356 KiB
01_handmade_12.txt WA 117 ms 38408 KiB
01_handmade_13.txt WA 123 ms 58200 KiB
01_handmade_14.txt WA 143 ms 72132 KiB
01_handmade_15.txt WA 123 ms 57032 KiB
01_handmade_16.txt WA 146 ms 71624 KiB
01_handmade_17.txt WA 132 ms 64436 KiB
01_handmade_18.txt WA 147 ms 71576 KiB
01_handmade_19.txt AC 104 ms 42212 KiB
01_handmade_20.txt AC 104 ms 42252 KiB
01_handmade_21.txt AC 104 ms 42164 KiB
01_handmade_22.txt MLE 929 ms > 1048576 KiB
01_handmade_23.txt MLE 922 ms > 1048576 KiB
01_handmade_24.txt MLE 961 ms > 1048576 KiB
01_handmade_25.txt AC 138 ms 72900 KiB
01_handmade_26.txt MLE 912 ms > 1048576 KiB
01_handmade_27.txt MLE 972 ms > 1048576 KiB
01_handmade_28.txt MLE 914 ms > 1048576 KiB
01_handmade_29.txt MLE 964 ms > 1048576 KiB
01_handmade_30.txt MLE 907 ms > 1048576 KiB
01_handmade_31.txt MLE 900 ms > 1048576 KiB