Submission #68181071


Source Code Expand

use proconio::{fastout, input};
use std::{collections::BTreeMap, mem::swap};

#[fastout]
pub fn main() {
    input!(n: usize, pab: [(usize, usize, usize); n], q: usize, x: [usize; q]);
    let mut map = BTreeMap::<usize, Vec<usize>>::new();
    for i in 0..q {
        map.entry(x[i]).or_default().push(i);
    }
    let mut acc = 0;
    let mut stack = vec![];
    for (p, a, b) in pab {
        while let Some((&key, _)) = map.range(..=p + acc).next() {
            let value = map.remove(&key).unwrap();
            stack.push((key.saturating_sub(acc) + acc + a + b, value));
        }
        while let Some((key, mut value)) = stack.pop() {
            map.entry(key)
                .and_modify(|e| {
                    if e.len() < value.len() {
                        swap(e, &mut value);
                    }
                    e.extend(&value);
                })
                .or_insert_with(|| value);
        }
        acc += b;
    }
    let mut ans = vec![0; q];
    for (key, value) in map {
        for i in value {
            ans[i] = key.saturating_sub(acc);
        }
    }
    for ans in ans {
        println!("{ans}");
    }
}

Submission Info

Submission Time
Task D - Takahashi's Expectation
User HBit
Language Rust (rustc 1.70.0)
Score 425
Code Size 1197 Byte
Status AC
Exec Time 502 ms
Memory 67384 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 30
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 2112 KiB
00_sample_01.txt AC 1 ms 2032 KiB
00_sample_02.txt AC 1 ms 2000 KiB
01_random_03.txt AC 273 ms 67356 KiB
01_random_04.txt AC 260 ms 67256 KiB
01_random_05.txt AC 266 ms 67288 KiB
01_random_06.txt AC 268 ms 67268 KiB
01_random_07.txt AC 269 ms 67332 KiB
01_random_08.txt AC 266 ms 67296 KiB
01_random_09.txt AC 260 ms 67384 KiB
01_random_10.txt AC 262 ms 67344 KiB
01_random_11.txt AC 263 ms 67372 KiB
01_random_12.txt AC 257 ms 67292 KiB
01_random_13.txt AC 251 ms 67228 KiB
01_random_14.txt AC 238 ms 67336 KiB
01_random_15.txt AC 253 ms 67272 KiB
01_random_16.txt AC 63 ms 21332 KiB
01_random_17.txt AC 81 ms 27680 KiB
01_random_18.txt AC 232 ms 62780 KiB
01_random_19.txt AC 30 ms 12928 KiB
01_random_20.txt AC 42 ms 16760 KiB
01_random_21.txt AC 219 ms 64232 KiB
01_random_22.txt AC 244 ms 66744 KiB
01_random_23.txt AC 115 ms 36840 KiB
01_random_24.txt AC 247 ms 67272 KiB
01_random_25.txt AC 234 ms 67324 KiB
01_random_26.txt AC 239 ms 67232 KiB
01_random_27.txt AC 502 ms 67348 KiB
01_random_28.txt AC 250 ms 67276 KiB
01_random_29.txt AC 242 ms 67312 KiB