結果

問題 No.2462 七人カノン
ユーザー ntudantuda
提出日時 2023-09-09 00:31:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 408 ms / 2,000 ms
コード長 1,015 bytes
コンパイル時間 722 ms
コンパイル使用メモリ 86,944 KB
実行使用メモリ 95,372 KB
最終ジャッジ日時 2023-09-09 00:31:27
合計ジャッジ時間 13,004 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,316 KB
testcase_01 AC 89 ms
78,328 KB
testcase_02 AC 74 ms
71,176 KB
testcase_03 AC 134 ms
80,128 KB
testcase_04 AC 124 ms
80,388 KB
testcase_05 AC 121 ms
80,144 KB
testcase_06 AC 120 ms
80,284 KB
testcase_07 AC 115 ms
80,384 KB
testcase_08 AC 116 ms
80,320 KB
testcase_09 AC 115 ms
80,056 KB
testcase_10 AC 123 ms
80,292 KB
testcase_11 AC 129 ms
80,312 KB
testcase_12 AC 118 ms
80,380 KB
testcase_13 AC 340 ms
93,052 KB
testcase_14 AC 365 ms
93,840 KB
testcase_15 AC 346 ms
93,680 KB
testcase_16 AC 393 ms
95,184 KB
testcase_17 AC 382 ms
95,372 KB
testcase_18 AC 126 ms
81,016 KB
testcase_19 AC 118 ms
81,208 KB
testcase_20 AC 381 ms
94,180 KB
testcase_21 AC 408 ms
94,212 KB
testcase_22 AC 384 ms
94,348 KB
testcase_23 AC 372 ms
94,072 KB
testcase_24 AC 279 ms
88,604 KB
testcase_25 AC 383 ms
95,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 区間和セグ木
def update(k, x):
    k += N0 - 1
    data[k] = x  # 加算にするなら+=に
    while k >= 0:
        k = (k - 1) // 2
        data[k] = data[2 * k + 1] + data[2 * k + 2]

def query(l, r):
    s = 0
    L = l + N0;
    R = r + N0
    while L < R:
        if R & 1:
            R -= 1
            s += data[R - 1]
        if L & 1:
            s += data[L - 1]
            L += 1
        L >>= 1;
        R >>= 1
    return s


N, Q = map(int, input().split())
IST = []
maxst = 0
for _ in range(Q):
    i, s, t = map(int, input().split())
    maxst = max(maxst, t)
    IST.append((i, s, t))

# N: 処理する区間の長さ
N0 = 2 ** (maxst + 1).bit_length()
data = [0.0] * (2 * N0)

A = [0] * (maxst + 1)
for i, s, t in IST:
    A[s] += 1
    A[t] -= 1

if A[0] > 0:
    update(0, 1 / A[0])
for i in range(1, maxst + 1):
    A[i] += A[i - 1]
    if A[i] > 0:
        update(i, 1 / A[i])

ans = [0] * N
for i, s, t in IST:
    ans[i - 1] += query(s, t)
for i in range(N):
    print(ans[i])
0