結果

問題 No.8072 Sum of sqrt(x)
ユーザー ecottea
提出日時 2023-08-03 01:49:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,869 ms / 2,000 ms
コード長 890 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 82,236 KB
実行使用メモリ 157,136 KB
最終ジャッジ日時 2024-06-24 10:32:56
合計ジャッジ時間 155,356 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

class FenwickTree:
    def __init__(self, n):
        self.n = n + 1
        self.v = [0] * n
    
    def __init__(self, a):
        self.n = len(a) + 1
        self.v = [0] + a
        pow2 = 1
        while 2 * pow2 < self.n:
            i = 2 * pow2
            while i < self.n:
                self.v[i] += self.v[i - pow2]
                i += 2 * pow2
            pow2 *= 2

    # 区間 [0..r) の和を返す
    def sum(self, r):
        res = 0
        while r > 0:
            res += self.v[r]
            r -= r & -r
        return res

    # 位置 i に x を加算する
    def add(self, i, x):
        i += 1
        while i <= self.n:
            self.v[i] += x
            i += i & -i

n = int(input())

x = []
for i in range(n):
    x.append(math.sqrt(int(input())))

f = FenwickTree(x)

for i in range(n):
    res = f.sum(i + 1)
    print(f'{res:.18g}')
0