Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::io;
- use std::io::Read;
- macro_rules! get {
- // 1行 1数値を取得する。
- ($t: ty) => {{
- let mut line: String = String::new();
- std::io::stdin().read_line(&mut line).unwrap();
- line.trim().parse::<$t>().unwrap()
- }};
- // ↑ を$n回やってVectorを返す。
- ($t:ty; $n:expr) => {{
- (0..$n).map(|_| get!($t) ).collect::<Vec<_>>()
- }};
- // 一行に含まれる複数値をタプルにして返す ex. in 1 2 3 : get!(usize, usize, usize) -> (1, 2, 3)
- ($ ($t:ty), *) => {{
- let mut line: String = String::new();
- std::io::stdin().read_line(&mut line).unwrap();
- let mut iter = lien.split_whitespace();
- (
- $( iter.next().unwarp().parse::<$t>().unwrap(), )*
- )
- }};
- // ↑ を $n回やって、Vec<(ty, ty, ty, ...)> を返す
- ($ ($t:ty), *; $n:expr) => {
- (0..$n).map(|_|
- get!($($t),*) // , カンマも繰り返される
- ).collect::<Vec<_>>()
- };
- // 1行n数値を、全部同じ型でパースしてVecで返す。
- ($t:ty ;;) => {{
- let mut line: String = String::new();
- std::io::stdin().read_line(&mut line).unwrap();
- line.split_whitespace().map(|text| text.parse::<$t>().unwrap()).collect::<Vec<_>>()
- }};
- // ↑を複数回繰り返して、2次元vectorで返す。vec[row][col]
- ($t:ty ;; $n:expr) => {
- (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
- };
- }
- fn main() {
- // バッファ用意
- let mut buf = String::new();
- io::stdin().read_to_string(&mut buf).unwrap();
- let mut iter = buf.split_whitespace();
- let n = get!(usize);
- let q: usize = iter.next().unwrap().parse().unwrap(); // データ列の数
- // 要素数 0 ~ q-1 のタプルVecを作って、vecterに代入する
- let lrt: Vec<(usize, usize, u64)> = (0..q)
- .map(|_| {
- (
- iter.next().unwrap().parse().unwrap(),
- iter.next().unwrap().parse().unwrap(),
- iter.next().unwrap().parse().unwrap(),
- )
- })
- .collect();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement