結果

問題 No.1441 MErGe
ユーザー mkawa2mkawa2
提出日時 2022-01-23 18:59:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 683 ms / 1,000 ms
コード長 1,061 bytes
コンパイル時間 1,282 ms
コンパイル使用メモリ 86,596 KB
実行使用メモリ 116,456 KB
最終ジャッジ日時 2023-08-20 00:41:49
合計ジャッジ時間 16,054 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
70,928 KB
testcase_01 AC 73 ms
71,064 KB
testcase_02 AC 73 ms
70,828 KB
testcase_03 AC 110 ms
77,072 KB
testcase_04 AC 104 ms
77,128 KB
testcase_05 AC 156 ms
78,252 KB
testcase_06 AC 155 ms
77,804 KB
testcase_07 AC 154 ms
77,892 KB
testcase_08 AC 248 ms
85,372 KB
testcase_09 AC 245 ms
84,180 KB
testcase_10 AC 318 ms
83,864 KB
testcase_11 AC 301 ms
82,392 KB
testcase_12 AC 321 ms
85,424 KB
testcase_13 AC 584 ms
115,412 KB
testcase_14 AC 591 ms
115,336 KB
testcase_15 AC 683 ms
112,044 KB
testcase_16 AC 501 ms
113,764 KB
testcase_17 AC 531 ms
111,836 KB
testcase_18 AC 459 ms
97,036 KB
testcase_19 AC 513 ms
109,324 KB
testcase_20 AC 409 ms
107,120 KB
testcase_21 AC 383 ms
100,672 KB
testcase_22 AC 497 ms
100,128 KB
testcase_23 AC 650 ms
116,448 KB
testcase_24 AC 642 ms
116,076 KB
testcase_25 AC 566 ms
116,308 KB
testcase_26 AC 588 ms
116,456 KB
testcase_27 AC 589 ms
116,384 KB
testcase_28 AC 323 ms
115,980 KB
testcase_29 AC 342 ms
116,336 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):
        idx = 0
        for lv in range(n.bit_length()-1, -1, -1):
            mid = idx+(1 << lv)
            if mid >= n+1: continue
            if table[mid] < x:
                x -= table[mid]
                idx += 1 << lv
        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)

    lr = list(range(n))

    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 = lr[i]+1
                add(j, -1)
                k = lr[j]
                lr[k] = i
                lr[i] = k
        else:
            i = rank(l)
            j = rank(r)
            print(cs[j]-cs[i])

main()
0