QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#804216#9873. Last Chance: Threads of Despairucup-team296#AC ✓83ms11396kbRust27.4kb2024-12-07 21:02:502024-12-07 21:02:57

Judging History

你现在查看的是最新测评结果

  • [2024-12-07 21:02:57]
  • 评测
  • 测评结果:AC
  • 用时:83ms
  • 内存:11396kb
  • [2024-12-07 21:02:50]
  • 提交

answer

// https://contest.ucup.ac/contest/1871/problem/9873
pub mod solution {
//{"name":"L. Last Chance: Threads of Despair","group":"Universal Cup - The 3rd Universal Cup. Stage 20: Kunming","url":"https://contest.ucup.ac/contest/1871/problem/9873","interactive":false,"timeLimit":1000,"tests":[{"input":"3\n3 2\n1 1 4\n2 6\n3 2\n1 1 4\n2 7\n2 1\n100 100\n2\n","output":"Yes\nNo\nYes\n"},{"input":"3\n7 1\n1 1 1 1 1 1 1\n9\n5 2\n3 4 5 6 7\n1 6\n5 3\n3 4 5 6 7\n1 5 7\n","output":"No\nNo\nYes\n"}],"testType":"single","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"LLastChanceThreadsOfDespair"}}}

use crate::algo_lib::collections::vec_ext::sorted::Sorted;
use crate::algo_lib::io::input::Input;
use crate::algo_lib::io::output::BoolOutput;
use crate::algo_lib::io::output::Output;
use crate::algo_lib::misc::recursive_function::Callable4;
use crate::algo_lib::misc::test_type::TaskType;

use crate::algo_lib::misc::test_type::TestType;
use crate::algo_lib::numbers::num_traits::bit_ops::BitOps;

type PreCalc = ();

fn solve(input: &mut Input, out: &mut Output, _test_case: usize, _data: &mut PreCalc) {
    let n = input.read_size();
    let m = input.read_size();
    let mut h0 = input.read_size_vec(n).sorted();
    let mut h1 = input.read_size_vec(m).sorted();

    let mut level = 0;
    let mut shots = if h0[0] == 1 { 1 } else { 0 };
    let mut j = 0;
    let mut k = 0;
    for i in 0..n {
        if h0[i] != 1 {
            shots += 1;
        }
        h0[i] -= 1;
    }
    loop {
        if j < m && h1[j] <= level {
            j += 1;
            level += 1;
        } else if k < n && h0[k] <= level {
            k += 1;
            level += 1;
        } else {
            break;
        }
    }
    while j < m {
        if shots == 0 {
            out.print_line(false);
            return;
        }
        h1[j] -= 1;
        shots -= 1;
        loop {
            if j < m && h1[j] <= level {
                j += 1;
                level += 1;
            } else if k < n && h0[k] <= level {
                k += 1;
                level += 1;
            } else {
                break;
            }
        }
    }
    out.print_line(true);
}

pub static TEST_TYPE: TestType = TestType::MultiNumber;
pub static TASK_TYPE: TaskType = TaskType::Classic;

pub(crate) fn run(mut input: Input, mut output: Output) -> bool {
    let mut pre_calc = ();
    output.set_bool_output(BoolOutput::YesNo);

    match TEST_TYPE {
        TestType::Single => solve(&mut input, &mut output, 1, &mut pre_calc),
        TestType::MultiNumber => {
            let t = input.read();
            for i in 1..=t {
                solve(&mut input, &mut output, i, &mut pre_calc);
            }
        }
        TestType::MultiEof => {
            let mut i = 1;
            while input.peek().is_some() {
                solve(&mut input, &mut output, i, &mut pre_calc);
                i += 1;
            }
        }
    }
    output.flush();
    match TASK_TYPE {
        TaskType::Classic => input.is_empty(),
        TaskType::Interactive => true,
    }
}

}
pub mod algo_lib {
#![allow(clippy::too_many_arguments)]
#![allow(clippy::type_complexity)]
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::legacy_numeric_constants)]

pub mod collections {
pub mod vec_ext {
pub mod default {
pub fn default_vec<T: Default>(len: usize) -> Vec<T> {
    let mut v = Vec::with_capacity(len);
    for _ in 0..len {
        v.push(T::default());
    }
    v
}
}
pub mod sorted {
pub trait Sorted {
    fn sorted(self) -> Self;
}

impl<T: Ord> Sorted for Vec<T> {
    fn sorted(mut self) -> Self {
        self.sort();
        self
    }
}
}
}
}
pub mod io {
pub mod input {
use crate::algo_lib::collections::vec_ext::default::default_vec;
use std::io::Read;
use std::mem::MaybeUninit;

pub struct Input<'s> {
    input: &'s mut (dyn Read + Send),
    buf: Vec<u8>,
    at: usize,
    buf_read: usize,
}

macro_rules! read_impl {
    ($t: ty, $read_name: ident, $read_vec_name: ident) => {
        pub fn $read_name(&mut self) -> $t {
            self.read()
        }

        pub fn $read_vec_name(&mut self, len: usize) -> Vec<$t> {
            self.read_vec(len)
        }
    };

    ($t: ty, $read_name: ident, $read_vec_name: ident, $read_pair_vec_name: ident) => {
        read_impl!($t, $read_name, $read_vec_name);

        pub fn $read_pair_vec_name(&mut self, len: usize) -> Vec<($t, $t)> {
            self.read_vec(len)
        }
    };
}

impl<'s> Input<'s> {
    const DEFAULT_BUF_SIZE: usize = 4096;

    pub fn new(input: &'s mut (dyn Read + Send)) -> Self {
        Self {
            input,
            buf: default_vec(Self::DEFAULT_BUF_SIZE),
            at: 0,
            buf_read: 0,
        }
    }

    pub fn new_with_size(input: &'s mut (dyn Read + Send), buf_size: usize) -> Self {
        Self {
            input,
            buf: default_vec(buf_size),
            at: 0,
            buf_read: 0,
        }
    }

    pub fn get(&mut self) -> Option<u8> {
        if self.refill_buffer() {
            let res = self.buf[self.at];
            self.at += 1;
            if res == b'\r' {
                if self.refill_buffer() && self.buf[self.at] == b'\n' {
                    self.at += 1;
                }
                return Some(b'\n');
            }
            Some(res)
        } else {
            None
        }
    }

    pub fn peek(&mut self) -> Option<u8> {
        if self.refill_buffer() {
            let res = self.buf[self.at];
            Some(if res == b'\r' { b'\n' } else { res })
        } else {
            None
        }
    }

    pub fn skip_whitespace(&mut self) {
        while let Some(b) = self.peek() {
            if !b.is_ascii_whitespace() {
                return;
            }
            self.get();
        }
    }

    pub fn next_token(&mut self) -> Option<Vec<u8>> {
        self.skip_whitespace();
        let mut res = Vec::new();
        while let Some(c) = self.get() {
            if c.is_ascii_whitespace() {
                break;
            }
            res.push(c);
        }
        if res.is_empty() {
            None
        } else {
            Some(res)
        }
    }

    //noinspection RsSelfConvention
    pub fn is_exhausted(&mut self) -> bool {
        self.peek().is_none()
    }

    //noinspection RsSelfConvention
    pub fn is_empty(&mut self) -> bool {
        self.skip_whitespace();
        self.is_exhausted()
    }

    pub fn read<T: Readable>(&mut self) -> T {
        T::read(self)
    }

    pub fn read_vec<T: Readable>(&mut self, size: usize) -> Vec<T> {
        let mut res = Vec::with_capacity(size);
        for _ in 0..size {
            res.push(self.read());
        }
        res
    }

    pub fn read_char(&mut self) -> u8 {
        self.skip_whitespace();
        self.get().unwrap()
    }

    read_impl!(u32, read_unsigned, read_unsigned_vec);
    read_impl!(u64, read_u64, read_u64_vec);
    read_impl!(usize, read_size, read_size_vec, read_size_pair_vec);
    read_impl!(i32, read_int, read_int_vec, read_int_pair_vec);
    read_impl!(i64, read_long, read_long_vec, read_long_pair_vec);
    read_impl!(i128, read_i128, read_i128_vec);

    fn refill_buffer(&mut self) -> bool {
        if self.at == self.buf_read {
            self.at = 0;
            self.buf_read = self.input.read(&mut self.buf).unwrap();
            self.buf_read != 0
        } else {
            true
        }
    }
}

pub trait Readable {
    fn read(input: &mut Input) -> Self;
}

impl Readable for u8 {
    fn read(input: &mut Input) -> Self {
        input.read_char()
    }
}

impl<T: Readable> Readable for Vec<T> {
    fn read(input: &mut Input) -> Self {
        let size = input.read();
        input.read_vec(size)
    }
}

impl<T: Readable, const SIZE: usize> Readable for [T; SIZE] {
    fn read(input: &mut Input) -> Self {
        unsafe {
            let mut res = MaybeUninit::<[T; SIZE]>::uninit();
            for i in 0..SIZE {
                let ptr: *mut T = (*res.as_mut_ptr()).as_mut_ptr();
                ptr.add(i).write(input.read::<T>());
            }
            res.assume_init()
        }
    }
}

macro_rules! read_integer {
    ($($t:ident)+) => {$(
        impl Readable for $t {
            fn read(input: &mut Input) -> Self {
                input.skip_whitespace();
                let mut c = input.get().unwrap();
                let sgn = match c {
                    b'-' => {
                        c = input.get().unwrap();
                        true
                    }
                    b'+' => {
                        c = input.get().unwrap();
                        false
                    }
                    _ => false,
                };
                let mut res = 0;
                loop {
                    assert!(c.is_ascii_digit());
                    res *= 10;
                    let d = (c - b'0') as $t;
                    if sgn {
                        res -= d;
                    } else {
                        res += d;
                    }
                    match input.get() {
                        None => break,
                        Some(ch) => {
                            if ch.is_ascii_whitespace() {
                                break;
                            } else {
                                c = ch;
                            }
                        }
                    }
                }
                res
            }
        }
    )+};
}

read_integer!(i8 i16 i32 i64 i128 isize u16 u32 u64 u128 usize);

macro_rules! tuple_readable {
    ($($name:ident)+) => {
        impl<$($name: Readable), +> Readable for ($($name,)+) {
            fn read(input: &mut Input) -> Self {
                ($($name::read(input),)+)
            }
        }
    }
}

tuple_readable! {T}
tuple_readable! {T U}
tuple_readable! {T U V}
tuple_readable! {T U V X}
tuple_readable! {T U V X Y}
tuple_readable! {T U V X Y Z}
tuple_readable! {T U V X Y Z A}
tuple_readable! {T U V X Y Z A B}
tuple_readable! {T U V X Y Z A B C}
tuple_readable! {T U V X Y Z A B C D}
tuple_readable! {T U V X Y Z A B C D E}
tuple_readable! {T U V X Y Z A B C D E F}

impl Read for Input<'_> {
    fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
        if self.at == self.buf_read {
            self.input.read(buf)
        } else {
            let mut i = 0;
            while i < buf.len() && self.at < self.buf_read {
                buf[i] = self.buf[self.at];
                i += 1;
                self.at += 1;
            }
            Ok(i)
        }
    }
}
}
pub mod output {
use crate::algo_lib::collections::vec_ext::default::default_vec;
use std::cmp::Reverse;
use std::io::stderr;
use std::io::Stderr;
use std::io::Write;

#[derive(Copy, Clone)]
pub enum BoolOutput {
    YesNo,
    YesNoCaps,
    PossibleImpossible,
    Custom(&'static str, &'static str),
}

impl BoolOutput {
    pub fn output(&self, output: &mut Output, val: bool) {
        (if val { self.yes() } else { self.no() }).write(output);
    }

    fn yes(&self) -> &str {
        match self {
            BoolOutput::YesNo => "Yes",
            BoolOutput::YesNoCaps => "YES",
            BoolOutput::PossibleImpossible => "Possible",
            BoolOutput::Custom(yes, _) => yes,
        }
    }

    fn no(&self) -> &str {
        match self {
            BoolOutput::YesNo => "No",
            BoolOutput::YesNoCaps => "NO",
            BoolOutput::PossibleImpossible => "Impossible",
            BoolOutput::Custom(_, no) => no,
        }
    }
}

pub struct Output<'s> {
    output: &'s mut dyn Write,
    buf: Vec<u8>,
    at: usize,
    auto_flush: bool,
    bool_output: BoolOutput,
    precision: Option<usize>,
}

impl<'s> Output<'s> {
    const DEFAULT_BUF_SIZE: usize = 4096;

    pub fn new(output: &'s mut dyn Write) -> Self {
        Self {
            output,
            buf: default_vec(Self::DEFAULT_BUF_SIZE),
            at: 0,
            auto_flush: false,
            bool_output: BoolOutput::YesNoCaps,
            precision: None,
        }
    }

    pub fn new_with_auto_flush(output: &'s mut dyn Write) -> Self {
        Self {
            output,
            buf: default_vec(Self::DEFAULT_BUF_SIZE),
            at: 0,
            auto_flush: true,
            bool_output: BoolOutput::YesNoCaps,
            precision: None,
        }
    }

    pub fn flush(&mut self) {
        if self.at != 0 {
            self.output.write_all(&self.buf[..self.at]).unwrap();
            self.output.flush().unwrap();
            self.at = 0;
        }
    }

    pub fn print<T: Writable>(&mut self, s: T) {
        s.write(self);
        self.maybe_flush();
    }

    pub fn print_line<T: Writable>(&mut self, s: T) {
        self.print(s);
        self.put(b'\n');
        self.maybe_flush();
    }

    pub fn put(&mut self, b: u8) {
        self.buf[self.at] = b;
        self.at += 1;
        if self.at == self.buf.len() {
            self.flush();
        }
    }

    pub fn maybe_flush(&mut self) {
        if self.auto_flush {
            self.flush();
        }
    }

    pub fn print_per_line<T: Writable>(&mut self, arg: &[T]) {
        self.print_per_line_iter(arg.iter());
    }

    pub fn print_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
        let mut first = true;
        for e in iter {
            if first {
                first = false;
            } else {
                self.put(b' ');
            }
            e.write(self);
        }
    }

    pub fn print_line_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
        self.print_iter(iter);
        self.put(b'\n');
    }

    pub fn print_per_line_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
        for e in iter {
            e.write(self);
            self.put(b'\n');
        }
    }

    pub fn set_bool_output(&mut self, bool_output: BoolOutput) {
        self.bool_output = bool_output;
    }
    pub fn set_precision(&mut self, precision: usize) {
        self.precision = Some(precision);
    }
    pub fn reset_precision(&mut self) {
        self.precision = None;
    }
    pub fn get_precision(&self) -> Option<usize> {
        self.precision
    }
}

impl Write for Output<'_> {
    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
        let mut start = 0usize;
        let mut rem = buf.len();
        while rem > 0 {
            let len = (self.buf.len() - self.at).min(rem);
            self.buf[self.at..self.at + len].copy_from_slice(&buf[start..start + len]);
            self.at += len;
            if self.at == self.buf.len() {
                self.flush();
            }
            start += len;
            rem -= len;
        }
        self.maybe_flush();
        Ok(buf.len())
    }

    fn flush(&mut self) -> std::io::Result<()> {
        self.flush();
        Ok(())
    }
}

pub trait Writable {
    fn write(&self, output: &mut Output);
}

impl Writable for &str {
    fn write(&self, output: &mut Output) {
        output.write_all(self.as_bytes()).unwrap();
    }
}

impl Writable for String {
    fn write(&self, output: &mut Output) {
        output.write_all(self.as_bytes()).unwrap();
    }
}

impl Writable for char {
    fn write(&self, output: &mut Output) {
        output.put(*self as u8);
    }
}

impl Writable for u8 {
    fn write(&self, output: &mut Output) {
        output.put(*self);
    }
}

impl<T: Writable> Writable for [T] {
    fn write(&self, output: &mut Output) {
        output.print_iter(self.iter());
    }
}

impl<T: Writable, const N: usize> Writable for [T; N] {
    fn write(&self, output: &mut Output) {
        output.print_iter(self.iter());
    }
}

impl<T: Writable + ?Sized> Writable for &T {
    fn write(&self, output: &mut Output) {
        T::write(self, output)
    }
}

impl<T: Writable> Writable for Vec<T> {
    fn write(&self, output: &mut Output) {
        self.as_slice().write(output);
    }
}

impl Writable for () {
    fn write(&self, _output: &mut Output) {}
}

macro_rules! write_to_string {
    ($($t:ident)+) => {$(
        impl Writable for $t {
            fn write(&self, output: &mut Output) {
                self.to_string().write(output);
            }
        }
    )+};
}

write_to_string!(u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize);

macro_rules! tuple_writable {
    ($name0:ident $($name:ident: $id:tt )*) => {
        impl<$name0: Writable, $($name: Writable,)*> Writable for ($name0, $($name,)*) {
            fn write(&self, out: &mut Output) {
                self.0.write(out);
                $(
                out.put(b' ');
                self.$id.write(out);
                )*
            }
        }
    }
}

tuple_writable! {T}
tuple_writable! {T U:1}
tuple_writable! {T U:1 V:2}
tuple_writable! {T U:1 V:2 X:3}
tuple_writable! {T U:1 V:2 X:3 Y:4}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5 A:6}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5 A:6 B:7}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5 A:6 B:7 C:8}

impl<T: Writable> Writable for Option<T> {
    fn write(&self, output: &mut Output) {
        match self {
            None => (-1).write(output),
            Some(t) => t.write(output),
        }
    }
}

impl Writable for bool {
    fn write(&self, output: &mut Output) {
        let bool_output = output.bool_output;
        bool_output.output(output, *self)
    }
}

impl<T: Writable> Writable for Reverse<T> {
    fn write(&self, output: &mut Output) {
        self.0.write(output);
    }
}

static mut ERR: Option<Stderr> = None;

