Advertisement
paranid5

QueueMin

Jun 20th, 2020
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.34 KB | None | 0 0
  1. extern crate text_io;
  2. use text_io::scan;
  3. use std::collections::VecDeque;
  4.  
  5. fn main() {
  6.     let mut _q: VecDeque<u32> = VecDeque::new();
  7.     let mut _ans: Vec<i32> = vec![];
  8.     let mut _n = 0;
  9.     scan!("{}", _n);
  10.     let mut _min: (u32, u32) = (0, 10001);
  11.     for _i in 0.._n {
  12.         let mut _command = 0;
  13.         scan!("{}", _command);
  14.         if _command == 0 {
  15.             if _q.is_empty() {
  16.                 _ans.push(-1);
  17.             } else {
  18.                 if _min.1 == 10001 {
  19.                     for _g in 0.._q.len() {
  20.                         if _q[_g] <= _min.1 {
  21.                             _min.1 = _q[_g];
  22.                             _min.0 = _g as u32;
  23.                         }
  24.                     }
  25.                 }
  26.                 _ans.push(_min.1 as i32);
  27.                 if _min.0 == 0 {
  28.                     _min.0 = 1;
  29.                     _min.1 = 10001;
  30.                 }
  31.                 _q.pop_front();
  32.                 _min.0 -= 1;
  33.             }
  34.         } else {
  35.             _q.push_back(_command);
  36.             if _command <= _min.1 {
  37.                 _min.0 = (_q.len()) as u32 - 1;
  38.                 _min.1 = _command;
  39.             }
  40.         }
  41.     }
  42.     for _i in _ans.iter() {
  43.         println!("{}", _i);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement