Submission #73101119


Source Code Expand

use proconio::input;
use std::collections::BTreeSet;

#[proconio::fastout]
fn main() {
    input! {
        n: usize,
        d: i64,
        a: [i64; n],
    }

    let mut set = BTreeSet::new();
    let mut r = 0;
    let mut ans = 0i64;

    for l in 0..n {
        while r < n {
            let x = a[r];
            let pred = set.range(..x).next_back();
            let succ = set.range(x..).next();

            let mut ok = true;
            if let Some(&p) = pred {
                if x - p < d {
                    ok = false;
                }
            }
            if ok {
                if let Some(&s) = succ {
                    if s - x < d {
                        ok = false;
                    }
                }
            }

            if ok {
                set.insert(x);
                r += 1;
            } else {
                break;
            }
        }

        ans += (r - l) as i64;

        set.remove(&a[l]);
    }

    println!("{}", ans);
}

Submission Info

Submission Time
Task E - Sparse Range
User memoka
Language Rust (rustc 1.89.0)
Score 450
Code Size 1044 Byte
Status AC
Exec Time 242 ms
Memory 15408 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 21
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 2064 KiB
min2.txt AC 1 ms 2156 KiB
random_01.txt AC 176 ms 10500 KiB
random_02.txt AC 151 ms 9320 KiB
random_03.txt AC 173 ms 10372 KiB
random_04.txt AC 149 ms 9132 KiB
random_05.txt AC 117 ms 9084 KiB
random_06.txt AC 66 ms 6008 KiB
random_07.txt AC 102 ms 8984 KiB
random_08.txt AC 74 ms 7220 KiB
random_09.txt AC 101 ms 8996 KiB
random_10.txt AC 66 ms 6704 KiB
random_11.txt AC 137 ms 8980 KiB
random_12.txt AC 6 ms 3540 KiB
random_13.txt AC 23 ms 9100 KiB
random_14.txt AC 220 ms 15212 KiB
random_15.txt AC 242 ms 15408 KiB
random_16.txt AC 211 ms 15260 KiB
sample_01.txt AC 1 ms 2096 KiB
sample_02.txt AC 1 ms 2100 KiB
sample_03.txt AC 1 ms 2060 KiB