pub fn err() -> Output<'static> {
    unsafe {
        if ERR.is_none() {
            ERR = Some(stderr());
        }
        Output::new_with_auto_flush(ERR.as_mut().unwrap())
    }
}
}
}
pub mod misc {
pub mod recursive_function {
use std::marker::PhantomData;

macro_rules! recursive_function {
    ($name: ident, $trait: ident, ($($type: ident $arg: ident,)*)) => {
        pub trait $trait<$($type, )*Output> {
            fn call(&mut self, $($arg: $type,)*) -> Output;
        }

        pub struct $name<F, $($type, )*Output>
        where
            F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,
        {
            f: std::cell::UnsafeCell<F>,
            $($arg: PhantomData<$type>,
            )*
            phantom_output: PhantomData<Output>,
        }

        impl<F, $($type, )*Output> $name<F, $($type, )*Output>
        where
            F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,
        {
            pub fn new(f: F) -> Self {
                Self {
                    f: std::cell::UnsafeCell::new(f),
                    $($arg: Default::default(),
                    )*
                    phantom_output: Default::default(),
                }
            }
        }

        impl<F, $($type, )*Output> $trait<$($type, )*Output> for $name<F, $($type, )*Output>
        where
            F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,
        {
            fn call(&mut self, $($arg: $type,)*) -> Output {
                unsafe { (*self.f.get())(self, $($arg, )*) }
            }
        }
    }
}

recursive_function!(RecursiveFunction0, Callable0, ());
recursive_function!(RecursiveFunction, Callable, (Arg arg,));
recursive_function!(RecursiveFunction2, Callable2, (Arg1 arg1, Arg2 arg2,));
recursive_function!(RecursiveFunction3, Callable3, (Arg1 arg1, Arg2 arg2, Arg3 arg3,));
recursive_function!(RecursiveFunction4, Callable4, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4,));
recursive_function!(RecursiveFunction5, Callable5, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5,));
recursive_function!(RecursiveFunction6, Callable6, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6,));
recursive_function!(RecursiveFunction7, Callable7, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7,));
recursive_function!(RecursiveFunction8, Callable8, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7, Arg8 arg8,));
recursive_function!(RecursiveFunction9, Callable9, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7, Arg8 arg8, Arg9 arg9,));
}
pub mod test_type {
pub enum TestType {
    Single,
    MultiNumber,
    MultiEof,
}

pub enum TaskType {
    Classic,
    Interactive,
}
}
}
pub mod numbers {
pub mod num_traits {
pub mod algebra {
use crate::algo_lib::numbers::num_traits::invertible::Invertible;
use std::ops::Add;
use std::ops::AddAssign;
use std::ops::Div;
use std::ops::DivAssign;
use std::ops::Mul;
use std::ops::MulAssign;
use std::ops::Neg;
use std::ops::Rem;
use std::ops::RemAssign;
use std::ops::Sub;
use std::ops::SubAssign;

pub trait Zero {
    fn zero() -> Self;
}

pub trait One {
    fn one() -> Self;
}

pub trait AdditionMonoid: Add<Output = Self> + AddAssign + Zero + Eq + Sized {}

impl<T: Add<Output = Self> + AddAssign + Zero + Eq> AdditionMonoid for T {}

pub trait AdditionMonoidWithSub: AdditionMonoid + Sub<Output = Self> + SubAssign {}

impl<T: AdditionMonoid + Sub<Output = Self> + SubAssign> AdditionMonoidWithSub for T {}

pub trait AdditionGroup: AdditionMonoidWithSub + Neg<Output = Self> {}

impl<T: AdditionMonoidWithSub + Neg<Output = Self>> AdditionGroup for T {}

pub trait MultiplicationMonoid: Mul<Output = Self> + MulAssign + One + Eq + Sized {}

impl<T: Mul<Output = Self> + MulAssign + One + Eq> MultiplicationMonoid for T {}

pub trait IntegerMultiplicationMonoid:
    MultiplicationMonoid + Div<Output = Self> + Rem<Output = Self> + DivAssign + RemAssign
{
}

impl<T: MultiplicationMonoid + Div<Output = Self> + Rem<Output = Self> + DivAssign + RemAssign>
    IntegerMultiplicationMonoid for T
{
}

pub trait MultiplicationGroup:
    MultiplicationMonoid + Div<Output = Self> + DivAssign + Invertible<Output = Self>
{
}

impl<T: MultiplicationMonoid + Div<Output = Self> + DivAssign + Invertible<Output = Self>>
    MultiplicationGroup for T
{
}

pub trait SemiRing: AdditionMonoid + MultiplicationMonoid {}

impl<T: AdditionMonoid + MultiplicationMonoid> SemiRing for T {}

pub trait SemiRingWithSub: AdditionMonoidWithSub + SemiRing {}

impl<T: AdditionMonoidWithSub + SemiRing> SemiRingWithSub for T {}

pub trait Ring: SemiRing + AdditionGroup {}

impl<T: SemiRing + AdditionGroup> Ring for T {}

pub trait IntegerSemiRing: SemiRing + IntegerMultiplicationMonoid {}

impl<T: SemiRing + IntegerMultiplicationMonoid> IntegerSemiRing for T {}

pub trait IntegerSemiRingWithSub: SemiRingWithSub + IntegerSemiRing {}

impl<T: SemiRingWithSub + IntegerSemiRing> IntegerSemiRingWithSub for T {}

pub trait IntegerRing: IntegerSemiRing + Ring {}

impl<T: IntegerSemiRing + Ring> IntegerRing for T {}

pub trait Field: Ring + MultiplicationGroup {}

impl<T: Ring + MultiplicationGroup> Field for T {}

macro_rules! zero_one_integer_impl {
    ($($t: ident)+) => {$(
        impl Zero for $t {
            fn zero() -> Self {
                0
            }
        }

        impl One for $t {
            fn one() -> Self {
                1
            }
        }
    )+};
}

zero_one_integer_impl!(i128 i64 i32 i16 i8 isize u128 u64 u32 u16 u8 usize);
}
pub mod bit_ops {
use crate::algo_lib::numbers::num_traits::algebra::One;
use crate::algo_lib::numbers::num_traits::algebra::Zero;
use std::ops::BitAnd;
use std::ops::BitAndAssign;
use std::ops::BitOr;
use std::ops::BitOrAssign;
use std::ops::BitXor;
use std::ops::BitXorAssign;
use std::ops::Not;
use std::ops::RangeInclusive;
use std::ops::Shl;
use std::ops::Sub;
use std::ops::ShlAssign;
use std::ops::Shr;
use std::ops::ShrAssign;

pub trait BitOps:
    Copy
    + BitAnd<Output = Self>
    + BitAndAssign
    + BitOr<Output = Self>
    + BitOrAssign
    + BitXor<Output = Self>
    + BitXorAssign
    + Not<Output = Self>
    + Shl<usize, Output = Self>
    + ShlAssign<usize>
    + Shr<usize, Output = Self>
    + ShrAssign<usize>
    + Zero
    + One
    + PartialEq
{
    #[inline]
    fn bit(at: usize) -> Self {
        Self::one() << at
    }

    #[inline]
    fn is_set(&self, at: usize) -> bool {
        (*self >> at & Self::one()) == Self::one()
    }

    #[inline]
    fn set_bit(&mut self, at: usize) {
        *self |= Self::bit(at)
    }

    #[inline]
    fn unset_bit(&mut self, at: usize) {
        *self &= !Self::bit(at)
    }

    #[must_use]
    #[inline]
    fn with_bit(mut self, at: usize) -> Self {
        self.set_bit(at);
        self
    }

    #[must_use]
    #[inline]
    fn without_bit(mut self, at: usize) -> Self {
        self.unset_bit(at);
        self
    }

    #[inline]
    fn flip_bit(&mut self, at: usize) {
        *self ^= Self::bit(at)
    }

    #[must_use]
    #[inline]
    fn flipped_bit(mut self, at: usize) -> Self {
        self.flip_bit(at);
        self
    }

    fn all_bits(n: usize) -> Self {
        let mut res = Self::zero();
        for i in 0..n {
            res.set_bit(i);
        }
        res
    }

    fn iter_all(n: usize) -> RangeInclusive<Self> {
        Self::zero()..=Self::all_bits(n)
    }
}

pub struct BitIter<T> {
    cur: T,
    all: T,
    ended: bool,
}

impl<T: Copy> BitIter<T> {
    pub fn new(all: T) -> Self {
        Self {
            cur: all,
            all,
            ended: false,
        }
    }
}

impl<T: BitOps + Sub<Output = T>> Iterator for BitIter<T> {
    type Item = T;

    fn next(&mut self) -> Option<Self::Item> {
        if self.ended {
            return None;
        }
        let res = self.cur;
        if self.cur == T::zero() {
            self.ended = true;
        } else {
            self.cur = (self.cur - T::one()) & self.all;
        }
        Some(res)
    }
}

impl<
        T: Copy
            + BitAnd<Output = Self>
            + BitAndAssign
            + BitOr<Output = Self>
            + BitOrAssign
            + BitXor<Output = Self>
            + BitXorAssign
            + Not<Output = Self>
            + Shl<usize, Output = Self>
            + ShlAssign<usize>
            + Shr<usize, Output = Self>
            + ShrAssign<usize>
            + One
            + Zero
            + PartialEq,
    > BitOps for T
{
}

pub trait Bits: BitOps {
    fn bits() -> u32;
}

macro_rules! bits_integer_impl {
    ($($t: ident $bits: expr),+) => {$(
        impl Bits for $t {
            fn bits() -> u32 {
                $bits
            }
        }
    )+};
}

bits_integer_impl!(i128 128, i64 64, i32 32, i16 16, i8 8, isize 64, u128 128, u64 64, u32 32, u16 16, u8 8, usize 64);
}
pub mod invertible {
pub trait Invertible {
    type Output;

