結果

問題 No.953 席
ユーザー akiradeveloperakiradeveloper
提出日時 2019-12-16 16:27:06
言語 Rust
(1.77.0 + proconio)
結果
WA  
実行時間 -
コード長 22,946 bytes
コンパイル時間 16,060 ms
コンパイル使用メモリ 379,472 KB
実行使用メモリ 31,488 KB
最終ジャッジ日時 2024-07-02 20:03:01
合計ジャッジ時間 23,600 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 WA -
testcase_02 AC 1,190 ms
9,472 KB
testcase_03 AC 437 ms
8,576 KB
testcase_04 AC 872 ms
9,472 KB
testcase_05 AC 229 ms
8,064 KB
testcase_06 AC 1,193 ms
9,600 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused imports: `BTreeMap`, `BTreeSet`
   --> src/main.rs:239:28
    |
239 |     use std::collections::{BTreeMap, BTreeSet};
    |                            ^^^^^^^^  ^^^^^^^^
    |
    = note: `#[warn(unused_imports)]` on by default

warning: use of deprecated method `std::slice::<impl [T]>::connect`: renamed to join
   --> src/main.rs:294:34
    |
294 |                 println!("{}",ss.connect(","));
    |                                  ^^^^^^^
    |
    = note: `#[warn(deprecated)]` on by default
help: replace the use of the deprecated method
    |
294 |                 println!("{}",ss.join(","));
    |                                  ~~~~

warning: unused variable: `out`
   --> src/main.rs:112:13
    |
112 |     let mut out = BufWriter::new(out.lock());
    |             ^^^ help: if this is intentional, prefix it with an underscore: `_out`
    |
    = note: `#[warn(unused_variables)]` on by default

warning: variable does not need to be mutable
   --> src/main.rs:112:9
    |
112 |     let mut out = BufWriter::new(out.lock());
    |         ----^^^
    |         |
    |         help: remove this `mut`
    |
    = note: `#[warn(unused_mut)]` on by default

warning: variable does not need to be mutable
   --> src/main.rs:490:17
    |
490 |             let mut it = self.iter();
    |                 ----^^
    |                 |
    |                 help: remove this `mut`

warning: method `print_graph` is never used
   --> src/main.rs:272:16
    |
