結果
| 問題 |
No.2650 [Cherry 6th Tune *] セイジャク
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-23 22:51:34 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 253 ms / 2,500 ms |
| コード長 | 2,454 bytes |
| コンパイル時間 | 25,082 ms |
| コンパイル使用メモリ | 395,464 KB |
| 実行使用メモリ | 29,212 KB |
| 最終ジャッジ日時 | 2024-09-29 08:02:31 |
| 合計ジャッジ時間 | 28,738 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 31 |
コンパイルメッセージ
warning: unused variable: `a` --> src/main.rs:9:9 | 9 | let a = temp[1]; | ^ help: if this is intentional, prefix it with an underscore: `_a` | = note: `#[warn(unused_variables)]` on by default
ソースコード
use std::collections::{BTreeSet, HashMap};
fn main() {
let mut temp = String::new();
std::io::stdin().read_line(&mut temp).ok();
let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
let n = temp[0];
let a = temp[1];
let mut x = String::new();
std::io::stdin().read_line(&mut x).ok();
let x: Vec<usize> = x.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
let mut t = String::new();
std::io::stdin().read_line(&mut t).ok();
let t: usize = t.trim().parse().unwrap();
let lrs = (0..t).map(|_| {
let mut temp = String::new();
std::io::stdin().read_line(&mut temp).ok();
let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
(temp[0], temp[1])
})
.collect::<Vec<_>>();
let mut result = vec![-1isize; n];
let mut order = (0..n).collect::<Vec<_>>();
order.sort_by_key(|&i| (x[i], i));
let mut sounds = BTreeSet::new();
let mut start_map: HashMap<usize, Vec<isize>> = HashMap::new();
let mut end_map: HashMap<usize, Vec<isize>> = HashMap::new();
for i in 0..t {
if start_map.contains_key(&lrs[i].0) {
start_map.get_mut(&lrs[i].0).unwrap().push(i as isize + 1);
} else {
start_map.insert(lrs[i].0, vec![i as isize + 1]);
}
if end_map.contains_key(&lrs[i].1) {
end_map.get_mut(&lrs[i].1).unwrap().push(i as isize + 1);
} else {
end_map.insert(lrs[i].1, vec![i as isize + 1]);
}
}
let starts = (0..t).map(|i| lrs[i].0).collect::<BTreeSet<_>>();
let ends = (0..t).map(|i| lrs[i].1).collect::<BTreeSet<_>>();
let mut pos = 0usize;
for idx in 0..n {
let i = order[idx];
let next_pos = x[i];
for s in starts.range(pos..=next_pos) {
for &sidx in start_map.get(s).unwrap().iter() {
sounds.insert(sidx);
}
}
for s in ends.range(pos..next_pos) {
for &sidx in end_map.get(s).unwrap().iter() {
sounds.remove(&sidx);
}
}
result[i] = *sounds.last().unwrap_or(&-1);
if idx+1 < n && x[order[idx]] < x[order[idx+1]] {
pos = next_pos;
}
}
let result = result.into_iter().map(|v| v.to_string()).collect::<Vec<_>>();
println!("{}", result.join("\n"));
}