    fn inv(&self) -> Option<Self::Output>;
}
}
}
}
}
fn main() {
    let mut sin = std::io::stdin();
    let input = algo_lib::io::input::Input::new(&mut sin);
    let mut stdout = std::io::stdout();
    let output = algo_lib::io::output::Output::new(&mut stdout);
    solution::run(input, output);
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 2256kb

input:

3
3 2
1 1 4
2 6
3 2
1 1 4
2 7
2 1
100 100
2

output:

Yes
No
Yes

result:

ok 3 token(s): yes count is 2, no count is 1

Test #2:

score: 0
Accepted
time: 0ms
memory: 2284kb

input:

3
7 1
1 1 1 1 1 1 1
9
5 2
3 4 5 6 7
1 6
5 3
3 4 5 6 7
1 5 7

output:

No
No
Yes

result:

ok 3 token(s): yes count is 1, no count is 2

Test #3:

score: 0
Accepted
time: 0ms
memory: 2344kb

input:

4
1 1
1
1
1 1
1
2
1 1
2
1
1 1
2
2

output:

Yes
Yes
Yes
No

result:

ok 4 token(s): yes count is 3, no count is 1

Test #4:

score: 0
Accepted
time: 0ms
memory: 2144kb

input:

18
1 2
1
1 1
1 2
1
2 1
1 2
1
1 3
1 2
1
2 2
1 2
1
3 2
1 2
1
3 3
1 2
2
1 1
1 2
2
1 2
1 2
2
1 3
1 2
2
2 2
1 2
2
2 3
1 2
2
3 3
1 2
3
1 1
1 2
3
1 2
1 2
3
1 3
1 2
3
2 2
1 2
3
3 2
1 2
3
3 3

output:

Yes
Yes
Yes
Yes
No
No
Yes
Yes
No
No
No
No
Yes
No
No
No
No
No

result:

ok 18 token(s): yes count is 7, no count is 11

Test #5:

score: 0
Accepted
time: 0ms
memory: 2128kb

input:

18
2 1
1 1
1
2 1
1 1
2
2 1
1 1
3
2 1
1 2
1
2 1
2 1
2
2 1
2 1
3
2 1
1 3
1
2 1
1 3
2
2 1
3 1
3
2 1
2 2
1
2 1
2 2
2
2 1
2 2
3
2 1
2 3
1
2 1
3 2
2
2 1
2 3
3
2 1
3 3
1
2 1
3 3
2
2 1
3 3
3

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
No

result:

ok 18 token(s): yes count is 15, no count is 3

Test #6:

score: 0
Accepted
time: 0ms
memory: 2148kb

input:

525
2 3
1 1
1 1 1
2 3
1 1
1 2 1
2 3
1 1
1 3 1
2 3
1 1
1 4 1
2 3
1 1
5 1 1
2 3
1 1
2 2 1
2 3
1 1
3 1 2
2 3
1 1
1 2 4
2 3
1 1
2 1 5
2 3
1 1
3 3 1
2 3
1 1
4 3 1
2 3
1 1
3 5 1
2 3
1 1
4 4 1
2 3
1 1
4 5 1
2 3
1 1
1 5 5
2 3
1 1
2 2 2
2 3
1 1
2 3 2
2 3
1 1
2 2 4
2 3
1 1
2 5 2
2 3
1 1
3 2 3
2 3
1 1
3 2 4
2 ...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
No
No
No
No
No
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
No
No
No
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

ok 525 token(s): yes count is 202, no count is 323

Test #7:

score: 0
Accepted
time: 0ms
memory: 2160kb

input:

525
3 2
1 1 1
1 1
3 2
1 1 1
2 1
3 2
1 1 1
3 1
3 2
1 1 1
1 4
3 2
1 1 1
1 5
3 2
1 1 1
2 2
3 2
1 1 1
2 3
3 2
1 1 1
4 2
3 2
1 1 1
2 5
3 2
1 1 1
3 3
3 2
1 1 1
4 3
3 2
1 1 1
5 3
3 2
1 1 1
4 4
3 2
1 1 1
5 4
3 2
1 1 1
5 5
3 2
1 1 2
1 1
3 2
2 1 1
2 1
3 2
2 1 1
1 3
3 2
1 2 1
1 4
3 2
1 1 2
5 1
3 2
1 1 2
2 2
3 ...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
No
Yes
Yes
Ye...

result:

ok 525 token(s): yes count is 317, no count is 208

Test #8:

score: 0
Accepted
time: 1ms
memory: 2284kb

input:

3136
3 3
1 1 1
1 1 1
3 3
1 1 1
2 1 1
3 3
1 1 1
3 1 1
3 3
1 1 1
1 1 4
3 3
1 1 1
5 1 1
3 3
1 1 1
1 1 6
3 3
1 1 1
2 1 2
3 3
1 1 1
2 1 3
3 3
1 1 1
1 4 2
3 3
1 1 1
2 5 1
3 3
1 1 1
1 6 2
3 3
1 1 1
3 3 1
3 3
1 1 1
4 1 3
3 3
1 1 1
1 5 3
3 3
1 1 1
1 3 6
3 3
1 1 1
4 1 4
3 3
1 1 1
4 1 5
3 3
1 1 1
4 1 6
3 3
1 1...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
No
No
No
No
No
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes...

result:

ok 3136 token(s): yes count is 1458, no count is 1678

Test #9:

score: 0
Accepted
time: 3ms
memory: 2276kb

input:

17640
3 4
1 1 1
1 1 1 1
3 4
1 1 1
2 1 1 1
3 4
1 1 1
1 1 1 3
3 4
1 1 1
1 1 1 4
3 4
1 1 1
5 1 1 1
3 4
1 1 1
1 6 1 1
3 4
1 1 1
7 1 1 1
3 4
1 1 1
1 1 2 2
3 4
1 1 1
1 2 3 1
3 4
1 1 1
1 4 1 2
3 4
1 1 1
5 1 2 1
3 4
1 1 1
2 1 1 6
3 4
1 1 1
7 1 1 2
3 4
1 1 1
3 3 1 1
3 4
1 1 1
4 1 3 1
3 4
1 1 1
1 1 3 5
3 4
1 ...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
No
N...

result:

ok 17640 token(s): yes count is 6647, no count is 10993

Test #10:

score: 0
Accepted
time: 3ms
memory: 2176kb

input:

17640
4 3
1 1 1 1
1 1 1
4 3
1 1 1 1
1 2 1
4 3
1 1 1 1
3 1 1
4 3
1 1 1 1
1 1 4
4 3
1 1 1 1
1 5 1
4 3
1 1 1 1
6 1 1
4 3
1 1 1 1
1 1 7
4 3
1 1 1 1
1 2 2
4 3
1 1 1 1
3 1 2
4 3
1 1 1 1
2 4 1
4 3
1 1 1 1
1 2 5
4 3
1 1 1 1
1 2 6
4 3
1 1 1 1
7 2 1
4 3
1 1 1 1
1 3 3
4 3
1 1 1 1
4 1 3
4 3
1 1 1 1
5 3 1
4 3
1 ...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
No
N...

result:

ok 17640 token(s): yes count is 8926, no count is 8714

Test #11:

score: 0
Accepted
time: 18ms
memory: 2124kb

input:

95040
3 5
1 1 1
1 1 1 1 1
3 5
1 1 1
2 1 1 1 1
3 5
1 1 1
1 3 1 1 1
3 5
1 1 1
1 1 4 1 1
3 5
1 1 1
1 5 1 1 1
3 5
1 1 1
1 1 6 1 1
3 5
1 1 1
7 1 1 1 1
3 5
1 1 1
1 1 1 8 1
3 5
1 1 1
2 1 2 1 1
3 5
1 1 1
1 1 2 1 3
3 5
1 1 1
1 4 2 1 1
3 5
1 1 1
2 5 1 1 1
3 5
1 1 1
6 1 2 1 1
3 5
1 1 1
1 7 2 1 1
3 5
1 1 1
1 8 ...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

ok 95040 token(s): yes count is 29907, no count is 65133

Test #12:

score: 0
Accepted
time: 15ms
memory: 2132kb

input:

95040
5 3
1 1 1 1 1
1 1 1
5 3
1 1 1 1 1
2 1 1
5 3
1 1 1 1 1
3 1 1
5 3
1 1 1 1 1
4 1 1
5 3
1 1 1 1 1
5 1 1
5 3
1 1 1 1 1
1 6 1
5 3
1 1 1 1 1
1 1 7
5 3
1 1 1 1 1
1 8 1
5 3
1 1 1 1 1
1 2 2
5 3
1 1 1 1 1
1 3 2
5 3
1 1 1 1 1
4 1 2
5 3
1 1 1 1 1
2 5 1
5 3
1 1 1 1 1
6 1 2
5 3
1 1 1 1 1
1 7 2
5 3
1 1 1 1 1
...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

ok 95040 token(s): yes count is 50357, no count is 44683

Test #13:

score: 0
Accepted
time: 21ms
memory: 2148kb

input:

108900
4 4
1 1 1 1
1 1 1 1
4 4
1 1 1 1
1 1 2 1
4 4
1 1 1 1
3 1 1 1
4 4
1 1 1 1
1 1 4 1
4 4
1 1 1 1
1 5 1 1
4 4
1 1 1 1
1 1 6 1
4 4
1 1 1 1
7 1 1 1
4 4
1 1 1 1
1 1 8 1
4 4
1 1 1 1
1 2 1 2
4 4
1 1 1 1
3 1 2 1
4 4
1 1 1 1
2 1 4 1
4 4
1 1 1 1
1 2 5 1
4 4
1 1 1 1
1 2 6 1
4 4
1 1 1 1
7 1 2 1
4 4
1 1 1 1
1...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

ok 108900 token(s): yes count is 46206, no count is 62694

Test #14:

score: 0
Accepted
time: 32ms
memory: 2128kb

input:

50000
10 10
20 6 5 16 10 3 1 17 12 8
20 6 4 17 9 2 2 17 13 8
10 10
17 14 15 4 13 18 3 16 2 11
17 14 14 6 12 17 2 16 2 13
10 10
2 20 12 3 7 17 18 19 8 5
1 20 12 4 6 16 18 19 9 6
10 10
2 11 19 14 1 16 6 4 7 5
2 12 19 13 2 16 5 3 8 5
10 10
17 1 13 14 5 11 8 20 15 18
17 3 12 14 4 11 9 21 14 17
10 10
14 ...

output:

Yes
No
No
Yes
No
Yes
No
No
No
No
No
No
No
Yes
Yes
Yes
No
No
Yes
Yes
No
Yes
No
No
Yes
No
No
No
Yes
No
Yes
No
Yes
Yes
No
No
Yes
Yes
No
No
No
Yes
Yes
No
Yes
Yes
No
Yes
Yes
Yes
No
No
Yes
Yes
No
No
No
No
Yes
No
No
No
Yes
No
No
No
Yes
Yes
No
Yes
Yes
No
Yes
Yes
No
Yes
No
No
Yes
Yes
Yes
Yes
No
No
Yes
No
No
...

result:

ok 50000 token(s): yes count is 19646, no count is 30354

Test #15:

score: 0
Accepted
time: 25ms
memory: 2148kb

input:

33333
12 15
9 7 15 17 13 18 8 14 10 25 11 22
9 6 14 17 15 17 8 13 9 24 13 22 26 1 21
12 15
8 20 15 25 6 24 23 4 26 13 18 5
7 19 16 27 5 23 24 3 25 14 17 4 9 1 16
12 15
26 16 14 8 20 11 1 5 2 15 12 4
26 16 15 8 19 10 1 4 3 14 12 5 9 24 12
12 15
17 13 15 19 4 25 1 22 6 2 27 16
17 13 15 18 3 24 2 23 5 ...

output:

No
No
Yes
No
Yes
Yes
No
No
No
Yes
Yes
No
No
No
No
No
Yes
No
Yes
No
Yes
No
No
Yes
No
Yes
No
Yes
No
Yes
Yes
Yes
No
Yes
Yes
No
Yes
No
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
No
No
No
Yes
No
Yes
Yes
Yes
Yes
No
No
No
Yes
No
No
No
No
No
No
No
Yes
No
Yes
No
No
No
No
Yes
No
No
Yes
No
No
Yes
No...

result:

ok 33333 token(s): yes count is 11692, no count is 21641

Test #16:

score: 0
Accepted
time: 25ms
memory: 2140kb

input:

33333
15 12
21 1 4 15 9 23 5 6 10 19 17 24 3 2 18
22 1 5 15 8 24 5 6 9 20 19 23
15 12
11 3 22 7 21 10 13 16 23 26 9 20 19 4 27
12 5 21 7 23 10 13 15 22 27 10 19
15 12
12 7 20 10 17 4 25 15 11 27 8 14 6 13 18
11 9 20 11 19 3 24 16 10 29 7 14
15 12
2 3 5 24 11 26 19 10 27 14 25 15 20 18 12
3 3 6 24 11...

output:

Yes
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
Yes
No
No
Yes
Yes
No
Yes
No
No
No
No
No
No
Yes
No
No
No
No
No
Yes
No
Yes
No
No
No
Yes
No
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
No
Yes
Yes
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
No
No
No
No
Yes
No
No
Yes
No
Yes
No
No
No
Yes
Yes
No
No
No
No
No
Yes
No
Yes
Ye...

result:

ok 33333 token(s): yes count is 13098, no count is 20235

Test #17:

score: 0
Accepted
time: 39ms
memory: 2108kb

input:

5000
100 100
133 5 137 121 30 141 27 123 178 128 171 21 67 74 175 47 26 82 125 48 65 102 106 89 179 43 60 164 136 46 9 159 111 144 59 198 157 93 28 169 12 186 42 29 183 87 56 8 139 22 154 161 109 101 168 130 17 182 103 147 132 33 129 158 23 195 53 35 138 185 51 114 126 10 57 7 62 99 55 191 176 199 1...

output:

No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
Yes
No
No
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
Yes
Yes
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
Yes
No
No
Yes
Yes
No
No
No
Yes
Yes
No
Yes
Yes
No
No
No
No
No
No
No
N...

result:

ok 5000 token(s): yes count is 1091, no count is 3909

Test #18:

score: 0
Accepted
time: 51ms
memory: 2112kb

input:

500
1000 1000
410 461 57 202 1577 1597 994 944 1488 956 379 380 1486 1780 1244 1921 1794 265 1563 1679 243 65 1079 192 1839 762 1014 206 23 193 1185 1746 822 948 1397 1854 917 645 623 1726 809 1708 1765 1908 761 527 1603 1073 758 46 1592 203 1871 1873 1252 438 808 416 1128 1099 1107 735 151 1959 171...

output:

No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
Yes
No
No
No
No
No
Yes
Yes
No
No
No
No
No
Yes
No
Yes
Yes
No
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
Yes
No
Yes
No
No
No
Yes
No
No
No
No
No
No
...

result:

ok 500 token(s): yes count is 70, no count is 430

Test #19:

score: 0
Accepted
time: 71ms
memory: 3892kb

input:

5
100000 100000
192348 43709 194484 134138 36415 165204 147428 196982 14278 195617 146117 168812 110270 1094 192657 135027 9041 181689 170958 162867 32338 18546 107477 98466 52702 82906 28257 89818 72376 34525 22246 170527 118863 160364 47995 153027 163962 98710 132547 38225 198231 78342 115823 4907...

output:

No
No
No
No
No

result:

ok 5 token(s): yes count is 0, no count is 5

Test #20:

score: 0
Accepted
time: 79ms
memory: 11112kb

input:

1
500000 500000
298323 92801 517022 733075 950589 442461 98931 873034 365485 969370 407317 138461 421780 932696 964828 249894 562117 873629 795988 841659 25700 657972 879460 790648 337233 96409 76314 442433 323234 93538 461415 502833 763238 606519 203793 398485 683063 957433 104205 604635 952026 185...

output:

No

result:

ok NO

Test #21:

score: 0
Accepted
time: 30ms
memory: 2140kb

input:

50000
10 10
12 14 6 7 8 18 9 20 23 2
12 14 6 7 8 18 9 20 23 2
10 10
18 5 10 16 8 7 17 15 2 1
18 5 10 16 8 7 17 15 2 1
10 10
6 10 3 18 19 21 7 15 9 17
6 10 3 18 19 21 7 15 9 17
10 10
6 11 9 20 1 13 2 16 17 4
6 11 9 20 1 13 2 16 17 4
10 10
15 9 14 2 10 22 12 11 23 1
15 9 14 2 10 22 12 11 23 1
10 10
14...

output:

No
Yes
No
Yes
No
No
Yes
Yes
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
N...

result:

ok 50000 token(s): yes count is 5971, no count is 44029

Test #22:

score: 0
Accepted
time: 27ms
memory: 2072kb

input:

33333
12 15
21 2 1 28 26 30 12 22 23 7 18 6
21 2 1 28 26 30 12 22 23 7 18 6 29 11 14
12 15
24 2 28 18 16 22 10 17 27 3 4 20
24 2 28 18 16 22 10 17 27 3 4 20 6 13 7
12 15
26 19 22 8 7 6 3 15 24 18 27 1
26 19 22 8 7 6 3 15 24 18 27 1 29 13 17
12 15
28 8 16 30 18 23 5 2 3 24 4 25
28 8 16 30 18 23 5 2 3...

output:

No
No
No
No
No
No
No
Yes
No
No
Yes
No
Yes
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
Yes
No
No
Yes
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
Yes
No
No
No
No
No
Yes
No
No
No
No
Yes
No
No...

result:

ok 33333 token(s): yes count is 2998, no count is 30335

Test #23:

score: 0
Accepted
time: 28ms
memory: 2232kb

input:

33333
15 12
3 11 17 19 23 9 29 22 14 27 5 26 20 2 6
3 11 17 19 23 9 29 22 14 27 5 26
15 12
25 29 1 22 13 5 24 26 3 9 23 6 4 12 17
25 29 1 22 13 5 24 26 3 9 23 6
15 12
26 16 20 2 6 8 29 7 4 19 27 12 13 28 21
26 16 20 2 6 8 29 7 4 19 27 12
15 12
13 2 4 6 29 28 25 27 15 10 19 16 18 14 5
13 2 4 6 29 28 ...

output:

No
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
Yes
No
No
No
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
No
Yes
Yes
No
No
Yes
No
Yes
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
Yes
No
No
Yes
No
No
N...

result:

ok 33333 token(s): yes count is 4670, no count is 28663

Test #24:

score: 0
Accepted
time: 38ms
memory: 2120kb

input:

5000
100 100
146 117 67 141 42 108 16 118 155 163 81 44 210 150 7 41 137 1 194 162 3 123 110 157 185 176 78 29 18 87 183 15 55 199 189 52 45 131 105 112 6 154 124 143 159 192 158 164 160 57 120 5 32 207 167 24 33 138 39 103 139 106 115 37 66 4 174 172 95 132 21 30 75 208 126 111 86 64 2 190 8 119 49...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
...

result:

ok 5000 token(s): yes count is 69, no count is 4931

Test #25:

score: 0
Accepted
time: 50ms
memory: 2252kb

input:

500
1000 1000
304 1098 1190 308 1439 1576 1127 1618 1697 1859 539 879 1361 1989 184 1645 1324 1172 695 476 936 133 437 479 1670 1852 1327 50 1402 259 958 1101 1057 1148 1865 316 26 1363 1933 1486 188 1513 434 109 1095 669 478 256 1976 842 932 127 652 261 1158 250 1906 1654 712 1907 46 86 1969 291 16...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
...

result:

ok 500 token(s): yes count is 0, no count is 500

Test #26:

score: 0
Accepted
time: 49ms
memory: 2120kb

input:

500
1000 1000
1338 1948 2347 2143 2632 740 1681 2113 304 1765 634 2862 1855 1467 1589 2805 414 246 288 2896 630 1340 493 2980 1852 2926 1380 472 1648 1778 10 2763 1257 2089 2960 1270 2498 1592 657 8 2263 1562 2573 2088 1314 1793 1842 1226 1586 436 1780 2217 1598 336 1274 1639 1457 2799 245 2175 350 ...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
...

result:

ok 500 token(s): yes count is 0, no count is 500

Test #27:

score: 0
Accepted
time: 71ms
memory: 4060kb

input:

5
100000 100000
175884 69085 200780 163097 174782 176860 177635 108439 58331 201693 45443 69964 67629 51542 230151 107451 248468 57 186555 154640 152853 186240 135695 65587 169123 140867 135857 34026 170860 122007 115654 152583 215432 194107 13818 172316 190315 104947 188587 138904 228578 106436 170...

output:

No
No
No
No
No

result:

ok 5 token(s): yes count is 0, no count is 5

Test #28:

score: 0
Accepted
time: 76ms
memory: 3940kb

input:

5
100000 100000
664173 769141 1166 421665 157281 469088 467744 347428 125383 437372 170344 193734 178373 196363 532625 552680 59286 602040 621936 226773 333095 417999 564272 587755 178960 506514 402308 783593 180747 706116 285043 195160 214919 82095 148311 473751 189806 114149 798307 261957 232368 2...

output:

No
No
No
No
No

result:

ok 5 token(s): yes count is 0, no count is 5

Test #29:

score: 0
Accepted
time: 80ms
memory: 11296kb

input:

1
500000 500000
897353 54134 40691 951584 976264 1025905 347917 284873 732288 588924 133252 567712 1015728 838624 494019 976920 723742 956033 571446 728126 129344 1060046 20061 258469 792326 765380 362099 832962 588916 305636 156212 843017 304793 1031490 746460 93058 760791 45824 309328 820232 94416...

output:

No

result:

ok NO

Test #30:

score: 0
Accepted
time: 40ms
memory: 2156kb

input:

500000
1 1
2
2
1 1
4
5
1 1
5
2
1 1
5
5
1 1
4
4
1 1
1
4
1 1
3
6
1 1
2
3
1 1
4
2
1 1
2
5
1 1
5
3
1 1
2
4
1 1
1
6
1 1
3
5
1 1
5
4
1 1
2
4
1 1
5
5
1 1
6
4
1 1
4
5
1 1
5
4
1 1
2
1
1 1
4
2
1 1
5
1
1 1
6
5
1 1
4
5
1 1
5
2
1 1
2
5
1 1
2
1
1 1
5
1
1 1
3
5
1 1
2
2
1 1
1
4
1 1
4
5
1 1
2
3
1 1
6
3
1 1
6
3
1 1
2...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
Yes
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
Yes
No
No
Yes
No
No
No
No
No
Yes
Yes
No
No
Yes
No
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
Yes
No
No
No
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
N...

result:

ok 500000 token(s): yes count is 97305, no count is 402695

Test #31:

score: 0
Accepted
time: 83ms
memory: 11396kb

input:

1
500000 500000
999999095 999999127 999999643 999999831 999999963 999999998 999999405 999999674 999999861 999999860 999999785 999999799 999999831 999999930 999999139 999999989 999999629 999999294 999999525 999999656 999999790 999999725 999999518 999999149 999999589 999999860 999999117 999999858 9999...

output:

No

result:

ok NO

Test #32:

score: 0
Accepted
time: 8ms
memory: 9912kb

input:

1
500000 500000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

Yes

result:

ok YES

Test #33:

score: 0
Accepted
time: 32ms
memory: 2160kb

input:

71428
7 7
13 3 2 6 3 12 5
3 1 8 5 13 9 12
7 7
3 8 2 3 10 1 9
4 5 1 10 8 13 1
7 7
12 12 13 4 8 13 13
2 2 2 8 7 5 12
7 7
5 4 8 10 6 4 6
3 3 7 10 5 8 9
7 7
10 4 12 11 12 2 12
1 5 12 2 5 2 4
7 7
10 2 9 1 11 1 8
3 13 13 6 1 5 2
7 7
8 12 3 11 2 13 9
9 8 9 12 7 8 11
7 7
1 11 1 5 3 11 11
9 2 6 6 2 1 8
7 7
1...

output:

Yes
Yes
No
No
Yes
Yes
No
Yes
No
Yes
No
Yes
Yes
No
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
No
Yes
No
Yes
Yes
No
Yes
No
No
Yes
Yes
No
Yes
Yes
No
Yes
Yes
No
Yes
No
Yes
Yes
Yes
No
Yes
No
No
Yes
No
No
No
No
Yes
Yes
Yes
No
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
No
No
Yes
Yes
No
Yes
N...

result:

ok 71428 token(s): yes count is 40447, no count is 30981

Test #34:

score: 0
Accepted
time: 25ms
memory: 2124kb

input:

29411
12 17
16 9 12 9 16 17 10 9 6 5 11 14
7 4 6 17 16 8 17 8 12 7 4 10 16 5 5 18 9
12 17
11 6 18 15 4 13 6 7 8 5 16 8
11 8 13 17 8 16 4 7 14 18 7 8 14 6 15 17 10
12 17
9 5 5 6 16 8 17 10 18 15 12 7
10 14 14 10 9 8 16 9 18 7 13 10 6 9 17 5 17
12 17
12 17 5 6 5 13 16 9 4 13 15 18
7 14 15 14 10 13 18 ...

output:

Yes
No
No
Yes
Yes
No
No
Yes
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
Yes
No
Yes
No
No
Yes
Yes
No
Yes
No
No
No
No
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
No
No
No
Yes
No
Yes
No
Yes
No
No
No
No
No
Yes
No
No
No
No
Yes
No
No
No
Yes
No...

result:

ok 29411 token(s): yes count is 7455, no count is 21956

Test #35:

score: 0
Accepted
time: 38ms
memory: 2148kb

input:

4166
100 120
61 33 78 91 193 51 81 102 55 22 102 121 78 38 183 25 111 119 34 159 72 199 167 194 186 144 121 80 63 199 193 162 32 188 102 75 76 164 87 17 104 75 148 16 25 82 42 28 121 174 118 40 70 194 198 38 185 162 196 72 92 91 24 114 101 139 123 133 185 91 147 66 198 172 176 173 101 169 146 143 19...

output:

No
Yes
No
No
No
No
No
Yes
Yes
Yes
No
Yes
No
Yes
No
No
Yes
No
No
Yes
Yes
No
No
No
No
No
No
No
No
Yes
No
Yes
Yes
No
No
Yes
Yes
No
Yes
Yes
No
Yes
No
No
No
Yes
No
No
No
Yes
Yes
Yes
No
Yes
Yes
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
Yes
Yes
Yes
No
Yes
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
Y...

result:

ok 4166 token(s): yes count is 1475, no count is 2691

Test #36:

score: 0
Accepted
time: 35ms
memory: 2232kb

input:

4166
120 100
184 49 107 106 74 173 105 105 6 92 34 37 188 107 87 180 22 106 101 156 86 12 134 112 117 82 57 156 170 28 53 8 17 101 30 94 125 154 91 60 103 115 65 198 48 130 59 46 102 109 40 189 195 76 173 93 109 117 24 22 105 179 46 60 148 139 57 40 25 146 55 195 77 177 25 121 109 151 141 179 155 16...

output:

Yes
No
No
Yes
Yes
No
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
No
Yes
No
No
No
No
No
Yes
Yes
Yes
No
No
No
No
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
No
Yes
No
Yes
Yes
Yes
No
No
No
No
Yes
No
Yes
Yes
No
No
No
Yes
No
No
Yes
No
No
No
Yes
Yes
No
Yes
No
No
No
Yes
No
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Y...

result:

ok 4166 token(s): yes count is 1704, no count is 2462

Test #37:

score: 0
Accepted
time: 53ms
memory: 2368kb

input:

500
1000 1000
1524 1161 1361 967 1364 413 627 230 510 1477 423 1918 1603 1803 114 957 934 423 1134 941 486 1809 602 1329 1434 1376 1473 1063 536 1209 315 736 1718 1653 1023 1360 1529 851 253 837 1634 577 1640 1306 1848 1694 204 203 1698 1320 1797 1062 1338 1720 158 1128 1159 966 1551 1069 1879 1525 ...

output:

Yes
No
Yes
Yes
Yes
No
No
Yes
No
Yes
No
No
No
Yes
No
No
No
No
Yes
No
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
Yes
No
No
No
No
Yes
Yes
Yes
Yes
Yes
No
No
No
No
No
No
Yes
No
No
No
No
No
No
Yes
No
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
Yes
No
No
Yes
Yes
No
No
Yes
No
Yes
No
No
No
Yes
No
No
Yes
...

result:

ok 500 token(s): yes count is 140, no count is 360

Test #38:

score: 0
Accepted
time: 65ms
memory: 2472kb

input:

50
10000 10000
13316 12271 9030 9937 15066 6648 4567 9204 13428 7471 2950 12781 5243 4144 7681 19222 7123 713 11026 874 8407 13294 10964 17013 8057 9448 2508 3925 15067 18361 10808 218 8234 16770 9784 9559 10931 5824 4004 13419 4737 12432 18659 6321 3029 9583 1691 14801 10830 19722 16935 13869 4213 ...

output:

No
Yes
No
No
No
Yes
No
Yes
No
No
Yes
No
No
No
Yes
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Yes
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
No
No
No
Yes

result:

ok 50 token(s): yes count is 17, no count is 33

Test #39:

score: 0
Accepted
time: 81ms
memory: 3912kb

input:

5
100000 100000
122970 105132 73963 94056 162471 131489 127977 103341 183724 26954 41670 151195 56892 10053 21080 28850 190304 20043 117241 89267 119797 55539 108561 23056 20091 165212 29954 147580 11463 119678 62291 101815 133681 12538 131847 28883 103223 135397 52611 148690 187409 174746 139531 14...

output:

No
Yes
Yes
No
Yes

result:

ok 5 token(s): yes count is 3, no count is 2

Test #40:

score: 0
Accepted
time: 72ms
memory: 11276kb

input:

1
500000 500000
867258 801062 31398 297983 529800 204463 632746 528358 780489 978801 87747 163039 898993 981347 748097 513586 442207 71852 449573 470697 323858 879893 789120 917636 370721 774453 335019 810520 410906 233994 172997 597660 546060 432919 137913 677074 542588 763280 849052 262052 951948 ...

output:

No

result:

ok NO

Extra Test:

score: 0
Extra Test Passed