1+ #!usr/bin/env python3
2+ from collections import defaultdict , deque , Counter , OrderedDict
3+ from bisect import bisect_left , bisect_right
4+ from functools import reduce , lru_cache
5+ from heapq import heappush , heappop , heapify
6+
7+ import itertools
8+ import math , fractions
9+ import sys , copy
10+
11+ def L (): return sys .stdin .readline ().split ()
12+ def I (): return int (sys .stdin .readline ().rstrip ())
13+ def SL (): return list (sys .stdin .readline ().rstrip ())
14+ def LI (): return [int (x ) for x in sys .stdin .readline ().split ()]
15+ def LI1 (): return [int (x ) - 1 for x in sys .stdin .readline ().split ()]
16+ def LS (): return [list (x ) for x in sys .stdin .readline ().split ()]
17+ def R (n ): return [sys .stdin .readline ().strip () for _ in range (n )]
18+ def LR (n ): return [L () for _ in range (n )]
19+ def IR (n ): return [I () for _ in range (n )]
20+ def LIR (n ): return [LI () for _ in range (n )]
21+ def LIR1 (n ): return [LI1 () for _ in range (n )]
22+ def SLR (n ): return [SL () for _ in range (n )]
23+ def LSR (n ): return [LS () for _ in range (n )]
24+
25+ def perm (n , r ): return math .factorial (n ) // math .factorial (r )
26+ def comb (n , r ): return math .factorial (n ) // (math .factorial (r ) * math .factorial (n - r ))
27+
28+ def make_list (n , * args , default = 0 ): return [make_list (* args , default = default ) for _ in range (n )] if args else [default for _ in range (n )]
29+
30+ dire = [[1 , 0 ], [0 , 1 ], [- 1 , 0 ], [0 , - 1 ]]
31+ dire8 = [[1 , 0 ], [1 , 1 ], [0 , 1 ], [- 1 , 1 ], [- 1 , 0 ], [- 1 , - 1 ], [0 , - 1 ], [1 , - 1 ]]
32+ alphabets = "abcdefghijklmnopqrstuvwxyz"
33+ ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
34+ MOD = 1000000007
35+ INF = float ("inf" )
36+
37+ sys .setrecursionlimit (1000000 )
38+
39+ class BIT :
40+ def __init__ (self , li ):
41+ self .n , self .data = len (li ) + 1 , [0 ] + li
42+ for i in range (1 , self .n ):
43+ if i + (i & - i ) < self .n : self .data [i + (i & - i )] += self .data [i ]
44+
45+ def add (self , i , a ):
46+ i += 1
47+ while i < self .n :
48+ self .data [i ] += a
49+ i += i & - i
50+
51+ # sum of [0, i)
52+ def acc (self , i ):
53+ res = 0
54+ while i > 0 :
55+ res += self .data [i ]
56+ i -= i & - i
57+ return res
58+
59+ # sum of [l, r)
60+ def get (self , l , r = None ):
61+ if r is None : r = l + 1
62+ return self .acc (r ) - self .acc (l )
63+
64+
65+
66+ def main ():
67+ N , K = LI ()
68+ A = IR (N )
69+ B = [ai - K for ai in A ]
70+ cum = list (itertools .accumulate (B ))
71+ mapping = {}
72+ count = 0
73+ for ci in sorted (cum ):
74+ if not ci in mapping :
75+ mapping [ci ] = count
76+ count += 1
77+ mappedcum = [mapping [ci ] for ci in cum ]
78+
79+ bit = BIT ([0 ]* N )
80+
81+ ans = 0
82+ for i , ci in enumerate (mappedcum ):
83+ ans += bit .acc (ci + 1 )
84+ if cum [i ] >= 0 : ans += 1
85+ bit .add (ci , 1 )
86+
87+ print (ans )
88+
89+
90+ if __name__ == '__main__' :
91+ main ()
0 commit comments