結果

問題 No.1441 MErGe
ユーザー mkawa2mkawa2
提出日時 2022-01-24 15:32:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 628 ms / 1,000 ms
コード長 1,009 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 85,632 KB
実行使用メモリ 116,848 KB
最終ジャッジ日時 2023-08-21 03:38:52
合計ジャッジ時間 18,379 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,140 KB
testcase_01 AC 79 ms
70,992 KB
testcase_02 AC 71 ms
71,104 KB
testcase_03 AC 104 ms
77,348 KB
testcase_04 AC 101 ms
76,972 KB
testcase_05 AC 153 ms
78,960 KB
testcase_06 AC 150 ms
78,468 KB
testcase_07 AC 147 ms
78,624 KB
testcase_08 AC 235 ms
85,560 KB
testcase_09 AC 225 ms
84,404 KB
testcase_10 AC 289 ms
83,772 KB
testcase_11 AC 272 ms
82,684 KB
testcase_12 AC 293 ms
85,528 KB
testcase_13 AC 527 ms
115,632 KB
testcase_14 AC 487 ms
115,772 KB
testcase_15 AC 628 ms
112,048 KB
testcase_16 AC 480 ms
114,200 KB
testcase_17 AC 503 ms
112,164 KB
testcase_18 AC 416 ms
97,284 KB
testcase_19 AC 472 ms
109,600 KB
testcase_20 AC 383 ms
107,672 KB
testcase_21 AC 375 ms
101,064 KB
testcase_22 AC 461 ms
100,340 KB
testcase_23 AC 590 ms
116,448 KB
testcase_24 AC 604 ms
116,848 KB
testcase_25 AC 546 ms
116,584 KB
testcase_26 AC 535 ms
116,396 KB
testcase_27 AC 547 ms
116,548 KB
testcase_28 AC 311 ms
115,812 KB
testcase_29 AC 324 ms
115,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys

    def add(i, x):
        i += 1
        while i < n+1:
            table[i] += x
            i += i & -i

    def rank(x):
        if x == 0: return 0
        idx = 0
        d = 1 << n.bit_length()-1
        while d:
            if idx+d <= n and table[idx+d] < x:
                x -= table[idx+d]
                idx |= d
            d >>= 1
        return idx

    n, q = list(map(int, sys.stdin.readline().split()))
    aa = list(map(int, sys.stdin.readline().split()))

    cs = [0]
    for a in aa: cs.append(cs[-1]+a)

    table = [0]*(n+1)
    for i in range(1, n): add(i, 1)

    rr = list(range(1, n+1))

    for _ in range(q):
        t, l, r = list(map(int, sys.stdin.readline().split()))
        l -= 1
        if t == 1:
            i = rank(l)
            for _ in range(r-l-1):
                j = rr[i]
                add(j, -1)
                rr[i] = rr[j]
        else:
            i = rank(l)
            j = rank(r)
            print(cs[j]-cs[i])

main()
0