Submission #73085581
Source Code Expand
#![allow(unused)]
use std::collections::BTreeSet;
use proconio::input;
fn main() {
input! {
n: usize,
d: i64,
arr: [i64; n],
}
// monotonic
// Two pointers with multiset
let check = |q: i64, s: &BTreeSet<(i64, usize)>| -> bool {
if let Some((x, _)) = s.range((q, 0)..).next() {
if x - q < d {
return false;
}
}
if let Some((x, _)) = s.range(..(q, !0)).last() {
if q - x < d {
return false;
}
}
true
};
let mut ans = 0;
let mut j = 0;
let mut set = BTreeSet::new();
for i in 0..n {
while j < n && check(arr[j], &set) {
set.insert((arr[j], j));
j += 1;
}
ans += (j - i) as i64;
set.remove(&(arr[i], i));
}
println!("{ans}");
}
fn join<T: ToString>(arr: &[T], sep: &str) -> String {
arr.iter()
.map(|x| x.to_string())
.collect::<Vec<String>>()
.join(sep)
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Sparse Range |
| User | amoshuangyc |
| Language | Rust (rustc 1.89.0) |
| Score | 450 |
| Code Size | 1093 Byte |
| Status | AC |
| Exec Time | 236 ms |
| Memory | 20304 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 450 / 450 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | min1.txt, min2.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| min1.txt | AC | 1 ms | 1856 KiB |
| min2.txt | AC | 1 ms | 1916 KiB |
| random_01.txt | AC | 174 ms | 11784 KiB |
| random_02.txt | AC | 149 ms | 10316 KiB |
| random_03.txt | AC | 169 ms | 11292 KiB |
| random_04.txt | AC | 145 ms | 10232 KiB |
| random_05.txt | AC | 114 ms | 9008 KiB |
| random_06.txt | AC | 63 ms | 5940 KiB |
| random_07.txt | AC | 97 ms | 9072 KiB |
| random_08.txt | AC | 70 ms | 7068 KiB |
| random_09.txt | AC | 95 ms | 8924 KiB |
| random_10.txt | AC | 61 ms | 6656 KiB |
| random_11.txt | AC | 135 ms | 10004 KiB |
| random_12.txt | AC | 6 ms | 3404 KiB |
| random_13.txt | AC | 21 ms | 9044 KiB |
| random_14.txt | AC | 220 ms | 20304 KiB |
| random_15.txt | AC | 236 ms | 20200 KiB |
| random_16.txt | AC | 220 ms | 20260 KiB |
| sample_01.txt | AC | 1 ms | 1856 KiB |
| sample_02.txt | AC | 1 ms | 1988 KiB |
| sample_03.txt | AC | 1 ms | 1804 KiB |