Problem:
K Average Ranges

数列a_1,a_2,..,a_Nが与えられます。

この数列に値の平均がK以上の長さ1以上の区間はいくつありますか。

入力

N K
a_1 a_2...a_N

出力

答えを出力せよ。

制約

1 \leq N \leq 10^5

1 \leq K \leq 10^9

1 \leq a_i \leq 10^9

入力例

6 6
8 6 9 1 2 1

出力例

7

Solution in Rust (judge verdict: Accepted)

//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn calc(a: &mut [i64]) -> u64 {
    let n = a.len();
    if n <= 1 {
        return 0;
    }
    let m = n / 2;
    let mut ans = calc(&mut a[..m]) + calc(&mut a[m..]);
    let mut b = vec![];
    let mut i = 0;
    let mut j = m;
    while i < m && j < n {
        if a[i] <= a[j] {
            ans += (n - j) as u64;
            b.push(a[i]);
            i += 1;
        } else {
            b.push(a[j]);
            j += 1;
        }
    }
    while i < m {
        b.push(a[i]);
        i += 1;
    }
    for i in 0..b.len() {
        a[i] = b[i];
    }
    ans
}

fn run() {
    input! {
        n: usize,
        k: i64,
        a: [i64; n],
    }
    let mut a = a;
    for a in a.iter_mut() {
        *a -= k;
    }
    a.push(0);
    a.reverse();
    for i in 1..(n + 1) {
        a[i] += a[i - 1];
    }
    let ans = calc(&mut a);
    println!("{}", ans);
}

fn main() {
    run();
}