Submission #62349028


Source Code Expand

use std::cmp::Reverse;
use std::collections::BinaryHeap;
use std::iter::Rev;
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input!{
        n: usize,
        w: usize,
        v: [(Usize1, Usize1); n],
        q: usize,
        queries: [(usize, Usize1); q],
    }

    let mut g = vec![BinaryHeap::new(); w];
    for (i, &(x, y)) in v.iter().enumerate() {
        g[x].push(Reverse((y, i)));
    }

    let mut kieru_jikan = vec![None; n];

    'lp: loop {
        let mut mh = 0;
        let mut list = vec![];
        for i in 0..w {
            if let Some(Reverse((y, p))) = g[i].pop() {
                list.push(p);
                mh = mh.max(y);
            } else {
                break 'lp;
            }
        }
        let t = mh+1;
        for i in list {
            kieru_jikan[i] = Some(t);
        }
    }
    let ans = queries.iter().map(|(t, a)| if let Some(tt) = kieru_jikan[*a] {
            if tt <= *t {
                "No"
            } else {
                "Yes"
            }
        } else {
            "Yes"
        }
    ).join("\n");
    println!("{ans}");

}

pub trait Debuggable {
    fn debug_string(&self) -> String;
}

impl<T: std::fmt::Debug + std::fmt::Display> Debuggable for Vec<T> {
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        use std::iter::repeat;
        if let Some(max_size) = self.iter()
            .enumerate()
            .map(|(i, x)| (format!("{:?}", x).len()).max(format!("{:?}", i).len()))
            .max() {
                let mut idx = String::from("idx |");   
                let mut val = String::from("val |");   
                for (i, xi) in self.iter().enumerate() {
                    idx.push_str(
                        &format!(" {:>w$} |", i, w=max_size)
                    );
                    val.push_str(
                        &format!(" {:>w$} |", xi, w=max_size)
                    );
                }

                format!("{}\n{}\n{}\n", idx, repeat('-').take(idx.len()).join(""), val)
            } else {
                format!("idx | \nval |\n")
            }
    }
}

impl<T: std::fmt::Debug + std::fmt::Display> Debuggable for std::collections::BTreeSet<T> {
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        format!("{{ {} }}", self.iter().join(", "))
    }
}

impl<T, U> Debuggable for std::collections::BTreeMap<T, U> 
where T: std::fmt::Debug + std::fmt::Display, U: std::fmt::Debug + std::fmt::Display
{
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        format!(
            "{{\n{}\n }}", self.iter()
                .map(|(k, v)| format!("{k} -> {v}, "))
                .join("\n")
        )
    }
}

// lg! マクロの定義
#[macro_export]
macro_rules! lg {
    ($val:expr) => {
        #[cfg(feature = "local")]
        {
            {
                use Debuggable;
                let val = &$val;
                eprintln!(
                    "[{}:{}] {} = \n{}",
                    file!(),
                    line!(),
                    stringify!($val),
                    val.debug_string()
                );
                val
            }
        }
    }
}
    

Submission Info

Submission Time
Task D - Gravity
User ardRiriy
Language Rust (rustc 1.70.0)
Score 400
Code Size 3393 Byte
Status AC
Exec Time 47 ms
Memory 26136 KiB

Compile Error

warning: unused import: `std::iter::Rev`
 --> src/main.rs:3:5
  |
3 | use std::iter::Rev;
  |     ^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: the item `Itertools` is imported redundantly
  --> src/main.rs:61:13
   |
5  | use itertools::Itertools;
   |     -------------------- the item `Itertools` is already imported here
...
61 |         use itertools::Itertools;
   |             ^^^^^^^^^^^^^^^^^^^^

warning: the item `Itertools` is imported redundantly
  --> src/main.rs:87:13
   |
5  | use itertools::Itertools;
   |     -------------------- the item `Itertools` is already imported here
...
87 |         use itertools::Itertools;
   |             ^^^^^^^^^^^^^^^^^^^^

warning: the item `Itertools` is imported redundantly
  --> src/main.rs:96:13
   |
5  | use itertools::Itertools;
   |     -------------------- the item `Itertools` is already imported here
...
96 |         use itertools::Itertools;
   |             ^^^^^^^^^^^^^^^^^^^^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 28
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 1864 KiB
00_sample_02.txt AC 0 ms 1864 KiB
01_test_01.txt AC 15 ms 8160 KiB
01_test_02.txt AC 47 ms 19840 KiB
01_test_03.txt AC 31 ms 14336 KiB
01_test_04.txt AC 44 ms 19688 KiB
01_test_05.txt AC 28 ms 13452 KiB
01_test_06.txt AC 40 ms 20296 KiB
01_test_07.txt AC 11 ms 7360 KiB
01_test_08.txt AC 42 ms 20084 KiB
01_test_09.txt AC 35 ms 15980 KiB
01_test_10.txt AC 38 ms 20568 KiB
01_test_11.txt AC 23 ms 15540 KiB
01_test_12.txt AC 46 ms 19932 KiB
01_test_13.txt AC 24 ms 12856 KiB
01_test_14.txt AC 41 ms 20556 KiB
01_test_15.txt AC 16 ms 10636 KiB
01_test_16.txt AC 33 ms 24868 KiB
01_test_17.txt AC 13 ms 8088 KiB
01_test_18.txt AC 28 ms 19012 KiB
01_test_19.txt AC 4 ms 3608 KiB
01_test_20.txt AC 29 ms 19664 KiB
01_test_21.txt AC 33 ms 15536 KiB
01_test_22.txt AC 42 ms 19052 KiB
01_test_23.txt AC 30 ms 15932 KiB
01_test_24.txt AC 37 ms 21532 KiB
01_test_25.txt AC 25 ms 20748 KiB
01_test_26.txt AC 32 ms 26136 KiB