結果

問題 No.3016 unordered_mapなるたけ落とすマン
ユーザー くれちーくれちー
提出日時 2020-05-22 13:30:41
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 107 ms / 1,000 ms
コード長 12,054 bytes
コンパイル時間 14,936 ms
コンパイル使用メモリ 378,600 KB
実行使用メモリ 5,504 KB
最終ジャッジ日時 2024-10-04 12:10:48
合計ジャッジ時間 16,173 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 107 ms
5,504 KB
testcase_04 AC 64 ms
5,504 KB
testcase_05 AC 21 ms
5,376 KB
testcase_06 AC 22 ms
5,376 KB
testcase_07 AC 22 ms
5,504 KB
testcase_08 AC 34 ms
5,504 KB
testcase_09 AC 18 ms
5,376 KB
testcase_10 AC 18 ms
5,248 KB
testcase_11 AC 19 ms
5,376 KB
testcase_12 AC 16 ms
5,376 KB
testcase_13 AC 16 ms
5,376 KB
testcase_14 AC 17 ms
5,248 KB
testcase_15 AC 18 ms
5,376 KB
testcase_16 AC 19 ms
5,376 KB
testcase_17 AC 17 ms
5,504 KB
testcase_18 AC 19 ms
5,248 KB
testcase_19 AC 17 ms
5,248 KB
testcase_20 AC 17 ms
5,248 KB
testcase_21 AC 17 ms
5,248 KB
testcase_22 AC 18 ms
5,248 KB
testcase_23 AC 16 ms
5,248 KB
testcase_24 AC 14 ms
5,248 KB
testcase_25 AC 17 ms
5,376 KB
testcase_26 AC 15 ms
5,248 KB
testcase_27 AC 17 ms
5,248 KB
testcase_28 AC 16 ms
5,248 KB
testcase_29 AC 17 ms
5,248 KB
testcase_30 AC 18 ms
5,248 KB
testcase_31 AC 16 ms
5,248 KB
testcase_32 AC 16 ms
5,248 KB
testcase_33 AC 17 ms
5,248 KB
testcase_34 AC 17 ms
5,248 KB
testcase_35 AC 17 ms
5,248 KB
testcase_36 AC 15 ms
5,248 KB
testcase_37 AC 15 ms
5,248 KB
testcase_38 AC 15 ms
5,248 KB
testcase_39 AC 14 ms
5,248 KB
testcase_40 AC 16 ms
5,248 KB
testcase_41 AC 1 ms
5,248 KB
testcase_42 AC 1 ms
5,248 KB
testcase_43 AC 1 ms
5,248 KB
testcase_44 AC 2 ms
5,248 KB
testcase_45 AC 2 ms
5,248 KB
testcase_46 AC 2 ms
5,248 KB
testcase_47 AC 13 ms
5,248 KB
testcase_48 AC 14 ms
5,504 KB
testcase_49 AC 14 ms
5,376 KB
testcase_50 AC 13 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// The main code is at the very bottom.

#[allow(unused_imports)]
use {
  lib::byte::ByteChar,
  std::cell::{Cell, RefCell},
  std::cmp::{
    self,
    Ordering::{self, *},
    Reverse,
  },
  std::collections::*,
  std::convert::identity,
  std::fmt::{self, Debug, Display, Formatter},
  std::io::prelude::*,
  std::iter::{self, FromIterator},
  std::marker::PhantomData,
  std::mem,
  std::num::Wrapping,
  std::ops::{Range, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive},
  std::process,
  std::rc::Rc,
  std::thread,
  std::time::{Duration, Instant},
  std::{char, f32, f64, i128, i16, i32, i64, i8, isize, str, u128, u16, u32, u64, u8, usize},
};

// https://github.com/rust-lang/rustc-hash/blob/5e09ea0a1c7ab7e4f9e27771f5a0e5a36c58d1bb/src/lib.rs
//
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// LICENSE-MIT:
// Permission is hereby granted, free of charge, to any
// person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the
// Software without restriction, including without
// limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice
// shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
pub mod rustc_hash {
  use std::collections::{HashMap, HashSet};
  use std::convert::TryInto;
  use std::hash::BuildHasherDefault;
  use std::hash::Hasher;
  use std::mem::size_of;
  use std::ops::BitXor;

  pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;

  pub type FxHashSet<V> = HashSet<V, BuildHasherDefault<FxHasher>>;

  pub struct FxHasher {
    hash: usize,
  }

  #[cfg(target_pointer_width = "32")]
  const K: usize = 0x9e3779b9;
  #[cfg(target_pointer_width = "64")]
  const K: usize = 0x517cc1b727220a95;

  impl Default for FxHasher {
    #[inline]
    fn default() -> FxHasher {
      FxHasher { hash: 0 }
    }
  }

  impl FxHasher {
    #[inline]
    fn add_to_hash(&mut self, i: usize) {
      self.hash = self.hash.rotate_left(5).bitxor(i).wrapping_mul(K);
    }
  }