271 |     impl Skiplist<usize> {
    |     -------------------- method in this implementation
272 |         pub fn print_graph(&self) {
    |                ^^^^^^^^^^^
    |
    = note: `#[warn(dead_code)]` on by default

warning: multiple methods are never used
   --> src/main.rs:373:16
    |
299 |     impl <T> Skiplist<T> where T: std::cmp::Ord + fmt::Debug + Clone {
    |     ---------------------------------------------------------------- methods in this implementation
...
373 |         pub fn find(&

ソースコード

diff #

#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[macro_export]
macro_rules ! chmax { ( $ x : expr , $ ( $ v : expr ) ,+ ) => { $ ( $ x = std :: cmp :: max ( $ x ,$ v ) ; ) + } ; }
#[macro_export]
macro_rules ! chmin { ( $ x : expr , $ ( $ v : expr ) ,+ ) => { $ ( $ x = std :: cmp :: min ( $ x ,$ v ) ; ) + } ; }
#[macro_export]
macro_rules ! max { ( $ x : expr ) => ( $ x ) ; ( $ x : expr , $ ( $ xs : expr ) ,+ ) => { std :: cmp :: max ( $ x , max ! ( $ ( $ xs ) ,+ ) ) } ; }
#[macro_export]
macro_rules ! min { ( $ x : expr ) => ( $ x ) ; ( $ x : expr , $ ( $ xs : expr ) ,+ ) => { std :: cmp :: min ( $ x , min ! ( $ ( $ xs ) ,+ ) ) } ; }
#[macro_export]
macro_rules ! dvec { ( $ t : expr ; $ len : expr ) => { vec ! [ $ t ; $ len ] } ; ( $ t : expr ; $ len : expr , $ ( $ rest : expr ) ,* ) => { vec ! [ dvec ! ( $ t ; $ ( $ rest ) ,* ) ; $ len ] } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
#[macro_export]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut parser = Parser :: from_str ( $ s ) ; input_inner ! { parser , $ ( $ r ) * } } ; ( parser = $ parser : ident , $ ( $ r : tt ) * ) => { input_inner ! { $ parser , $ ( $ r ) * } } ; ( new_stdin_parser = $ parser : ident , $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let reader = std :: io :: BufReader :: new ( stdin . lock ( ) ) ; let mut $ parser = Parser :: new ( reader ) ; input_inner ! { $ parser , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { input ! { new_stdin_parser = parser , $ ( $ r ) * } } ; }
#[macro_export]
macro_rules ! input_inner { ( $ parser : ident ) => { } ; ( $ parser : ident , ) => { } ; ( $ parser : ident , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ parser , $ t ) ; input_inner ! { $ parser $ ( $ r ) * } } ; }
#[macro_export]
macro_rules ! read_value { ( $ parser : ident , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ parser , $ t ) ) ,* ) } ; ( $ parser : ident , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ parser , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ parser : ident , chars ) => { read_value ! ( $ parser , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ parser : ident , usize1 ) => { read_value ! ( $ parser , usize ) - 1 } ; ( $ parser : ident , $ t : ty ) => { $ parser . next ::<$ t > ( ) . expect ( "Parse error" ) } ; }
use std::io;
use std::io::BufRead;
use std::str;
pub struct Parser<R> {
    reader: R,
    buf: Vec<u8>,
    pos: usize,
}
impl Parser<io::Empty> {
    pub fn from_str(s: &str) -> Parser<io::Empty> {
        Parser {
            reader: io::empty(),
            buf: s.as_bytes().to_vec(),
            pos: 0,
        }
    }
}
impl<R: BufRead> Parser<R> {
    pub fn new(reader: R) -> Parser<R> {
        Parser {
            reader: reader,
            buf: vec![],
            pos: 0,
        }
    }
    pub fn update_buf(&mut self) {
        self.buf.clear();
        self.pos = 0;
        loop {
            let (len, complete) = {
                let buf2 = self.reader.fill_buf().unwrap();
                self.buf.extend_from_slice(buf2);
                let len = buf2.len();
                if len == 0 {
                    break;
                }
                (len, buf2[len - 1] <= 0x20)
            };
            self.reader.consume(len);
            if complete {
                break;
            }
        }
    }
    pub fn next<T: str::FromStr>(&mut self) -> Result<T, T::Err> {
        loop {
            let mut begin = self.pos;
            while begin < self.buf.len() && (self.buf[begin] <= 0x20) {
                begin += 1;
            }
            let mut end = begin;
            while end < self.buf.len() && (self.buf[end] > 0x20) {
                end += 1;
            }
            if begin != self.buf.len() {
                self.pos = end;
                return str::from_utf8(&self.buf[begin..end]).unwrap().parse::<T>();
            } else {
                self.update_buf();
            }
        }
    }
}
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    input!{
        n:usize,k1:usize,k2:usize,
        q:usize,
        ab:[(i64,i64);q]
    }

    let mut tablecoord = vec![];
    for i in 0..n {
        let i = i as i64;
        tablecoord.push(i*3);
    }
    let k1 = k1-1;
    let k2 = k2-1;
    let doorcoord = if k1 > k2 {
        tablecoord[k1]-1
    } else {
        tablecoord[k1]+1
    };

    let mut tableadj = vec![vec![]; n];
    tableadj[0].push(1);
    for i in 1..n-1 {
        tableadj[i].push(i-1);
        tableadj[i].push(i+1);
    }
    tableadj[n-1].push(n-2);

    let mut tabledist = vec![0;n];
    for i in 0..n {
        tabledist[i] = i64::abs(tablecoord[i] - doorcoord);
    }


    let mut forbidcnt = vec![0; n];
    let mut waitq = VecDeque::new();
    let mut tablemain = skiplist::Skiplist::new();
    for i in 0..n {
        tablemain.insert((tabledist[i], i));
    }
    let mut tablesub = skiplist::Skiplist::new();
    let mut events = BinaryHeap::new();
    for i in 0..q {
        events.push((-1 * ab[i].0, true, i));
    }

    let mut alloc = vec![1<<30; q];
    loop {
        if events.is_empty() { break; }

        let evt = events.pop().unwrap();
        let (t, b, man) = evt;
        let t = -1 * t;
        if !b { // leave
            let tbl = alloc[man];
            // 戻す
            let x = (tabledist[tbl], tbl);
            if forbidcnt[tbl] == 0 {
                tablemain.insert(x);
            } else {
                tablesub.insert(x);
            }
            for &adj in &tableadj[tbl] {
                forbidcnt[adj] -= 1;
                if forbidcnt[adj] == 0 {
                    let x = (tabledist[adj], adj);
                    if tablesub.remove(&x) {
                        tablemain.insert(x);
                    }
                }
            }
        } else {
            // まず最初にウェイトキューに入れることにする
            // すでに待ってる人たちと同一に扱うため
            waitq.push_back(man);
        }

        while !tablemain.is_empty() && !waitq.is_empty() {
            let (_, tbl) = tablemain.pop().unwrap();
            let man = waitq.pop_front().unwrap();

            alloc[man] = tbl;
            // 帰るイベントを登録する
            // falseにすることで同時刻ならleaveを優先する
            let leave_t = t + ab[man].1;
            events.push((-1 * leave_t, false, man));

            for &adj in &tableadj[tbl] {
                if forbidcnt[adj] == 0 {
                    let x = (tabledist[adj], adj);
                    if tablemain.remove(&x) {
                        tablesub.insert(x);
                    }
                }
                forbidcnt[adj] += 1;
            }
        }
        while !tablesub.is_empty() && !waitq.is_empty() {
            let (_, tbl) = tablesub.pop().unwrap();
            let man = waitq.pop_front().unwrap();

            alloc[man] = tbl;
            // 帰るイベントを登録する
            // falseにすることで同時刻ならleaveを優先する
            let leave_t = t + ab[man].1;
            events.push((-1 * leave_t, false, man));

            for &adj in &tableadj[tbl] {
                if forbidcnt[adj] == 0 {
                    let x = (tabledist[adj], adj);
                    if tablemain.remove(&x) {
                        tablesub.insert(x);
                    }
                }
                forbidcnt[adj] += 1;
            }
        }
    }

    for i in 0..q {
        println!("{}", alloc[i]+1);
    }
}

mod skiplist {
    use std;
    use std::collections::{BTreeMap, BTreeSet};
    use std::rc::Rc;
    use std::cell::{Cell, RefCell};
    // use std::ops::RangeBounds;
    use std::fmt;

    struct RandGen {
        x: u64,
    }
    impl RandGen {
        fn new(seed: u64) -> RandGen {
            RandGen {
                x: seed,
            }
        }
        fn next(&mut self) -> u64 {
            const a: u64 = 1103515245;
            const b: u64 = 12345;
            const m: u64 = 1<<32;
            self.x = (a*self.x+b)%m;
            self.x
        }
    }

    pub struct Skiplist<T> {
        max_height: Option<usize>,
        left_sentinel: Rc<RefCell<SkipNode<T>>>,
        right_sentinel: Rc<RefCell<SkipNode<T>>>,
        rand_gen: RandGen,
        traverse_stat: Cell<usize>,
        connect_stat: Cell<usize>,
    }
    impl Skiplist<usize> {
        pub fn print_graph(&self) {
            for level in (0..self.height()).rev() {
                let mut line=vec![];
                let mut cur = self.left_sentinel.clone();
                loop {
                    let next0 = cur.borrow().next[level].clone();
                    let next = next0.unwrap().clone();
                    if next.borrow().value.is_none() {
                        break;
                    } else {
                        cur = next.clone();
                        let v = cur.borrow().value.clone().unwrap();
                        line.push(v);
                    }
                }
                let mut ss = vec![];
                for x in line {
                    while ss.len() < x {
                        ss.push("--".to_string());
                    }
                    ss.push(format!("{:>02}", x));
                }
                println!("{}",ss.connect(","));
            }
            println!("");
        }
    }
    impl <T> Skiplist<T> where T: std::cmp::Ord + fmt::Debug + Clone {
        pub fn new() -> Skiplist<T> {
            let left_sentinel = Rc::new(RefCell::new(SkipNode::sentinel()));
            let right_sentinel = Rc::new(RefCell::new(SkipNode::sentinel()));
            let sentinel_height = left_sentinel.borrow().height();
            for level in 0..sentinel_height {
                left_sentinel.borrow_mut().next[level] = Some(right_sentinel.clone());
                right_sentinel.borrow_mut().prev[level] = Some(left_sentinel.clone());
            }
            Skiplist {
                max_height: None,
                left_sentinel: left_sentinel,
                right_sentinel: right_sentinel,
                rand_gen: RandGen::new(0),
                traverse_stat: Cell::new(0),
                connect_stat: Cell::new(0),
            }
        }
        fn height(&self) -> usize {
            self.max_height.unwrap_or(33)
        }
        fn pick_height(&mut self) -> usize {
            let z = self.rand_gen.next();
            let mut k = 0;
            let mut m = 1;
            while z&m!=0 {
                k+=1;
                m<<=1;
            }
            k+1
        }
        pub fn insert(&mut self, x: T) -> bool {
            let mut paths = self.traverse(&x);
            // println!("insert {:?}: {:?}", x, &paths);

            if !paths.is_empty() {
                let next0 = paths[0].borrow().next[0].clone();
                let next = next0.unwrap();
                let found = next.borrow().value.as_ref() == Some(&x);
                if found {
                    return false;
                }
            }

            let new_height = self.pick_height();
            self.max_height = Some(std::cmp::max(self.max_height.unwrap_or(0), new_height));
            while paths.len() < new_height {
                paths.push(self.left_sentinel.clone());
            }
            let new_node = Rc::new(RefCell::new(SkipNode::new(x, new_height)));
            for level in 0..new_height {
                let prev = &paths[level];
                self.connect_stat.set(self.connect_stat.get()+1);
                SkipNode::connect(prev, &new_node, level);
            }
            
            true
        }
        fn find_node(&self, x: &T) -> Option<Rc<RefCell<SkipNode<T>>>> {
            let paths = self.traverse(x);
            // println!("find {:?}: {:?}", x, &paths);

            if paths.is_empty() {
                return None
            }

            let next0 = paths[0].borrow().next[0].clone();
            let next = next0.unwrap();
            if next.borrow().value.as_ref() == Some(x) {
                Some(next)
            } else {
                None
            }
        }
        pub fn find(&self, x: &T) -> bool {
            self.find_node(x).is_some()
        }
        pub fn reset_stat(&self) {
            self.traverse_stat.set(0);
            self.connect_stat.set(0);
        }
        pub fn show_stat(&self) {
            println!("traverse: {}", self.traverse_stat.get());
            println!("connect: {}", self.connect_stat.get());
        }
        fn traverse(&self, x: &T) -> Vec<Rc<RefCell<SkipNode<T>>>> {
            if self.height() == 0 {
                return vec![]
            }

            let mut cur = self.left_sentinel.clone();
            let mut acc = vec![self.left_sentinel.clone(); self.height()];
            let mut level = self.height() - 1;
            loop {
                if level == 0 {
                    loop {
                        acc[level] = cur.clone();
                        let next0 = cur.borrow().next[level].clone();
                        let next = next0.unwrap();
                        if next.borrow().value.is_none() || next.borrow().value.as_ref().unwrap() >= x {
                            break;
                        } else {
                            cur = next.clone();
                            self.traverse_stat.set(self.traverse_stat.get()+1);
                        }
                    }
                    break;
                }

                let next0 = cur.borrow().next[level].clone();
                let next = next0.unwrap();
                if next.borrow().value.is_none() || next.borrow().value.as_ref().unwrap() >= x {
                    acc[level] = cur.clone();
                    level -= 1;
                    continue;
                } else {
                    cur = next;
                    self.traverse_stat.set(self.traverse_stat.get()+1);
                }
            }
            acc
        }
        fn traverse_rev(&self, x: &T) -> Vec<Rc<RefCell<SkipNode<T>>>> {
            if self.height() == 0 {
                return vec![]
            }

            let mut cur = self.right_sentinel.clone();
            let mut acc = vec![self.right_sentinel.clone(); self.height()];
            let mut level = self.height() - 1;
            loop {
                if level == 0 {
                    loop {
                        acc[level] = cur.clone();
                        let next = cur.borrow().prev[level].clone().unwrap();
                        if next.borrow().value.is_none() || next.borrow().value.as_ref().unwrap() <= x {
                            break;
                        } else {
                            cur = next.clone();
                        }
                    }
                    break;
                }

                let next = cur.borrow().prev[level].clone().unwrap();
                if next.borrow().value.is_none() || next.borrow().value.as_ref().unwrap() <= x {
                    acc[level] = cur.clone();
                    level -= 1;
                    continue;
                } else {
                    cur = next;
                }
            }
            acc
        }
        pub fn remove(&mut self, x: &T) -> bool {
            let node = self.find_node(x);
            if node.is_none() {
                return false
            }
            let node = node.unwrap();
            node.borrow_mut().remove();
            true
        }
        #[doc = "iterator in range [x,]"]
        pub fn ge_iter(&self, x: &T) -> Range<T> {
            let f = self.traverse(x)[0].clone();
            Range {
                forward: true,
                f: f,
                b: self.right_sentinel.clone(),
            }
        }
        #[doc = "iterator in range [,x]"]
        pub fn le_iter(&self, x: &T) -> Range<T> {
            let b = self.traverse_rev(x)[0].clone();
            Range {
                forward: false,
                f: self.left_sentinel.clone(),
                b: b,
            }
        }
        #[doc = "iterator in range [..]"]
        pub fn iter(&self) -> Range<T> {
            Range {
                forward: true,
                f: self.left_sentinel.clone(),
                b: self.right_sentinel.clone(),
            }
        }
        pub fn is_empty(&self) -> bool {
            let mut it = self.iter();
            let mut l = 0;
            for _ in it {
                l += 1;
            }
            l == 0
        }
        #[doc = "O(n)"]
        pub fn pop(&mut self) -> Option<T> {
            if self.is_empty() {
                None
            } else {
                let mut it = self.iter();
                let x = it.next().unwrap();
                self.remove(&x);
                Some(x)
            }
        }
        #[doc = "O(n)"]
        pub fn pop_back(&mut self) -> Option<T> {
            if self.is_empty() {
                None
            } else {
                let mut it = self.iter().rev();
                let x = it.next().unwrap();
                self.remove(&x);
                Some(x)
            }
        }
    }
    pub struct Range<T> {
        forward: bool,
        f: Rc<RefCell<SkipNode<T>>>,
        b: Rc<RefCell<SkipNode<T>>>,
    }
    impl <T: Clone> Iterator for Range<T> {
        type Item = T;
        fn next(&mut self) -> Option<Self::Item> {
            let next0 = if self.forward {
                self.f.borrow().next[0].clone()
            } else {
                self.b.borrow().prev[0].clone()
            };
            if next0.is_none() {
                return None
            }
            let next = next0.unwrap();
            if self.forward {
                self.f = next;
                self.f.borrow().value.clone()
            } else {
                self.b = next;
                self.b.borrow().value.clone()
            }
        }
    }
    impl <T: Clone> DoubleEndedIterator for Range<T> {
        fn next_back(&mut self) -> Option<Self::Item> {
            let next0 = if self.forward {
                self.b.borrow().prev[0].clone()
            } else {
                self.f.borrow().next[0].clone()
            };
            if next0.is_none() {
                return None
            }
            let next = next0.unwrap();
            if self.forward {
                self.b = next;
                self.b.borrow().value.clone()
            } else {
                self.f = next;
                self.f.borrow().value.clone()
            }
        }
    }
    impl <T> fmt::Debug for Skiplist<T> where T: fmt::Debug + Clone + std::cmp::Ord {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            let v: Vec<T> = self.iter().collect();
            writeln!(f, "{:?}", v);
            Ok(())
        }
    }
    struct SkipNode<T> {
        value: Option<T>,
        prev: Vec<Option<Rc<RefCell<SkipNode<T>>>>>,
        next: Vec<Option<Rc<RefCell<SkipNode<T>>>>>,
    }
    impl <T> fmt::Debug for SkipNode<T> where T: fmt::Debug + std::cmp::Ord {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            writeln!(f, "{:?}, {:?}", self.value, self.height());
            Ok(())
        }
    }
    impl <T> SkipNode<T> where T: std::cmp::Ord + fmt::Debug {
        fn sentinel() -> SkipNode<T> {
            SkipNode {
                value: None,
                prev: vec![None; 33],
                next: vec![None; 33],
            }
        }
        fn new(value: T, height: usize) -> SkipNode<T> {
            SkipNode {
                value: Some(value),
                prev: vec![None; height],
                next: vec![None; height],
            }
        }
        fn height(&self) -> usize {
            self.next.len()
        }
        fn remove(&mut self) {
            for level in 0..self.height() {
                let prev_node = self.prev[level].clone().unwrap();
                let next_node = self.next[level].clone().unwrap();
                next_node.borrow_mut().prev[level] = Some(prev_node.clone());
                prev_node.borrow_mut().next[level] = Some(next_node.clone());
            }
        }
        // x -> z => x -> y -> z
        // z = some or none
        fn connect(x: &Rc<RefCell<Self>>, y: &Rc<RefCell<Self>>, level: usize) {
            let x_next = x.borrow().next[level].clone().unwrap();
            x.borrow_mut().next[level] = Some(y.clone());
            y.borrow_mut().prev[level] = Some(x.clone());

            y.borrow_mut().next[level] = Some(x_next.clone());
            x_next.borrow_mut().prev[level] = Some(y.clone());
        }
    }
 

    use std::collections::HashMap;
    pub struct Multiset<T> {
        sl: Skiplist<T>,
        counting: HashMap<T, usize>,
    }
    impl <T> Multiset<T> where T: Ord + fmt::Debug + Clone + std::hash::Hash {
        pub fn new() -> Multiset<T> {
            Multiset {
                sl: Skiplist::new(),
                counting: HashMap::new(),
            }
        }
        pub fn insert(&mut self, x: T) {
            self.sl.insert(x.clone());
            *self.counting.entry(x).or_insert(0) += 1;
        }
        pub fn counting(&self, x: &T) -> usize {
            self.counting.get(x).cloned().unwrap_or(0)
        }
        pub fn remove(&mut self, x: &T) -> bool {
            let cnt = self.counting(x);
            if cnt == 0 {
                return false
            }

            if cnt >= 2 {
                *self.counting.get_mut(x).unwrap() -= 1;
            }
            else if cnt == 1 {
                self.counting.remove(x);
                self.sl.remove(x);
            }
            return true
        }
        pub fn unwrap(&self) -> &Skiplist<T> {
            &self.sl
        }
    }
}
0