結果

問題 No.1110 好きな歌
ユーザー convexineq
提出日時 2021-04-11 02:19:23
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,032 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 82,372 KB
実行使用メモリ 844,440 KB
最終ジャッジ日時 2024-06-26 22:46:42
合計ジャッジ時間 4,477 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 2 RE * 2 MLE * 1 -- * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT: #0-indexed
    __slots__ = ["size", "tree","depth","n0"]
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
        self.depth = n.bit_length()
        self.n0 = 1<<self.depth

    def get_sum(self, i): #a_0 + ... + a_{i} #閉区間
        s = 0; i += 1
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def range_sum(self,l,r): #a_l + ... + a_r 閉区間
        return self.get_sum(r) - self.get_sum(l-1) 

    def range_sum_larger(self,l): #a_l + ... (端まで)
        return self.get_sum(self.size-1) - (self.get_sum(l-1) if l else 0)
    
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

n,d = map(int,input().split())
a = [int(input()) for _ in range(n)]
#M = 2*10**5+2
M = max(a)+1
bit = BIT(M)
for ai in a:
    bit.add(ai,1)
for ai in a:
    ai -= d
    if ai < 0:
        print(0)
    elif ai >= M:
        print(n-1)
    else:
        print(bit.get_sum(ai))
0