  impl Hasher for FxHasher {
    #[inline]
    fn write(&mut self, mut bytes: &[u8]) {
      #[cfg(target_pointer_width = "32")]
      let read_usize = |bytes: &[u8]| u32::from_ne_bytes(bytes[..4].try_into().unwrap());
      #[cfg(target_pointer_width = "64")]
      let read_usize = |bytes: &[u8]| u64::from_ne_bytes(bytes[..8].try_into().unwrap());

      let mut hash = FxHasher { hash: self.hash };
      assert!(size_of::<usize>() <= 8);
      while bytes.len() >= size_of::<usize>() {
        hash.add_to_hash(read_usize(bytes) as usize);
        bytes = &bytes[size_of::<usize>()..];
      }
      if (size_of::<usize>() > 4) && (bytes.len() >= 4) {
        hash.add_to_hash(u32::from_ne_bytes(bytes[..4].try_into().unwrap()) as usize);
        bytes = &bytes[4..];
      }
      if (size_of::<usize>() > 2) && bytes.len() >= 2 {
        hash.add_to_hash(u16::from_ne_bytes(bytes[..2].try_into().unwrap()) as usize);
        bytes = &bytes[2..];
      }
      if (size_of::<usize>() > 1) && bytes.len() >= 1 {
        hash.add_to_hash(bytes[0] as usize);
      }
      self.hash = hash.hash;
    }

    #[inline]
    fn write_u8(&mut self, i: u8) {
      self.add_to_hash(i as usize);
    }

    #[inline]
    fn write_u16(&mut self, i: u16) {
      self.add_to_hash(i as usize);
    }

    #[inline]
    fn write_u32(&mut self, i: u32) {
      self.add_to_hash(i as usize);
    }

    #[cfg(target_pointer_width = "32")]
    #[inline]
    fn write_u64(&mut self, i: u64) {
      self.add_to_hash(i as usize);
      self.add_to_hash((i >> 32) as usize);
    }

    #[cfg(target_pointer_width = "64")]
    #[inline]
    fn write_u64(&mut self, i: u64) {
      self.add_to_hash(i as usize);
    }

    #[inline]
    fn write_usize(&mut self, i: usize) {
      self.add_to_hash(i);
    }

    #[inline]
    fn finish(&self) -> u64 {
      self.hash as u64
    }
  }
}

#[allow(unused_imports)]
#[macro_use]
pub mod lib {
  pub mod byte {
    pub use self::byte_char::*;

    mod byte_char {
      use std::error::Error;
      use std::fmt::{self, Debug, Display, Formatter};
      use std::str::FromStr;

      #[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
      #[repr(transparent)]
      pub struct ByteChar(pub u8);

      impl Debug for ByteChar {
        fn fmt(&self, f: &mut Formatter) -> fmt::Result {
          write!(f, "b'{}'", self.0 as char)
        }
      }

      impl Display for ByteChar {
        fn fmt(&self, f: &mut Formatter) -> fmt::Result {
          write!(f, "{}", self.0 as char)
        }
      }

      impl FromStr for ByteChar {
        type Err = ParseByteCharError;

        fn from_str(s: &str) -> Result<ByteChar, ParseByteCharError> {
          match s.as_bytes().len() {
            1 => Ok(ByteChar(s.as_bytes()[0])),
            0 => Err(ParseByteCharErrorKind::EmptyStr.into()),
            _ => Err(ParseByteCharErrorKind::TooManyBytes.into()),
          }
        }
      }

      #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
      pub struct ParseByteCharError {
        kind: ParseByteCharErrorKind,
      }

      impl Display for ParseByteCharError {
        fn fmt(&self, f: &mut Formatter) -> fmt::Result {
          f.write_str(match self.kind {
            ParseByteCharErrorKind::EmptyStr => "empty string",
            ParseByteCharErrorKind::TooManyBytes => "too many bytes",
          })
        }
      }

      impl Error for ParseByteCharError {}

      #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
      enum ParseByteCharErrorKind {
        EmptyStr,
        TooManyBytes,
      }

      impl From<ParseByteCharErrorKind> for ParseByteCharError {
        fn from(kind: ParseByteCharErrorKind) -> ParseByteCharError {
          ParseByteCharError { kind }
        }
      }
    }
  }

  pub mod io {
    pub use self::scanner::*;

    mod scanner {
      use std::io::{self, BufRead};
      use std::iter;
      use std::str::FromStr;

      #[derive(Debug)]
      pub struct Scanner<R> {
        reader: R,
        buf: String,
        pos: usize,
      }

      impl<R: BufRead> Scanner<R> {
        pub fn new(reader: R) -> Self {
          Scanner {
            reader,
            buf: String::new(),
            pos: 0,
          }
        }

        pub fn next(&mut self) -> io::Result<&str> {
          let start = loop {
            match self.rest().find(|c| c != ' ') {
              Some(i) => break i,
              None => self.fill_buf()?,
            }
          };
          self.pos += start;
          let len = self.rest().find(' ').unwrap_or(self.rest().len());
          let s = &self.buf[self.pos..][..len]; // self.rest()[..len]
          self.pos += len;
          Ok(s)
        }

        pub fn parse_next<T>(&mut self) -> io::Result<Result<T, T::Err>>
        where
          T: FromStr,
        {
          Ok(self.next()?.parse())
        }

        pub fn parse_next_n<T>(&mut self, n: usize) -> io::Result<Result<Vec<T>, T::Err>>
        where
          T: FromStr,
        {
          iter::repeat_with(|| self.parse_next()).take(n).collect()
        }

        pub fn map_next_bytes<T, F>(&mut self, mut f: F) -> io::Result<Vec<T>>
        where
          F: FnMut(u8) -> T,
        {
          Ok(self.next()?.bytes().map(&mut f).collect())
        }

        pub fn map_next_bytes_n<T, F>(&mut self, n: usize, mut f: F) -> io::Result<Vec<Vec<T>>>
        where
          F: FnMut(u8) -> T,
        {
          iter::repeat_with(|| self.map_next_bytes(&mut f))
            .take(n)
            .collect()
        }

        fn rest(&self) -> &str {
          &self.buf[self.pos..]
        }

        fn fill_buf(&mut self) -> io::Result<()> {
          self.buf.clear();
          self.pos = 0;
          let read = self.reader.read_line(&mut self.buf)?;
          if read == 0 {
            return Err(io::ErrorKind::UnexpectedEof.into());
          }
          if *self.buf.as_bytes().last().unwrap() == b'\n' {
            self.buf.pop();
          }
          Ok(())
        }
      }
    }
  }
}

#[allow(unused_macros)]
macro_rules! eprint {
  ($($arg:tt)*) => {
    if cfg!(debug_assertions) {
      std::eprint!($($arg)*)
    }
  };
}
#[allow(unused_macros)]
macro_rules! eprintln {
  ($($arg:tt)*) => {
    if cfg!(debug_assertions) {
      std::eprintln!($($arg)*)
    }
  };
}
#[allow(unused_macros)]
macro_rules! dbg {
  ($($arg:tt)*) => {
    if cfg!(debug_assertions) {
      std::dbg!($($arg)*)
    } else {
      ($($arg)*)
    }
  };
}

const CUSTOM_STACK_SIZE_MIB: Option<usize> = Some(128);
const INTERACTIVE: bool = false;

fn main() -> std::io::Result<()> {
  match CUSTOM_STACK_SIZE_MIB {
    Some(stack_size_mib) => std::thread::Builder::new()
      .name("run_solver".to_owned())
      .stack_size(stack_size_mib * 1024 * 1024)
      .spawn(run_solver)?
      .join()
      .unwrap(),
    None => run_solver(),
  }
}

fn run_solver() -> std::io::Result<()> {
  let stdin = std::io::stdin();
  let reader = stdin.lock();
  let stdout = std::io::stdout();
  let writer = stdout.lock();
  macro_rules! with_wrapper {
    ($($wrapper:expr)?) => {{
      let mut writer = $($wrapper)?(writer);
      solve(reader, &mut writer)?;
      writer.flush()
    }};
  }
  if cfg!(debug_assertions) {
    with_wrapper!()
  } else if INTERACTIVE {
    with_wrapper!(std::io::LineWriter::new)
  } else {
    with_wrapper!(std::io::BufWriter::new)
  }
}

fn solve<R, W>(reader: R, mut writer: W) -> std::io::Result<()>
where
  R: BufRead,
  W: Write,
{
  let mut _scanner = lib::io::Scanner::new(reader);
  #[allow(unused_macros)]
  macro_rules! scan {
    ($T:ty) => {
      _scanner.parse_next::<$T>()?.unwrap()
    };
    ($($T:ty),+) => {
      ($(scan!($T)),+)
    };
    ($T:ty; $n:expr) => {
      _scanner.parse_next_n::<$T>($n)?.unwrap()
    };
    ($($T:ty),+; $n:expr) => {
      iter::repeat_with(|| -> std::io::Result<_> { Ok(($(scan!($T)),+)) })
        .take($n)
        .collect::<std::io::Result<Vec<_>>>()?
    };
  }
  #[allow(unused_macros)]
  macro_rules! scan_bytes_map {
    ($f:expr) => {
      _scanner.map_next_bytes($f)?
    };
    ($f:expr; $n:expr) => {
      _scanner.map_next_bytes_n($n, $f)?
    };
  }
  #[allow(unused_macros)]
  macro_rules! print {
    ($($arg:tt)*) => {
      write!(writer, $($arg)*)?
    };
  }
  #[allow(unused_macros)]
  macro_rules! println {
    ($($arg:tt)*) => {
      writeln!(writer, $($arg)*)?
    };
  }
  #[allow(unused_macros)]
  macro_rules! answer {
    ($($arg:tt)*) => {{
      println!($($arg)*);
      return Ok(());
    }};
  }
  {
    let (n, m) = scan!(usize, usize);
    let mut a = rustc_hash::FxHashMap::with_capacity_and_hasher(n, <_>::default());
    for _ in 0..n {
      let a_i = scan!(u64);
      *a.entry(a_i).or_default() += 1;
    }
    for _ in 0..m {
      let b_i = scan!(u64);
      print!("{} ", a.get(&b_i).copied().unwrap_or(0));
    }
    println!();
  }
  Ok(())
}
0