結果
問題 | No.5011 Better Mo's Algorithm is Needed!! (Weighted) |
ユーザー | akakimidori |
提出日時 | 2022-12-17 00:09:46 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 134 ms / 5,000 ms |
コード長 | 2,639 bytes |
コンパイル時間 | 2,958 ms |
実行使用メモリ | 13,520 KB |
スコア | 34,917,031,721 |
最終ジャッジ日時 | 2022-12-17 00:10:56 |
合計ジャッジ時間 | 65,265 ms |
ジャッジサーバーID (参考情報) |
judge10 / judge11 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 120 |
コンパイルメッセージ
warning: unused import: `std::io::Write` --> Main.rs:1:5 | 1 | use std::io::Write; | ^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: type alias is never used: `Map` --> Main.rs:4:1 | 4 | type Map<K, V> = BTreeMap<K, V>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default warning: type alias is never used: `Set` --> Main.rs:5:1 | 5 | type Set<T> = BTreeSet<T>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type alias is never used: `Deque` --> Main.rs:6:1 | 6 | type Deque<T> = VecDeque<T>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: 4 warnings emitted
ソースコード
use std::io::Write; use std::collections::*; type Map<K, V> = BTreeMap<K, V>; type Set<T> = BTreeSet<T>; type Deque<T> = VecDeque<T>; fn run() { input! { n: usize, q: usize, _x: [u32; 2], _a: [u32; n], ask: [(usize1, usize); q], } let batch = ((n as f64) / (q as f64).sqrt()).ceil() as usize; let mut p = (0..q).collect::<Vec<_>>(); p.sort_by_key(|x| { let (l, r) = ask[*x]; let l = l / batch; let r = if l % 2 == 0 {r} else {!r}; (l, r) }); use util::*; println!("{}", p.iter().map(|p| *p + 1).join(" ")); } fn main() { run(); } // ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 #[macro_export] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } #[macro_export] macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } #[macro_export] macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::<Vec<char>>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::<Vec<u8>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ---------- mod util { pub trait Join { fn join(self, sep: &str) -> String; } impl<T, I> Join for I where I: Iterator<Item = T>, T: std::fmt::Display, { fn join(self, sep: &str) -> String { let mut s = String::new(); use std::fmt::*; for (i, v) in self.enumerate() { if i > 0 { write!(&mut s, "{}", sep).ok(); } write!(&mut s, "{}", v).ok(); } s } } }