結果

問題 No.1471 Sort Queries
ユーザー mai
提出日時 2021-04-21 22:29:26
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,475 bytes
コンパイル時間 13,258 ms
コンパイル使用メモリ 401,452 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-04 06:05:04
合計ジャッジ時間 13,919 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `collections::*`
 --> src/main.rs:1:11
  |
1 | use std::{collections::*, io::Read};
  |           ^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

ソースコード

diff #

use std::{collections::*, io::Read};

fn take_token<R: std::io::BufRead>(cin: &mut R) -> String {
    cin.bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>()
}
#[allow(unused)]
macro_rules! scan {
    ($io:expr => $t:ty) => (take_token(&mut $io).parse::<$t>().unwrap());
    ($io:expr => $t:tt * $n:expr) => ((0..$n).map(|_| scan!($io => $t)).collect::<Vec<_>>());
    ($io:expr => $($t:tt),*) => (($(scan!($io => $t)),*));
    ($io:expr => $($t:tt),* * $n:expr) => ((0..$n).map(|_| ($(scan!($io => $t)),*)).collect::<Vec<_>>());
}

fn main() {
    solve(std::io::stdin().lock())
}

fn solve<R: std::io::BufRead>(mut cin: R) {
    let (n, q) = scan!(cin => i32, i32);
    let s = scan!(cin => String);
    let mut totals = vec![vec![0; (n + 1) as usize]; 27];
    for (i, c) in s.as_bytes().iter().enumerate() {
        totals[*c as usize - 'a' as usize][i + 1] = 1;
    }
    for c in 0..27 as usize {
        for i in 0..n as usize {
            totals[c][i + 1] += totals[c][i];
        }
    }

    for _ in 0..q {
        let (l, r, x2) = scan!(cin => i32, i32, i32);
        let mut x = x2;
        for c in 0..27 as usize {
            let d = totals[c][r as usize] - totals[c][(l - 1) as usize];
            x -= d;
            if x <= 0 {
                println!("{}", ('a' as u8 + c as u8) as char);
                break;
            }
        }
    }
}
0